+ All Categories
Home > Documents > pir sensor based energy saver

pir sensor based energy saver

Date post: 15-Jul-2016
Category:
Upload: kaparna
View: 26 times
Download: 1 times
Share this document with a friend
Description:
it saves power
104
PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2 CH APTER-1 INTRODUCTION TO PIR SENSOR BASED POWER SAVER Embedded systems have grown tremendously in recent years, not only in their popularity but also in their complexity. Gadgets are increasingly becoming intelligent and autonomous. Refrigerators, air-conditioners, automobiles, mobile phones etc are some of the common examples of devices with built in intelligence. These devices function based on operating and environmental parameters. The intelligence of smart devices resides in embedded systems. An embedded system, in general, in co-operates hardware, operating systems, low-level software binding the operating system and peripheral devices, and communication software to enable the device to perform the pre-defined functions. An embedded system performs a single, well-defined task, is tightly constrained, is reactive and computes results in real time. Let us take a detailed look at these features of embedded systems: Single functioned: An embedded system executes a specific program repeatedly. For example, a pager is always a pager. In contrast a desktop system executes a variety of programs like spreadsheets, word processors, etc. However there are 1 Department of ECE VMTW
Transcript
Page 1: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

CHAPTER-1

INTRODUCTION TO PIR SENSOR BASED POWER SAVER

Embedded systems have grown tremendously in recent years, not only in their popularity

but also in their complexity. Gadgets are increasingly becoming intelligent and autonomous.

Refrigerators, air-conditioners, automobiles, mobile phones etc are some of the common

examples of devices with built in intelligence. These devices function based on operating and

environmental parameters.

The intelligence of smart devices resides in embedded systems. An embedded system, in

general, in co-operates hardware, operating systems, low-level software binding the operating

system and peripheral devices, and communication software to enable the device to perform the

pre-defined functions. An embedded system performs a single, well-defined task, is tightly

constrained, is reactive and computes results in real time.

Let us take a detailed look at these features of embedded systems:

Single functioned: An embedded system executes a specific program repeatedly. For

example, a pager is always a pager. In contrast a desktop system executes a variety of

programs like spreadsheets, word processors, etc. However there are exceptions where in

an embedded system’s program is updated with newer program versions. Cell phones are

examples of being updated in such a manner.

Tightly constrained: All computing systems have constraints on design metrics but

those on embedded systems can be especially tight. A design metric is a measure of an

implementation’s features, such as cost, size performance and power.

Reactive and real time: Many embedded systems must continually react to changes in

the system’s environment and must compute certain results in real time without delay.

1Department of ECE VMTW

Page 2: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

1.1 EMBEDDED HARDWARE

All embedded systems need a microprocessor, and the kinds of microprocessors used in

them are quite varied. A list of some of the common microprocessor families is the ZILOG Z8

family, Intel 805/80188/x 86 families, Motorola 68k family and the PowerPC family.

1.2 EMBEDDED SOFTWARE

The software for the embedded systems is called firmware. The firmware will be written

in assembly languages for time or resource critical operations or using higher-level languages

like C or embedded C. The software will be simulated using micro code simulators for the target

processor. Since they are supposed to perform only specific tasks these programs are stored in

Read Only Memories (ROM’s).

1.3 APPLICATIONS

Embedded software is present in almost every electronic device you use today. There is

embedded software inside your watch, cellular phone, automobile, thermostats, industrial control

equipment and scientific and medical equipment. Defence services use embedded software to

guide missiles and detect aircraft’s communication satellites, medical instruments and deep space

probes would have been nearly impossible without these systems. Embedded systems cover such

as broad range of products that generalization is difficult.

Here are some broad categories:

Aerospace and Defence Electronics (ADE)

Consumer/Internet applications

Data Communications

Digital imaging

Medical electronic Mobile data infrastructures

2Department of ECE VMTW

Page 3: pir sensor based energy saver

Embedded System

Software Hardware

ALPCVB Etc.,

ProcessorPeripheralsmemory

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

1.4 BLOCK DIAGRAM OF EMBEDDED SYSTEMS

Fig 1.1 Block Diagram Of Embedded Systems

Software deals with the languages like ALP, C, and VB etc., and Hardware deals with

Processors, Peripherals, and Memory.

Memory: It is used to store data or address.

Peripherals: These are the external devices connected

Processor: It is an IC which is used to perform some task

Processors are classified into four types like:

Micro Processor (µp)

Micro controller (µc)

Digital Signal Processor (DSP)

Application Specific Integrated Circuits (ASIC)

The project automatic auditorium auditorium control system using microcontroller is an

interesting project which uses AT89S52 microcontroller. this system switches on the light only

3Department of ECE VMTW

Page 4: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

in the darkness. PIR sensor is used to recognise the movement or motion. If the movement is

identified in the room, then the light will be automatically switched on else it will be off.

The PIR sensors also senses the temperature of the room. If the room

temperature is high then the Fans will be switched on else it will be off. This sensation of

temperature will be done by using thermistor. This thermistor is placed in the PIR sensor. It

senses the temperature and swich on the fan. Thermistor reads the temperature value to the ADC.

Then it coverts the analog signal to digital signal.

The operation of the appliances (light or fan) will be done by using the

driver circuit. Depending upon the recognisation by the PIR sensor the driver circuit will switch

on and off the fan and light. The buzzer is used to indicate us that whether the fans and light are

on or off.

4Department of ECE VMTW

Page 5: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

BLOCK DIAGRAM

Fig 1.2 :

Block diagram of PIR sensor

5Department of ECE VMTW

Page 6: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

CHAPTER 2

MICROCONTROLLER AT89S52

2.1 A BRIEF HISTORY OF 8051

In 1981, Intel Corporation introduced an 8 bit microcontroller called 8051. This

microcontroller had 128 bytes of RAM, 4K bytes of chip ROM, two timers, one serial port, and

four ports all on a single chip. At the time it was also referred as “A SYSTEM ON A CHIP”

AT89S52:

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of

in-system programmable Flash memory. The device is manufactured using Atmel’s high-density

nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction

set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or

by a conventional nonvolatile memory pro-grammer. By combining a versatile 8-bit CPU with

in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful

microcontroller, which provides a highly flexible and cost-effective solution to many, embedded

control applications. The AT89S52 provides the following standard features: 8K bytes of Flash,

256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters,

a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and

clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero

frequency and supports two software selectable power saving modes. The Idle Mode stops the

CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue

functioning. The Power-down mode saves the RAM con-tents but freezes the oscillator,

disabling all other chip functions until the next interrupt

6Department of ECE VMTW

Page 7: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 2.1 Diagram of 8051 Microcontroller

Fig 2.2: Diagram of an entire computer on a single chip

8031 has 128 bytes of RAM, two timers and 6 interrupts.

8051 has 4K ROM, 128 bytes of RAM, two timers and 6 interrupts.

8052 has 8K ROM, 256 bytes of RAM, three timers and 8 interrupts.

Of the three microcontrollers, 8051 is the most preferable. Microcontroller supports both

serial and parallel communication.

7Department of ECE VMTW

Page 8: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

In the concerned project 8052 microcontroller is used. Here microcontroller used is

AT89S52, which is manufactured by ATMEL laboratories.

The 8051 is the name of a big family of microcontrollers. The device which we are going to use

along this tutorial is the 'AT89S52' which is a typical 8051 microcontroller manufactured by

Atmel™. Note that this part doesn't aim to explain the functioning of the different components of

a 89S52 microcontroller, but rather to give you a general idea of the organization of the chip and

the available features, which shall be explained in detail along this tutorial.

The block diagram provided by Atmel™ in their datasheet showing the architecture the 89S52

device can seem very complicated, and since we are going to use the C high level language to

program it, a simpler architecture can be represented as the figure 1.2.A.

This figures shows the main features and components that the designer can interact with. You

can notice that the 89S52 has 4 different ports, each one having 8 Input/output lines providing a

total of 32 I/O lines. Those ports can be used to output DATA and orders do other devices, or to

read the state of a sensor, or a switch. Most of the ports of the 89S52 have 'dual function'

meaning that they can be used for two different functions: the fist one is to perform input/output

operations and the second one is used to implement special features of the microcontroller like

counting external pulses, interrupting the execution of the program according to external events,

performing serial data transfer or connecting the chip to a computer to update the software.

2.2 NECESSITY OF MICROCONTROLLERS:

Microprocessors brought the concept of programmable devices and made many

applications of intelligent equipment. Most applications, which do not need large amount of data

and program memory, tended to be costly.

The microprocessor system had to satisfy the data and program requirements so,

sufficient RAM and ROM are used to satisfy most applications .The peripheral control

equipment also had to be satisfied. Therefore, almost all-peripheral chips were used in the

design. Because of these additional peripherals cost will be comparatively high.

An example:

8085 chip needs:

8Department of ECE VMTW

Page 9: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

An Address latch for separating address from multiplex address and data.32-KB RAM and

32-KB ROM to be able to satisfy most applications. As also Timer / Counter, Parallel

programmable port, Serial port, and Interrupt controller are needed for its efficient applications.

In comparison a typical Micro controller 8051 chip has all that the 8051 board has except

a reduced memory as follows.

4K bytes of ROM as compared to 32-KB, 128 Bytes of RAM as compared to 32-KB.

Bulky:

On comparing a board full of chips (Microprocessors) with one chip with all components

in it (Microcontroller).

Debugging:

Lots of Microprocessor circuitry and program to debug. In Micro controller there is no

Microprocessor circuitry to debug.

Slower Development time: As we have observed Microprocessors need a lot of debugging at

board level and at program level, where as, Micro controller do not have the excessive circuitry

and the built-in peripheral chips are easier to program for operation.

So peripheral devices like Timer/Counter, Parallel programmable port, Serial

Communication Port, Interrupt controller and so on, which were most often used were integrated

with the Microprocessor to present the Micro controller .RAM and ROM also were integrated in

the same chip. The ROM size was anything from 256 bytes to 32Kb or more. RAM was

optimized to minimum of 64 bytes to 256 bytes or more.

Microprocessor has following instructions to perform:

1. Reading instructions or data from program memory ROM.

2. Interpreting the instruction and executing it.

3. Microprocessor Program is a collection of instructions stored in a Nonvolatile memory.

4. Read Data from I/O device

9Department of ECE VMTW

Page 10: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

5. Process the input read, as per the instructions read in program memory.

6. Read or write data to Data memory.

7. Write data to I/O device and output the result of processing to O/P device.

2.3 INTRODUCTION TO AT89S52

The system requirements and control specifications clearly rule out the use of 16, 32 or 64

bit micro controllers or microprocessors. Systems using these may be earlier to implement due to

large number of internal features. They are also faster and more reliable but, the above

application is satisfactorily served by 8-bit micro controller. Using an inexpensive 8-bit

Microcontroller will doom the 32-bit product failure in any competitive market place. Coming to

the question of why to use 89S52 of all the 8-bit Microcontroller available in the market the main

answer would be because it has 8kB Flash and 256 bytes of data RAM32 I/O lines, three 16-bit

timer/counters, a Eight-vector two-level interrupt architecture, a full duplex serial port, on-chip

oscillator, and clock circuitry.

In addition, the AT89S52 is designed with static logic for operation down to zero frequency and

supports two software selectable power saving modes. The Idle Mode stops the CPU while

allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The

Power Down Mode saves the RAM contents but freezes the oscillator, disabling all other chip

functions until the next hardware reset. The Flash program memory supports both parallel

programming and in Serial In-System Programming (ISP). The 89S52 is also In-Application

Programmable (IAP), allowing the Flash program memory to be reconfigured even while the

application is running.

By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89S52 is

a powerful microcomputer which provides a highly flexible and cost effective solution to many

embedded control applications.

2.4 FEATURES

Compatible with MCS-51 Products

8K Bytes of In-System Reprogrammable Flash Memory

10Department of ECE VMTW

Page 11: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fully Static Operation: 0 Hz to 33 MHz

Three-level Program Memory Lock

256 x 8-bit Internal RAM

32 Programmable I/O Lines

Three 16-bit Timer/Counters

Eight Interrupt Sources

Programmable Serial Channel

Low-power Idle and Power-down Modes

4.0V to 5.5V Operating Range

Full Duplex UART Serial Channel

Interrupt Recovery from Power-down Mode

Watchdog Timer

Dual Data Pointer

Power-off Flag

Fast Programming Time

Flexible ISP Programming (Byte and Page Mode)

11Department of ECE VMTW

Page 12: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

2.5 PIN DIAGRAM

FIG-2.3 PIN DIAGRAM OF 89S52 IC

2.6 PIN DESCRIPTION

Pin Description

VCC

Supply voltage.

GND

Ground.

12Department of ECE VMTW

Page 13: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Port 0

Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight

TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance

inputs.Port 0 can also be configured to be the multiplexed loworder address/data bus during

accesses to external program and data memory. In this mode, P0 has internal pullups. Port 0 also

receives the code bytes during Flash programming and outputs the code bytes during program

verification.

External pullups are required during program verification.

Port 1

Port 1 is an 8-bit bidirectional I/O port with internal pullups. The Port 1 output buffers can

sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the

internal pullups and can be used as inputs. As inputs,Port 1 pins that are externally being pulled

low will source current (IIL) because of the internal pullups. In addition, P1.0 and P1.1 can be

configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2

trigger input (P1.1/T2EX), respectively, as shown in the following table. Port 1 also receives the

low-order address bytes during Flash programming and verification.

Table 2.1 : Alternate functions of port 1

13Department of ECE VMTW

Page 14: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Port 2

Port 2 is an 8-bit bidirectional I/O port with internal pullups.The Port 2 output buffers can

sink/source four TTL inputs.When 1s are written to Port 2 pins, they are pulled high by

the internal pullups and can be used as inputs. As inputs, Port 2 pins that are externally being

pulled low will source current (IIL) because of the internal pullups. Port 2 emits the high-order

address byte during fetches from external program memory and during accesses to external data

memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong

internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit

addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2

also receives the high-order address bits and some control signals during Flash programming and

verification.

Port 3

Port 3 is an 8-bit bidirectional I/O port with internal pullups.The Port 3 output buffers can

sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the

internal pullups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled

low will source current (IIL) because of the pullups. Port 3 also serves the functions of various

special features of the AT89S52, as shown in the following table. Port 3 also receives some

control signals for Flash programming and verification.

Table 2.2 : Alternate functions of port 2

14Department of ECE VMTW

Page 15: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

RST

Reset input. A high on this pin for two machine cycles while the oscillator is running resets the

device. This pin drives High for 96 oscillator periods after the Watchdog times out. The DISRTO

bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit

DISRTO, the RESET HIGH out feature is enabled. ALE/PROG Address Latch Enable (ALE) is

an output pulse for latching the low byte of the address during accesses to external memory. This

pin is also the program pulse input (PROG) during Flash programming. In normal operation,

ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external

timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to

external data memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location

8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the

pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in

external execution mode.

PSEN

Program Store Enable (PSEN) is the read strobe to external program memory. When the

AT89S52 is executing code from external program memory, PSEN is activated twice each

machine cycle, except that two PSEN activations are skipped during each access to external data

memory.

EA/VPP

External Access Enable. EA must be strapped to GND in order to enable the device to fetch code

from external program memory locations starting at 0000H up to FFFFH. Note, however, that if

lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC

for internal program executions. This pin also receives the 12-volt programming enable voltage

(VPP) during Flash programming.

XTAL1

Input to the inverting oscillator amplifier and input to the

internal clock operating circuit.

15Department of ECE VMTW

Page 16: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

XTAL2

Output from the inverting oscillator amplifier.

FIG-2.4 Functional block diagram of micro controller

The 8052 Oscillator and Clock:

The heart of the 8051 circuitry that generates the clock pulses by which all the internal

all internal operations are synchronized. Pins XTAL1 And XTAL2 is provided for connecting a

resonant network to form an oscillator. Typically a quartz crystal and capacitors are employed.

The crystal frequency is the basic internal clock frequency of the microcontroller. The

manufacturers make 8051 designs that run at specific minimum and maximum frequencies

typically 1 to 16 MHz.

16Department of ECE VMTW

Page 17: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig-2.5 Oscillator and timing circuit

MEMORIES

Types of memory:

The 8052 have three general types of memory. They are on-chip memory, external Code memory

and external Ram. On-Chip memory refers to physically existing memory on the micro controller

itself. External code memory is the code memory that resides off chip. This is often in the form

of an external EPROM. External RAM is the Ram that resides off chip. This often is in the form

of standard static RAM or flash RAM.

17Department of ECE VMTW

Page 18: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

a) Code memory

Code memory is the memory that holds the actual 8052 programs that is to be run. This memory

is limited to 64K. Code memory may be found on-chip or off-chip. It is possible to have 8K of

code memory on-chip and 60K off chip memory simultaneously. If only off-chip memory is

available then there can be 64K of off chip ROM. This is controlled by pin provided as EA

b) Internal RAM

The 8052 have a bank of 256 bytes of internal RAM. The internal RAM is found on-chip.

So it is the fastest Ram available. And also it is most flexible in terms of reading and writing.

Internal Ram is volatile, so when 8051 is reset, this memory is cleared. 256 bytes of internal

memory are subdivided. The first 32 bytes are divided into 4 register banks. Each bank contains

8 registers. Internal RAM also contains 256 bits, which are addressed from 20h to 2Fh. These

bits are bit addressed i.e. each individual bit of a byte can be addressed by the user. They are

numbered 00h to FFh. The user may make use of these variables with commands such as SETB

and CLR.

Special Function registered memory:

Special function registers are the areas of memory that control specific functionality of

the 8052 micro controller.

a) Accumulator (0E0h) As its name suggests, it is used to accumulate the results of large no of

instructions. It can hold 8 bit values.

b) B registers (0F0h)

The B register is very similar to accumulator. It may hold 8-bit value. The b register is only used

by MUL AB and DIV AB instructions. In MUL AB the higher byte of the product gets stored in

B register. In div AB the quotient gets stored in B with the remainder in A.

c) Stack pointer (81h)

The stack pointer holds 8-bit value. This is used to indicate where the next value to be removed

from the stack should be taken from. When a value is to be pushed onto the stack, the 8052 first

18Department of ECE VMTW

Page 19: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

store the value of SP and then store the value at the resulting memory location. When a value is

to be popped from the stack, the 8052 returns the value from the memory location indicated by

SP and then decrements the value of SP.

d) Data pointer

The SFRs DPL and DPH work together work together to represent a 16-bit value called the data

pointer. The data pointer is used in operations regarding external RAM and some instructions

code memory. It is a 16-bit SFR and also an addressable SFR.

e) Program counter

The program counter is a 16 bit register, which contains the 2 byte address, which tells the 8052

where the next instruction to execute to be found in memory. When the 8052 is initialized PC

starts at 0000h. And is incremented each time an instruction is executes. It is not addressable

SFR.

f) PCON (power control, 87h)

The power control SFR is used to control the 8051’s power control modes. Certain operation

modes of the 8051 allow the 8051 to go into a type of “sleep mode” which consumes much lee

power.

g) TCON (timer control, 88h)

The timer control SFR is used to configure and modify the way in which the 8051’s two timers

operate. This SFR controls whether each of the two timers is running or stopped and contains a

flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are

located in TCON SFR. These bits are used to configure the way in which the external interrupt

flags are activated, which are set when an external interrupt occurs.

19Department of ECE VMTW

Page 20: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

h) TMOD (Timer Mode, 89h)

The timer mode SFR is used to configure the mode of operation of each of the two timers. Using

this SFR your program may configure each timer to be a 16-bit timer, or 13 bit timer, 8-bit auto

reload timer, or two separate timers. Additionally you may configure the timers to only count

when an external pin is activated or to count “events” that are indicated on an external pin.

i) TO (Timer 0 low/high, address 8A/8C h)

These two SFRs taken together represent timer 0. Their exact behavior depends on how

the timer is configured in the TMOD SFR; however, these timers always count up. What is

configurable is how and when they increment in value.

j) T1 (Timer 1 Low/High, address 8B/ 8D h)

These two SFRs, taken together, represent timer 1. Their exact behavior depends on how

the timer is configured in the TMOD SFR; however, these timers always count up..

k) P0 (Port 0, address 90h, bit addressable)

This is port 0 latch. Each bit of this SFR corresponds to one of the pins on a micro controller.

Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin

P0.0, bit 7 is pin p0.7. Writing a value of 1 to a bit of this SFR will send a high level on the

corresponding I/O pin whereas a value of 0 will bring it to low level.

20Department of ECE VMTW

Page 21: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

l) P1 (port 1, address 90h, bit addressable)

This is port latch1. Each bit of this SFR corresponds to one of the pins on a micro

controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port

0 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a high level on

the corresponding I/O pin whereas a value of 0 will bring it to low level

m) P2 (port 2, address 0A0h, bit addressable):

This is a port latch2. Each bit of this SFR corresponds to one of the pins on a micro

controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port

0 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this SFR will send a high level on

the corresponding I/O pin whereas a value of 0 will bring it to low level.

n) P3 (port 3, address B0h, bit addressable) :

This is a port latch3. Each bit of this SFR corresponds to one of the pins on a micro

controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port

0 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will send a high level on

the corresponding I/O pin whereas a value of 0 will bring it to low level.

o) IE (interrupt enable, 0A8h):

The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7 bits

of the SFR are used to enable/disable the specific interrupts, where the MSB bit is used to enable

or disable all the interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of

whether an individual interrupt is enabled by setting a lower bit.

p) IP (Interrupt Priority, 0B8h)

The interrupt priority SFR is used to specify the relative priority of each interrupt. On

8051, an interrupt maybe either low or high priority. An interrupt may interrupt interrupts. For

21Department of ECE VMTW

Page 22: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

e.g., if we configure all interrupts as low priority other than serial interrupt. The serial interrupt

always interrupts the system, even if another interrupt is currently executing. However, if a serial

interrupt is executing no other interrupt will be able to interrupt the serial interrupt routine since

the serial interrupt routine has the highest priority.

q) PSW (Program Status Word, 0D0h)

The program Status Word is used to store a number of important bits that are set and

cleared by 8052 instructions. The PSW SFR contains the carry flag, the auxiliary carry flag, the

parity flag and the overflow flag. Additionally, it also contains the register bank select flags,

which are used to select, which of the “R” register banks currently in use.

r) SBUF (Serial Buffer, 99h)

SBUF is used to hold data in serial communication. It is physically two registers. One is

writing only and is used to hold data to be transmitted out of 8052 via TXD. The other is read

only and holds received data from external sources via RXD. Both mutually exclusive registers

use address 99h.

22Department of ECE VMTW

Page 23: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

CHAPTER3

DESCRIPTION OF HARDWARE COMPONENTS

3.1 POWER SUPPLY

The power supplies are designed to convert high voltage AC mains electricity to a

suitable low voltage supply for electronics circuits and other devices. A power supply can by

broken down into a series of blocks, each of which performs a particular function. A d.c power

supply which maintains the output voltage constant irrespective of a.c mains fluctuations or load

variations is known as “Regulated D.C Power Supply”

For example a 5V regulated power supply system as shown below:

Fig 3.1 : block diagram of power supply

3.1.1 Transformer

A transformer is an electrical device which is used to convert electrical power from one

Electrical circuit to another without change in frequency.

23Department of ECE VMTW

Page 24: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Transformers convert AC electricity from one voltage to another with little loss of power.

Transformers work only with AC and this is one of the reasons why mains electricity is AC.

Step-up transformers increase in output voltage, step-down transformers decrease in output

voltage. Most power supplies use a step-down transformer to reduce the dangerously high mains

voltage to a safer low voltage. The input coil is called the primary and the output coil is called

the secondary. There is no electrical connection between the two coils; instead they are linked by

an alternating magnetic field created in the soft-iron core of the transformer. The two lines in the

middle of the circuit symbol represent the core. Transformers waste very little power so the

power out is (almost) equal to the power in. Note that as voltage is stepped down current is

stepped up. The ratio of the number of turns on each coil, called the turn’s ratio, determines the

ratio of the voltages. A step-down transformer has a large number of turns on its primary (input)

coil which is connected to the high voltage mains supply, and a small number of turns on its

secondary (output) coil to give a low output voltage.

Fig 9 : Diagram of transformer

Fig 3.2 : Diagram of transformer

An Electrical Transformer

Turns ratio = Vp/ VS = Np/NS

Power Out= Power In

VS X IS=VP X IP

24Department of ECE VMTW

Page 25: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Vp = primary (input) voltage

Np = number of turns on primary coil

Ip  = primary (input) current    

3.1.2 Rectifier

A circuit which is used to convert a.c to dc is known as RECTIFIER. The process of

conversion a.c to d.c is called “rectification”

TYPES OF RECTIFIERS:

Half wave Rectifier

Full wave rectifier

1. Centre tap full wave rectifier.

2. Bridge type full bridge rectifier.

Table 3.1 Comparison of rectifier circuits:

Parameter

Type of Rectifier

Half wave Full wave Bridge

Number of diodes

1

2

4

PIV of diodes

Vm

2Vm

Vm

D.C output voltage

Vm/

2Vm/

2Vm/

Vdc,at

0.318Vm

0.636Vm 0.636Vm

25Department of ECE VMTW

Page 26: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

no-load

Ripple factor

1.21

0.482

0.482

Ripple

Frequency

f

2f

2f

Rectification

Efficiency

0.406

0.812

0.812

Transformer

Utilization

Factor(TUF)

0.287 0.693 0.812

RMS voltage Vrms Vm/2 Vm/√2 Vm/√2

Full-wave Rectifier:

From the above comparison we came to know that full wave bridge rectifier as more advantages

than the other two rectifiers. So, in our project we are using full wave bridge rectifier circuit.

Bridge Rectifier: A bridge rectifier makes use of four diodes in a bridge arrangement to achieve

full-wave rectification. This is a widely used configuration, both with individual diodes wired as

shown and with single component bridges where the diode bridge is wired internally.

A bridge rectifier makes use of four diodes in a bridge arrangement as shown in fig(a)

to achieve full-wave rectification. This is a widely used configuration, both with individual

diodes wired as shown and with single component bridges where the diode bridge is wired

internally.

26Department of ECE VMTW

Page 27: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.3 : Diagram of full wave rectifier

Operation:

During positive half cycle of secondary, the diodes D2 and D3 are in forward biased while D1

and D4 are in reverse biased as shown in the fig(b). The current flow direction is shown in the

fig (b) with dotted arrows.

Fig 3.4 : Operation of Full wave rectifier

During negative half cycle of secondary voltage, the diodes D1 and D4 are in forward biased

while D2 and D3 are in reverse biased as shown in the fig(c). The current flow direction is

shown in the fig (c) with dotted arrows.

27Department of ECE VMTW

Page 28: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.5 : Operation of half wave rectifier

3.1.3 Filter

A Filter is a device which removes the a.c component of rectifier output

but allows the d.c component to reach the load

Capacitor Filter:

We have seen that the ripple content in the rectified output of half wave rectifier is 121% or

that of full-wave or bridge rectifier or bridge rectifier is 48% such high percentages of ripples is

not acceptable for most of the applications. Ripples can be removed by one of the following

methods of filtering.

(a) A capacitor, in parallel to the load, provides an easier by –pass for the ripples voltage though

it due to low impedance. At ripple frequency and leave the d.c.to appears the load.

(b) An inductor, in series with the load, prevents the passage of the ripple current (due to high

impedance at ripple frequency) while allowing the d.c (due to low resistance to d.c)

(c) Various combinations of capacitor and inductor, such as L-section filter section filter,

multiple section filter etc. which make use of both the properties mentioned in (a) and (b) above.

Two cases of capacitor filter, one applied on half wave rectifier and another with full wave

rectifier.

28Department of ECE VMTW

Page 29: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Filtering is performed by a large value electrolytic capacitor connected across the DC supply to

act as a reservoir, supplying current to the output when the varying DC voltage from the rectifier

is falling. The capacitor charges quickly near the peak of the varying DC, and then discharges as

it supplies current to the output. Filtering significantly increases the average DC voltage to

almost the peak value (1.4 × RMS value).

To calculate the value of capacitor(C),

C = ¼*√3*f*r*Rl

Where,

f = supply frequency,

r = ripple factor,

Rl = load resistance

Note: In our circuit we are using 1000µF. Hence large value of capacitor is placed to reduce

ripples and to improve the DC component.

3.1.4 Regulator:

Voltage regulator ICs is available with fixed (typically 5, 12 and 15V) or variable output

voltages. The maximum current they can pass also rates them. Negative voltage regulators are

available, mainly for use in dual supplies. Most regulators include some automatic protection

from excessive current ('overload protection') and overheating ('thermal protection'). Many of

the fixed voltage regulator ICs have 3 leads and look like power transistors, such as the 7805

+5V 1A regulator shown on the right. The LM7805 is simple to use. You simply connect the

positive lead of your unregulated DC power supply (anything from 9VDC to 24VDC) to the

Input pin, connect the negative lead to the Common pin and then when you turn on the power,

you get a 5 volt supply from the output pin.

29Department of ECE VMTW

Page 30: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.6: A Three Terminal Voltage Regulator

78XX:

The Bay Linear LM78XX is integrated linear positive regulator with three terminals. The

LM78XX offer several fixed output voltages making them useful in wide range of applications.

When used as a zener diode/resistor combination replacement, the LM78XX usually results in an

effective output impedance improvement of two orders of magnitude, lower quiescent current.

The LM78XX is available in the TO-252, TO-220 & TO-263packages,

Features:

• Output Current of 1.5A

• Output Voltage Tolerance of 5%

• Internal thermal overload protection

• Internal Short-Circuit Limited

• No External Component

• Output Voltage 5.0V, 6V, 8V, 9V, 10V,12V, 15V, 18V, 24V

• Offer in plastic TO-252, TO-220 & TO-263

• Direct Replacement for LM78XX

30Department of ECE VMTW

Page 31: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

3.2 PIR SENSOR

3.2.1 What is a PIR sensor?

PIR sensors allow you to sense motion, almost always used to detect whether a human has

moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and

don't wear out. For that reason they are commonly found in appliances and gadgets used in

homes or businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR

motion" sensors.

PIRs are basically made of a pyroelectric sensor (which you can see above as the round metal

can with a rectangular crystal in the center), which can detect levels of infrared radiation.

Everything emits some low level radiation, and the hotter something is, the more radiation is

emitted. The sensor in a motion detector is actually split in two halves. The reason for that is that

we are looking to detect motion (change) not average IR levels. The two halves are wired up so

that they cancel each other out. If one half sees more or less IR radiation than the other, the

output will swing high or low.

Along with the pyroelectic sensor is a bunch of supporting circuitry, resistors and capacitors. It

seems that most small hobbyist sensors use the BISS0001 ("Micro Power PIR Motion Detector

IC") , undoubtedly a very inexpensive chip. This chip takes the output of the sensor and does

some minor processing on it to emit a digital output pulse from the analog sensor.

For many basic projects or products that need to detect when a person has left or entered the

area, or has approached, PIR sensors are great. They are low power and low cost, pretty rugged,

have a wide lens range, and are easy to interface with. Note that PIRs won't tell you how many

people are around or how close they are to the sensor, the lens is often fixed to a certain sweep

and distance (although it can be hacked somewhere) and they are also sometimes set off by

house pets.

31Department of ECE VMTW

Page 32: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.7 : Diagram of PIR Sensor

32Department of ECE VMTW

Page 33: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

3.2.2 PIR Module

Fig 3.8 : PIR module

3.2.3 Some basic stats

33Department of ECE VMTW

Page 34: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

These stats are for the PIR sensor in the Adafruit shop which is very much like the Parallax one .

Nearly all PIRs will have slightly different specifications, although they all pretty much work the

same. If there's a datasheet, you'll want to refer to it

Size: Rectangular

Price: $10.00 at the Adafruit shop

Output: Digital pulse high (3V) when triggered (motion detected) digital low when idle

(no motion detected). Pulse lengths are determined by resistors and capacitors on the

PCB and differ from sensor to sensor.

Sensitivity range: up to 20 feet (6 meters) 110° x 70° detection range

Power supply:3.3V - 5V input voltage,

BIS0001 Datasheet (the decoder chip used)

RE200B datasheet (most likely the PIR sensing element used)

NL11NH datasheet (equivalent lens used)

3.2.4 How does it work?

PIR sensors are more complicated than many of the other sensors explained in these tutorials

(like photocells, FSRs and tilt switches) because there are multiple variables that affect the

sensors input and output. To begin explaining how a basic sensor works, we'll use this rather nice

diagram (if anyone knows where it originates plz let me know).

The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to

IR. The lens used here is not really doing much and so we see that the two slots can 'see' out past

some distance (basically the sensitivity of the sensor). When the sensor is idle, both slots detect

the same amount of IR, the ambient amount radiated from the room or walls or outdoors. When a

warm body like a human or animal passes by, it first intercepts one half of the PIR sensor, which

causes a positive differential change between the two halves. When the warm body leaves the

sensing area, the reverse happens, whereby the sensor generates a negative differential change.

These change pulses are what is detected.

The IR sensor itself is housed in a hermetically sealed metal can to improve

noise/temperature/humidity immunity. There is a window made of IR-transmissive material

34Department of ECE VMTW

Page 35: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

(typically coated silicon since that is very easy to come by) that protects the sensing element.

Behind the window are the two balanced sensors.

3.2.5 Lenses

PIR sensors are rather generic and for the most part vary only in price and sensitivity. Most of

the real magic happens with the optics. This is a pretty good idea for manufacturing: the PIR

sensor and circuitry is fixed and costs a few dollars. The lens costs only a few cents and can

change the breadth, range, sensing pattern, very easily.

In the diagram up top, the lens is just a piece of plastic, but that means that the detection area is

just two rectangles. Usually we'd like to have a detection area that is much larger. To do that, we

use a simple lens such as those found in a camera: they condenses a large area (such as a

landscape) into a small one (on film or a CCD sensor). For reasons that will be apparent soon, we

would like to make the PIR lenses small and thin and moldable from cheap plastic, even though

it may add distortion. For this reason the sensors are actually Fresnel lenses :

3.2.6 Testing PIR

Once you have your PIR wired up its a good idea to do a simple test to verify that it works the

way you expect. This test is also good for range testing. Simply connect 3-4 alkaline batteries

(make sure you have more than 3.5VDC out but less than 6V by checking with your multimeter!)

and connect ground to the - pin on your PIR. Power goes to the + pin. Then connect a basic red

LED (red LEDs have lower forward voltages than green or blue so they work better with only

the 3.3v output) and a 220Ω resistor (any value from 100Ω to 1.0KΩ will do fine) to the out pin

as shown. Of course, the LED and resistor can swap locations as long as the LED is oriented

connection and connects between out and ground.

Now when the PIR detects motion, the output pin will go "high" to 3.3V and light up the

LED!

35Department of ECE VMTW

Page 36: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Once you have the breadboard wired up, insert batteries and wait 30-60 seconds for the PIR to

'stabilize'. During that time the LED may blink a little. Wait until the LED is off and then move

around in front of it, waving a hand, etc, to see the LED light up!

3.3 TEMPERATURE SENSOR (LM35)

The LM35 sensor series are precision integrated-circuit temperature sensors, whose output

voltage is linearly proportional to the Celsius (Centigrade) temperature.

Fig 3.9: Diagram of Temperature sensor (LM35)

3.3.1 LM35 Sensor Specification

The LM35 series are precision integrated-circuit LM35 temperature sensors, whose output

voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 sensor thus

has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not

required to subtract a large constant voltage from its output to obtain convenient Centigrade

scaling. The LM35 sensor does not require any external calibration or trimming to provide

typical accuracies of ±¼°C at room temperature and ±¾°C over a full -55 to +150°C temperature

range. Low cost is assured by trimming and calibration at the wafer level. The LM35's low

36Department of ECE VMTW

Page 37: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

output impedance, linear output, and precise inherent calibration make interfacing to readout or

control circuitry especially easy. It can be used with single power supplies, or with plus and

minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than

0.1°C in still air. The LM35 is rated to operate over a -55° to +150°C temperature range, while

the LM35C sensor is rated for a -40° to +110°C range (-10° with improved accuracy). The LM35

series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA,

and LM35D are also available in the plastic TO-92 transistor package. The LM35D sensor is also

available in an 8-lead surface mount small outline package and a plastic TO-220 packag

3.3.2 LM35 Sensor Circuit Schematic

Fig 3.10 : LM35 Sensor circuit schematic

 3.3.3 LM35 Sensor Pin outs and Packaging:

37Department of ECE VMTW

Page 38: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.11: LM35 sensor pinouts and packaging 

3.3.4 LM35 Sensor Sources

There are several manufacturers of this popular part and each has LM35 sensor specs, datasheets

and other free LM35 downloads. This amplifier is available from the following manufacturers.

National Semiconductor

On Semiconductor

Texas Instruments

Fairchild Semiconductor

STMicroelectronics

Jameco Electronics

Analog Devices

3.3.5 LM35 Sensor Background and Applications

Most commonly-used electrical temperature sensors are difficult to apply. For example,

thermocouples have low output levels and require cold junction compensation. Thermistors are

38Department of ECE VMTW

Page 39: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

nonlinear. In addition, the outputs of these sensors are not linearly proportional to any

temperature scale. Early monolithic sensors, such as the LM3911, LM134 and LM135, overcame

many of these difficulties, but their outputs are related to the Kelvin temperature scale rather than

the more popular Celsius and Fahrenheit scales. Fortunately, in 1983 two I.C.’s, the LM34

Precision Fahrenheit Temperature Sensor and the LM35 Precision Celsius Temperature Sensor,

were introduced. This application note will discuss the LM34, but with the proper scaling factors

can easily be adapted to the LM35.

The LM35/LM34 has an output of 10 mV/°F with a typical nonlinearity of only ±0.35°F over a

−50 to +300°F temperature range, and is accurate to within ±0.4°F typically at room temperature

(77°F). The LM34’s low output impedance and linear output characteristic make interfacing with

readout or control circuitry easy. An inherent strength of the LM34 sensor over other currently

available temperature sensors is that it is not as susceptible to large errors in its output from low

level leakage currents. For instance, many monolithic temperature sensors have an output of only

1 μA/°K. This leads to a 1°K error for only 1 μ-Ampere of leakage current. On the other hand,

the LM34 sensor may be operated as a current mode device providing 20 μA/°F of output

current. The same 1 μA of leakage current will cause an error in the LM34’s output of only

0.05°F (or 0.03°K after scaling).

Low cost and high accuracy are maintained by performing trimming and calibration procedures

at the wafer level. The device may be operated with either single or dual supplies. With less than

70 μA of current drain, the LM34 sensor has very little self-heating (less than 0.2°F in still air),

and comes in a TO-46 metal can package, a SO-8 small outline package and a TO-92 plastic

package.

The LM35/LM34 is a versatile device which may be used for a wide variety of applications,

including oven controllers and remote temperature sensing. The device is easy to use (there are

only three terminals) and will be within 0.02°F of a surface to which it is either glued or

cemented. The TO-46 package allows the user to solder the sensor to a metal surface, but in

doing so, the GND pin will be at the same potential as that metal. For applications where a

steady reading is desired despite small changes in temperature, the user can solder the TO-46

package to a thermal mass. Conversely, the thermal time constant may be decreased to speed up

response time by soldering the sensor to a small heat fin.

39Department of ECE VMTW

Page 40: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

 3.4: RELAY:

A relay is an electrically operated switch. Many relays use an electromagnet to operate a

switching mechanism, but other operating principles are also used. Relays find applications

where it is necessary to control a circuit by a low-power signal, or where several circuits must be

controlled by one signal. The first relays were used in long distance telegraph circuits, repeating

the signal coming in from one circuit and re-transmitting it to another. Relays found extensive

use in telephone exchanges and early computers to perform logical operations. A type of relay

that can handle the high power required to directly drive an electric motor is called a contactor.

Solid-state relays control power circuits with no moving parts, instead using a semiconductor

device triggered by light to perform switching. Relays with calibrated operating characteristics

and sometimes multiple operating coils are used to protect electrical circuits from overload or

faults; in modern electric power systems these functions are performed by digital instruments

still called "protection relays".

3.4.1 Basic design and operation:

Fig 3.12: Basic operation and design of relay

Simple electromechanical relay

40Department of ECE VMTW

Page 41: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.13: Diagram of simple electromechanical relay

Small relay as used in electronics

A simple electromagnetic relay, such as the one taken from a car in the first picture, is an

adaptation of an electromagnet. It consists of a coil of wire surrounding a soft iron core, an iron

yoke, which provides a low reluctance path for magnetic flux, a movable iron armature, and a

set, or sets, of contacts; two in the relay pictured. The armature is hinged to the yoke and

mechanically linked to a moving contact or contacts. It is held in place by a spring so that when

the relay is de-energized there is an air gap in the magnetic circuit. In this condition, one of the

two sets of contacts in the relay pictured is closed, and the other set is open. Other relays may

have more or fewer sets of contacts depending on their function. The relay in the picture also has

a wire connecting the armature to the yoke. This ensures continuity of the circuit between the

moving contacts on the armature, and the circuit track on the printed circuit board (PCB) via the

yoke, which is soldered to the PCB.

When an electric current is passed through the coil, the resulting magnetic field attracts the

armature and the consequent movement of the movable contact or contacts either makes or

breaks a connection with a fixed contact. If the set of contacts was closed when the relay was

De-energized, then the movement opens the contacts and breaks the connection, and vice versa if

the contacts were open. When the current to the coil is switched off, the armature is returned by a

force, approximately half as strong as the magnetic force, to its relaxed position. Usually this

force is provided by a spring, but gravity is also used commonly in industrial motor starters.

Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce

noise. In a high voltage or high current application, this is to reduce arcing.

41Department of ECE VMTW

Page 42: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the

energy from the collapsing magnetic field at deactivation, which would otherwise generate a

voltage spike dangerous to circuit components. Some automotive relays already include a diode

inside the relay case. Alternatively a contact protection network, consisting of a capacitor and

resistor in series, may absorb the surge. If the coil is designed to be energized with AC, a small

copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-

phase current, which increases the minimum pull on the armature during the AC cycle.

By analogy with the functions of the original electromagnetic device, a solid-state relay is made

with a thyristor or other solid-state switching device. To achieve electrical isolation an opt

coupler can be used which is a light-emitting diode (LED) coupled with a photo transistor.

3.4.2 Types

Latching relay

Fig 3.14 Latching relay

Latching relay, dust cover removed, showing pawl and ratchet mechanism. The ratchet operates

a cam, which raises and lowers the moving contact arm, seen edge-on just below it. The moving

and fixed contacts are visible at the left side of the image.

A latching relay has two relaxed states (bistable). These are also called "impulse", "keep", or

"stay" relays. When the current is switched off, the relay remains in its last state. This is achieved

with a solenoid operating a ratchet and cam mechanism, or by having two opposing coils with an

over-center spring or permanent magnet to hold the armature and contacts in position while the

coil is relaxed, or with a remanent core. In the ratchet and cam example, the first pulse to the coil

42Department of ECE VMTW

Page 43: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

turns the relay on and the second pulse turns it off. In the two coil example, a pulse to one coil

turns the relay on and a pulse to the opposite coil turns the relay off. This type of relay has the

advantage that it consumes power only for an instant, while it is being switched, and it retains its

last setting across a power outage. A remanent core latching relay requires a current pulse of

opposite polarity to make it change state.

Reed relay

A reed relay has a set of contacts inside a vacuum or inert gas filled glass tube, which protects

the contacts against atmospheric corrosion. The contacts are closed by a magnetic field generated

when current passes through a coil around the glass tube. Reed relays are capable of faster

switching speeds than larger types of relays, but have low switch current and voltage ratings.

Fig 3.15: Reed relay

Mercury-wetted relay

A mercury-wetted reed relay is a form of reed relay in which the contacts are wetted with

mercury. Such relays are used to switch low-voltage signals (one volt or less) because of their

low contact resistance, or for high-speed counting and timing applications where the mercury

eliminates contact bounce. Mercury wetted relays are position-sensitive and must be mounted

vertically to work properly. Because of the toxicity and expense of liquid mercury, these relays

are rarely specified for new equipment. See also mercury switch.

Polarized relay

A polarized relay placed the armature between the poles of a permanent magnet to increase

sensitivity. Polarized relays were used in middle 20th Century telephone exchanges to detect

faint pulses and correct telegraphic distortion. The poles were on screws, so a technician could

43Department of ECE VMTW

Page 44: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

first adjust them for maximum sensitivity and then apply a bias spring to set the critical current

that would operate the relay.

Machine tool relay

A machine tool relay is a type standardized for industrial control of machine tools, transfer

machines, and other sequential control. They are characterized by a large number of contacts

(sometimes extendable in the field) which are easily converted from normally-open to normally-

closed status, easily replaceable coils, and a form factor that allows compactly installing many

relays in a control panel. Although such relays once were the backbone of automation in such

industries as automobile assembly, the programmable logic controller (PLC) mostly displaced

the machine tool relay from sequential control applications.

Contactor relay

A contactor is a very heavy-duty relay used for switching electric motors and lighting loads.

Continuous current ratings for common contactors range from 10 amps to several hundred amps.

High-current contacts are made with alloys containing silver. The unavoidable arcing causes the

contacts to oxidize; however, silver oxide is still a good conductor. Such devices are often used

for motor starters. A motor starter is a contactor with overload protection devices attached. The

overload sensing devices are a form of heat operated relay where a coil heats a bi-metal strip, or

where a solder pot melts, releasing a spring to operate auxiliary contacts. These auxiliary

contacts are in series with the coil. If the overload senses excess current in the load, the coil is

de-energized. Contactor relays can be extremely loud to operate, making them unfit for use

where noise is a chief concern.

Solid-state relay

44Department of ECE VMTW

Page 45: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.16: Solid state relay

Solid state relay, which has no moving parts

Fig 3.17 :Solid state relay which has no moving parts

25 A or 40 A solid state contactors

A solid state relay (SSR) is a solid state electronic component that provides a similar function to

an electromechanical relay but does not have any moving components, increasing long-term

reliability. With early SSR's, the tradeoff came from the fact that every transistor has a small

voltage drop across it. This voltage drop limited the amount of current a given SSR could handle.

As transistors improved, higher current SSR's, able to handle 100 to 1,200 Amperes, have

become commercially available. Compared to electromagnetic relays, they may be falsely

triggered by transients.

Solid state contactor relay

A solid state contactor is a very heavy-duty solid state relay, including the necessary heat sink,

used for switching electric heaters, small electric motors and lighting loads; where frequent

on/off cycles are required. There are no moving parts to wear out and there is no contact bounce

due to vibration. They are activated by AC control signals or DC control signals from

Programmable logic controller (PLCs), PCs, Transistor-transistor logic (TTL) sources, or other

microprocessor and microcontroller controls.

45Department of ECE VMTW

Page 46: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Buchholz relay

A Buchholz relay is a safety device sensing the accumulation of gas in large oil-filled

transformers, which will alarm on slow accumulation of gas or shut down the transformer if gas

is produced rapidly in the transformer oil.

Forced-guided contacts relay

A forced-guided contacts relay has relay contacts that are mechanically linked together, so that

when the relay coil is energized or de-energized, all of the linked contacts move together. If one

set of contacts in the relay becomes immobilized, no other contact of the same relay will be able

to move. The function of forced-guided contacts is to enable the safety circuit to check the status

of the relay. Forced-guided contacts are also known as "positive-guided contacts", "captive

contacts", "locked contacts", or "safety relays".

Overload protection relay

Electric motors need over current protection to prevent damage from over-loading the motor, or

to protect against short circuits in connecting cables or internal faults in the motor windings. One

type of electric motor overload protection relay is operated by a heating element in series with

the electric motor. The heat generated by the motor current heats a bimetallic strip or melts

solder, releasing a spring to operate contacts. Where the overload relay is exposed to the same

environment as the motor, a useful though crude compensation for motor ambient temperature is

provided.

Pole and throw:

46Department of ECE VMTW

Page 47: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig 3.18: Circuit symbols of relays

\Circuit symbols of relays. "C" denotes the common terminal in SPDT and DPDT types.

Fig 3.19: The diagram on the package of a DPDT AC coil relay

Since relays are switches, the terminology applied to switches is also applied to relays. A relay

will switch one or more poles, each of whose contacts can be thrown by energizing the coil in

one of three ways:

Normally-open (NO) contacts connect the circuit when the relay is activated; the circuit is

disconnected when the relay is inactive. It is also called a Form A contact or "make" contact.

Normally-closed (NC) contacts disconnect the circuit when the relay is activated; the circuit is

connected when the relay is inactive. It is also called a Form B contact or "break" contact.

Change-over (CO), or double-throw (DT), contacts control two circuits: one normally-open

contact and one normally-closed contact with a common terminal. It is also called a Form C

47Department of ECE VMTW

Page 48: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

contact or "transfer" contact ("break before make"). If this type of contact utilizes”make before

break" functionality, then it is called a Form D contact.

The following designations are commonly encountered:

SPST – Single Pole Single Throw. These have two terminals which can be connected or

disconnected. Including two for the coil, such a relay has four terminals in total. It is ambiguous

whether the pole is normally open or normally closed. The terminology "SPNO" and "SPNC" is

sometimes used to resolve the ambiguity.

SPDT – Single Pole Double Throw. A common terminal connects to either of two others.

Including two for the coil, such a relay has five terminals in total.

DPST – Double Pole Single Throw. These have two pairs of terminals. Equivalent to two SPST

switches or relays actuated by a single coil. Including two for the coil, such a relay has six

terminals in total. The poles may be Form A or Form B (or one of each).

DPDT – Double Pole Double Throw. These have two rows of change-over terminals. Equivalent

to two SPDT switches or relays actuated by a single coil. Such a relay has eight terminals,

including the coil.

The "S" or "D" may be replaced with a number, indicating multiple switches connected to a

single actuator. For example 4PDT indicates a four pole double throw relay (with 14 terminals).

3.4.3 Applications:

Relays are used to and for:

Control a high-voltage circuit with a low-voltage signal, as in some types of modems or audio

amplifiers,

Control a high-current circuit with a low-current signal, as in the starter solenoid of an

automobile,

Detect and isolate faults on transmission and distribution lines by opening and closing circuit

breakers (protection relays),

48Department of ECE VMTW

Page 49: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig:3.20 A DPDT AC coil relay with "ice cube" packaging

Isolate the controlling circuit from the controlled circuit when the two are at different potentials,

for example when controlling a mains-powered device from a low-voltage switch. The latter is

often applied to control office lighting as the low voltage wires are easily installed in partitions,

which may be often moved as needs change. They may also be controlled by room occupancy

detectors in an effort to conserve energy,

Logic functions. For example, the boolean AND function is realised by connecting normally

open relay contacts in series, the OR function by connecting normally open contacts in parallel.

The change-over or Form C contacts perform the XOR (exclusive or) function. Similar functions

for NAND and NOR are accomplished using normally closed contacts. The Ladder

programming language is often used for designing relay logic networks.

Early computing. Before vacuum tubes and transistors, relays were used as logical elements in

digital computers. See ARRA (computer), Harvard Mark II, Zuse Z2, and Zuse Z3.

Safety-critical logic. Because relays are much more resistant than semiconductors to nuclear

radiation, they are widely used in safety-critical logic, such as the control panels of radioactive

waste-handling machinery.

Time delay functions. Relays can be modified to delay opening or delay closing a set of contacts.

A very short (a fraction of a second) delay would use a copper disk between the armature and

moving blade assembly. Current flowing in the disk maintains magnetic field for a short time,

lengthening release time. For a slightly longer (up to a minute) delay, a dashpot is used. A

dashpot is a piston filled with fluid that is allowed to escape slowly. The time period can be

49Department of ECE VMTW

Page 50: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

varied by increasing or decreasing the flow rate. For longer time periods, a mechanical

clockwork timer is installed.

Relay application considerations:

Fig 3.21 A relay with two coils and many sets of contacts

A large relay with two coils and many sets of contacts, used in an old telephone switching

system.

Several 30-contact relays in "Connector" circuits in mid 20th century 1XB switch and

5XB switch telephone exchanges; cover removed on one

Selection of an appropriate relay for a particular application requires evaluation of many

different factors:

Number and type of contacts – normally open, normally closed, (double-throw)

Contact sequence – "Make before Break" or "Break before Make". For example, the old

style telephone exchanges required Make-before-break so that the connection didn't get

dropped while dialing the number.

50Department of ECE VMTW

Page 51: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Rating of contacts – small relays switch a few amperes, large contactors are rated for up

to 3000 amperes, alternating or direct current

Voltage rating of contacts – typical control relays rated 300 VAC or 600 VAC,

automotive types to 50 VDC, special high-voltage relays to about 15 000 V

Coil voltage – machine-tool relays usually 24 VAC, 120 or 250 VAC, relays for

switchgear may have 125 V or 250 VDC coils, "sensitive" relays operate on a few mill

amperes

Coil current

Package/enclosure – open, touch-safe, double-voltage for isolation between circuits,

explosion proof, outdoor, oil and splash resistant, washable for printed circuit board

assembly

Assembly – Some relays feature a sticker that keeps the enclosure sealed to allow PCB

post soldering cleaning, which is removed once assembly is complete.

Mounting – sockets, plug board, rail mount, panel mount, through-panel mount,

enclosure for mounting on walls or equipment

Switching time – where high speed is required

"Dry" contacts – when switching very low level signals, special contact materials may be

needed such as gold-plated contacts

Contact protection – suppress arcing in very inductive circuits

Coil protection – suppress the surge voltage produced when switching the coil current

Isolation between coil circuit and contacts

Aerospace or radiation-resistant testing, special quality assurance

Expected mechanical loads due to acceleration – some relays used in aerospace

applications are designed to function in shock loads of 50 g or more

Accessories such as timers, auxiliary contacts, pilot lamps, test buttons

Regulatory approvals

Stray magnetic linkage between coils of adjacent relays on a printed circuit board.

3.4.4 Advantages of relays:

Relays can switch AC and DC, transistors can only switch DC.

51Department of ECE VMTW

Page 52: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Relays can switch high voltages, transistors cannot.

Relays are a better choice for switching large currents (> 5A).

Relays can switch many contacts at once.

3.4.5 Disadvantages of relays:

Relays are bulkier than transistors for switching small currents.

Relays cannot switch rapidly (except reed relays), transistors can switch many times per

second.

Relays use more power due to the current flowing through their coil.

Relays require more current than many ICs can provide, so a low power transistor may be

needed to switch the current for the relay's coil.

CHAPTER 4

52Department of ECE VMTW

Page 53: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

SOFTWARE DESCRIPTION

4.1 PROGRAMMING FOR 8051 MICROCONTROLLER

We are using embedded C programming language to program the microcontroller.

Need of C:

Compiler produces hex file that we download into ROM of microcontroller.

The size of hex file produced by compiler is one of the main concerns of microcontroller

programmers for two reasons:

Microcontroller has limited on -chip ROM

The code space for 8051 is limited to 64 KB

Programming in assembly language is tedious and time consuming. C is a high level

programming language that is portable across many hardware architectures.

Reasons for using Embedded C:

It is easier and less time consuming to write in C than assembly.

C is easier to modify and update.

You can use code available in function libraries.

C code is portable to other microcontrollers with little or no modification.

We use reg51.h as a header file as “#include <reg51.h>”. These files contain all the

definitions of the 80C51 registers. This file is included in your project and will be assembled

together with the compiled output of your C program.

4.1.1 EMBEDDED C COMPILER

53Department of ECE VMTW

Page 54: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

ANSI C - Full featured and portable

Reliable - mature, field-proven technology

Multiple C optimization levels

An optimizing assembler

Full linker, with overlaying of local variables to minimize RAM usage

Comprehensive C library with all source code provided

Includes support for 24-bit and 32-bit IEEE floating point and 32-bit long data types

Mixed C and assembler programming

Unlimited number of source files

Listings showing generated assembler

Runs on multiple platforms: Windows, Linux, UNIX, Mac OS X, Solaris

We can compile, with assemble and link our embedded application a single step.

Optionally, the compiler may be run directly from the command line, allowing you to

compile, assemble and link using one command. This enables the compiler to be integrated into

third party development environments, such as Microchip's MPLAB IDE.

Simulator

Simulator is a machine that simulates an environment for the purpose of training.

Compiler

A compiler is a program that reads a program in one language, the source language and translates

into an equivalent program in another language, the target

Language

The translation process should also report the presence of errors in the source program.

4.2 KEIL µVISION

54Department of ECE VMTW

Page 55: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

KEIL Software

Keil compiler is software used where the machine language code is written and compiled. After

compilation, the machine source code is converted into hex code which is to be dumped into the

microcontroller for further processing. Keil compiler also supports C language code.

Steps To Write a C Program In Keil And Compile It

Install the Keil Software in the PC in any of the drives.

After installation, an icon will be created with the name “Keil µVision3”. Just drag this icon

onto the desktop so that it becomes easy whenever you try to write programs in keil.

Double click on this icon to start the keil compiler.

A page opens with different options in it showing the project workspace at the leftmost

corner side, output window in the bottom and an ash coloured space for the program to be

written.

Now to start using the keil, click on the option “project”.

A small window opens showing the options like new project, import project, open project

etc. Click on “New project”.

A small window with the title bar “Create new project” opens. The window asks the user to

give the project name with which it should be created and the destination location. The

project can be created in any of the drives available. You can create a new folder and then a

new file or can create directly a new file.

After the file is saved in the given destination location, a window opens where a list of

vendors will be displayed and you have to select the device for the target you have created.

The most widely used vendor is Atmel. So click on Atmel and now the family of

microcontrollers manufactured by Atmel opens. You can select any one of the

microcontrollers according to the requirement.

When you click on any one of the microcontrollers, the features of that particular

microcontroller will be displayed on the right side of the page. The most appropriate

55Department of ECE VMTW

Page 56: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

microcontroller with which most of the projects can be implemented is the AT89C51. Click

on this microcontroller and have a look at its features. Now click on “OK” to select this

microcontroller.

A small window opens asking whether to copy the startup code into the file you have created

just now. Just click on “No” to proceed further.

Now you can see the TARGET and SOURCE GROUP created in the project workspace.

Now click on “File” and in that “New”. A new page opens and you can start writing program

in it.

After the program is completed, save it with any name but with the .asm extension. Save the

program in the file you have created earlier.

You can notice that after you save the program, the predefined keywords will be highlighted

in bold letters.

Now add this file to the target by giving a right click on the source group. A list of options

open and in that select “Add files to the source group”. Check for this file where you have

saved and add it.

Right click on the target and select the first option “Options for target”. A window opens

with different options like device, target, output etc. First click on “target”.

Since the set frequency of the microcontroller is 11.0592 MHz to interface with the PC, just

enter this frequency value in the Xtal (MHz) text area and put a tick on the Use on-chip

ROM. This is because the program what we write here in the keil will later be dumped into

the microcontroller and will be stored in the inbuilt ROM in the microcontroller.

Now click the option “Output” and give any name to the hex file to be created in the “Name

of executable” text area and put a tick to the “Create HEX file” option present in the same

window. The hex file can be created in any of the drives. You can change the folder by

clicking on “Select folder for Objects”.

56Department of ECE VMTW

Page 57: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Now to check whether the program you have written is errorless or not, click on the icon

exactly below the “Open file” icon which is nothing but Build Target icon. You can even use

the shortcut key F7 to compile the program written.

To check for the output, there are several windows like serial window, memory window,

project window etc. Depending on the program you have written, select the appropriate

window to see the output by entering into debug mode.

The icon with the letter “d” indicates the debug mode.

Click on this icon and now click on the option “View” and select the appropriate window to

check for the output.

After this is done, click the icon “debug” again to come out of the debug mode.

The hex file created as shown earlier will be burned into the microcontroller ROM with the

help of software called µFLASH.

Steps

Create a Project File

To create a new project file select from the µVision menu Project – New Project…. This

opens a standard Windows dialog that asks you for the new project file name.

We suggest that you use a separate folder for each project. You can simply use the icon

Create New Folder in this dialog to get a new empty folder. Then select this folder and enter the

file name for the new project, i.e. Project1. µVision creates a new project file with the name

PROJECT1.UV2 which contains a default target and file group name. You can see these names

in the Project Workspace – Files.

Select a Device

When you create a new project µVision asks you to select a CPU for your project. The

Select Device dialog box shows the µVision device database. Just select the microcontroller you

use. We are using for our examples the Philips 80C51RD+ controller. This selection sets

57Department of ECE VMTW

Page 58: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

necessary tool options for the 80C51RD+ device and simplifies in this way the tool

configuration.

Fig 4.1 select device

Once you have selected a CPU from the device database you can open the user manuals

for that device in the Project Workspace – Books page. These user manuals are part of the Keil

Development Tools CD-ROM that should be present in your CD drive.

58Department of ECE VMTW

Page 59: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Fig: 4.2 select cd drive

Create New Source Files

You may create a new source file with the menu option File – New. This opens an empty

editor window where you can enter your source code. µVision enables the C color syntax

highlighting when you save your file with the dialog File – Save As… under a filename with the

extension *.C. We are saving our example file under the name MAIN.C.

Fig: 4.3 Create New Source Files

59Department of ECE VMTW

Page 60: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Add and Configure the Startup Code

The STARTUP.A51 file is the startup code for the most 8051 CPU variants. The startup

code clears the data memory and initializes hardware and reentrant stack pointers. In addition,

some 8051 derivatives require a CPU initialization code that needs to match the configuration of

your hardware design. For example, the Philips 8051RD+ offers you on-chip xdata RAM that

should be enabled in the startup code. Since you need to modify that file to match your target

hardware, you should copy the STARTUP.A51 file from the folder C:\KEIL\C51\LIB to your

project folder.

Group Project Files

File group allow you to organize large projects. For the CPU startup code and other

system configuration files you may create a own file group in the Project – Components,

Environment, Books… dialog box. Use the New (Insert) button to create a file group named

System Files. In the project window you may drag and drop the STARTUP.A51 file to this new

file group.

Fig: 4.4 Group Project Files

60Department of ECE VMTW

Page 61: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Now, the Project Workspace – Files lists all items of your project.  To open a file for

editing, double click on the file name in the Project Workspace. You may need to configure the

startup STARTUP.A51 in the editor.

Set Tool Options for Target

µVision lets you set options for your target hardware. The dialog Options for Target

opens via the toolbar icon or via the Project - Options for Target menu item. In the Target tab

you specify all relevant parameters of your target hardware and the on-chip components of the

device you have selected. The following the settings for our example are shown.

Fig: 4.5 Set Tool Options for Target

61Department of ECE VMTW

Page 62: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Build Project and Create a HEX File

Typical, the tool settings under Options – Target are all you need to start a new

application. You may translate all source files and line the application with a click on the Build

Target toolbar icon. When you build an application with syntax errors, µVision will display

errors and warning messages in the Output Window – Build page. A double click on a message

line opens the source file on the correct location in a µVision editor window.

Fig: 4.6 Build Project and Create a HEX File

Once you have successfully generated your application you can start debugging as

described under Testing Programs with the µVision Debugger. 

Now you may modify existing source code or add new source files to the project. The

Build Target toolbar button translates only modified or new source files and generates the

executable file. µVision maintains a file dependency list and knows all include files used within

a source file. Even the tool options are saved in the file dependency list, so that µVision rebuilds

files only when needed. With the Rebuild Target command, all source files are translated,

regardless of modifications.

After you have tested your application, it might be required to create an Intel HEX file

and to download the application software into the physical device using a Flash programming

utility. µVision creates HEX files with each build process when Create HEX files under Options

for Target – Output is enabled. The Merge32K Hex file option is available for Code Banking

Applications when you have selected the Extended Linker LX51. You may start your Flash

programming utility after the make process when you specify the program under the option Run

User Program #1.

62Department of ECE VMTW

Page 63: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

4.3 µFLASH

µFLASH is a PC tool for programming flash based microcontrollers from NXP using a

serial protocol while in the target hardware. 

Features

Straightforward and intuitive user interface

Five simple steps to erasing and programming a device and setting any options desired

Programs Intel Hex Files

Automatic verifying after programming

Fills unused Flash to increase firmware security

Ability to automatically program checksums. Using the supplied checksum calculation

routine your firmware can easily verify the integrity of a Flash block, ensuring no

unauthorized or corrupted code can ever be executed

Program security bits

63Department of ECE VMTW

Page 64: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Check which Flash blocks are blank or in use with the ability to easily erase all blocks in

use

Read the device signature

Read any section of Flash and save as an Intel Hex File

Reprogram the Boot Vector and Status Byte with the help of confirmation features that

prevent accidentally programming incorrect values

Display the contents of Flash in ASCII and Hexadecimal formats

Single-click access to the manual, Flash Magic home page and NXP Microcontrollers

home page

Ability to use high-speed serial communications on devices that support it. Flash Magic

calculates the highest baud rate that both the device and your PC can use and switches to

that baud rate transparently

Command Line interface allowing Flash Magic to be used in IDEs and Batch Files

Manual in PDF format

Supports half-duplex communications

Verify Hex Files previously programmed

Save and open settings

Able to control the DTR and RTS RS232 signals when connected to RST and /PSEN to

place the device into Boot ROM and Execute modes automatically. An example circuit

diagram is included in the Manual. Essential for ISP with target hardware that is hard to

access.

Able to send commands to place the device in Boot ROM mode, with support for

command line interfaces. The installation includes an example project for the Keil and

Resonance 8051 compilers that show how to build support for this feature into

applications.

Able to play any Wave file when finished programming.

Built in automated version checker - helps ensure you always have the latest version.

Powerful, flexible Just In Time Code feature. Write your own JIT Modules to generate

last minute code for programming. Uses include:

Serial number generation 

Copy protection and copy authorization 

64Department of ECE VMTW

Page 65: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Storing program date and time - manufacture date 

Storing program operator and location 

Lookup table generation 

Language tables or language selection

Centralized record keeping

Obtaining latest firmware from the Corporate Web site or project intranet

Sponsored by NXP Semiconductors

Features automatically updating Internet links including links to related technical

documents, software updates, utilities and code examples, using Embedded Hints

technology

Displays information about the selected Hex File, including the creation and modification

dates, flash memory used, percentage of the current device used.

4.4 PRINTED CIRCUIT BOARD

Printed circuit boards may be covered in two topics namely

1) Technology

2) Design

Introduction to printed circuit boards:

It is called PCB in short printed circuit consists of conductive circuit pattern

Applied to one or both sides of an insulating base, depending upon that, it is called single sided

PCB or double-sided PCB.(SSB and DSB).

Conductor materials available are silver, brass, aluminium and copper. Copper is most

widely used. The thickness of conducting material depends upon the current carrying capacity of

circuit. Thus a thicker copper layer will have more current carrying capacity.

The printed circuit boards usually serves three distinct functions.

1) it provides mechanical support for the components mounted on it.

2) It provides necessary electrical interconnections.

65Department of ECE VMTW

Page 66: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

3) It acts as heat sink that is provides a conduction path leading to removal of the heat

generated in the circuit.

Advantages of PCB:

1) When a number of identical assemblies are required. PCB’s provide cost saving because

once a layout is approved there is no need to check the circuit every time.

2) For large equipments such as computers, the saving on checking connections or wires is

substantial.

3) PCB’s have controllable and predictable electrical and mechanical properties.

4) A more uniform product is produced because wiring errors are eliminated.

5) The distributed capacitances are constant from one production to another.

6) Soldering is done in one operation instead of connecting discrete components by wires.

7) The PCB construction lands itself for automatic assembly.

8) Spiral type of inductors may be printed.

9) Weight is less.

10) It has miniaturization potential.

11) It has reproducible performance.

12) All the signals are accessible for testing at any point along conductor track.

4.5. PCB Layout Design with Proteus

Generally we are listening the words PCB’s, PCB layout, PCB designing, ect. But what is

PCB? Why we are using this PCB? We want to know about all these things as a electronic

engineer. PCB means Printed Circuit Board. This is a circuit board with printed copper

66Department of ECE VMTW

Page 67: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

layout connections. These PCB’s are two types. One is dotted PCB and another one is layout

PCB. The two examples are shown in below.

Fig 4.7: Dotted PCB Fig 4.8: Layout PCB

What is the main difference between the dotted PCB and layout PCB? 

In dotted PCB board only dots are available. According to our requirement we can place

or insert the components in those holes and attach the components with wires and soldering lid.

In this dotted PCB we can make the circuit as out wish but it is very hard to design. There are so

many difficulties are there. Those are connecting the proper pins, avoiding shot connections and

etc. Coming to the layout PCB this is simple to design. First we select the our circuit and by

using different PCB designing software’s, design the layout of the circuit and by itching process

preparing the copper layout of our circuit and solder the components in the correct places. It is

simple to design, take less time to design, no shortages, looking nice and perfect.

Up to now we have discussed about types of PCB’s and difference between the types. Now we

can discuss about PCB designing software. There are so many PCB designing softwares

available. Some are Express PCB, eagle PCB, PCB Elegance, free PCB, open circuit

design,zenith PCB and Proteus etc. Apart from remaining Proteus is different. Proteus is design

suit and PCB layout designing software. In Proteus we can design any circuit and simulate the

circuit and make PCB layout for that circuit.

67Department of ECE VMTW

Page 68: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

Introduction to Proteus:

Proteus professional is a software combination of ISIS schematic capture program and ARES

PCB layout program. This is a powerful and integrated development environment. Tools in this

suit are very easy to use and these tools are very useful in education and professional PCB

designing. As professional PCB designing software with integrated space based auto router, it

provides features such as fully featured schematic capture, highly configurable design rules,

interactive SPICE circuit simulator, extensive support for power planes, industry standard

CADCAM & ODB++ output and integrated 3D viewer.

Up to know we have discussed about the basics and software description. Now we are

entering into the designing section. Run the ISIS professional program by clicking the icon on

the desktop, then this splash screen will appear.

 

Next, a work space with interface buttons for designing circuit will appear as

shown in figure below. Note that there is a blue rectangular line in the workspace; make sure that

whole circuit is designed inside the rectangular space.

68Department of ECE VMTW

Page 69: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

69Department of ECE VMTW

Page 70: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

CHAPTER 5

SOURCE CODE

#include<reg52.h>

sbit pir1=P2^7;

sbit pir2=P2^6;

sbit pir3=P2^5;

sbit pir4=P2^4;

sbit relay1=P3^7; //bulb

sbit relay2=P3^6; //fan

sbit temp=P1^0;

sbit led=P2^0;

void delay(unsigned int time) // delay function

{

unsigned int i,j;

for(i=0;i<time;i++)

for(j=0;j<1275;j++);

}

void main()

{

pir1=pir2=pir3=pir4=0;

led=relay1=relay2=0;

70Department of ECE VMTW

Page 71: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

while(1)

{

led=1;

delay(100);

led=0;

delay(100);

led=1;

delay(100);

led=0;

delay(100);

if(pir1==1)

{

relay1=1;

led=1;

}

else if(pir2==1)

{

relay1=1;

led=1;

}

else if(pir3==1)

71Department of ECE VMTW

Page 72: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

{

relay1=1;

led=1;

}

else if(pir4==1)

{

relay1=1;

led=1;

}

else if(temp==1)

{

relay2=1;

led=1;

}

else

{

relay1=relay2=0;

led=0;

}

}

}

72Department of ECE VMTW

Page 73: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

CONCLUSION

The project “PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND

CONFERENCE HALL” has been successfully completed and tested with integration of the

features of every hardware component for its development. Presence of every block has been

reasoned out and placed carefully thus contributing to the best working of the unit.

The project is built using very simple and easily available components making it

lightweight and portable. This helps for power saving and decreasing manual work purpose in

important areas.

We believe that our step is towards complete automation for different electrical loads in home and

industries.

Finally we conclude that this project application gives very good features and there is huge scope

for further research and development

73Department of ECE VMTW

Page 74: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

REFERENCE AND BIBILIOGRAPHY

Books

1. Kennedy,’ Electronic Communication Systems’, McGraw-Hill Publ, 2001

2. D.Roy Chowdhury, ‘Linear Integrated Circuits’, New Age International (P) Ltd., 2003

3. Kenneth J.Ayala,’The 8051 MicroController,’Penram International, Second edition, 1997

4. Douglas V. Hall,’ Micro Processor and Interfacing’, TMH, Second Edition.

5. A.K.Ray and K.M.Bhurchandi.’ Advanced Micro Processors and Peripherals,’ TMH,

2000.

6. The 8051 Microcontroller and Embedded Systems Using Assembly and C , second

edition Muhammad Ali Mazidi., Janice Gillispie Mazidi, Rolin D. McKinlay

Websites

1. www.nationalsemicondutor.com

2. www.atmel.com

3. www.wikipedia.org

4. www.discovercircuits.com .

74Department of ECE VMTW

Page 75: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

75Department of ECE VMTW

Page 76: pir sensor based energy saver

PIR SENSOR BASED POWER SAVER FOR AUDITORIUM AND CONFERENCE HALL MN12-B2

76Department of ECE VMTW


Recommended