Top Banner
NLS (NIGHT LIGHT SAVER) 2011 ECE, MIT MANDSAUR Page 1 CHAPTER: 1 INTRODUCTION Engineering is not only a theoretical study but it is a implementation of all we study for creating something new and making things more easy and useful through practical study. It is an art which can be gained with systematic study, observation and practice. In the college curriculum we usually get the theoretical knowledge of industries, and a little bit of implementation knowledge that how it is works? But how can we prove our practical knowledge to increase the productivity or efficiency of the industry? Just imagine a light which automatically turns ON and OFF at a particular time. It obviously suits the daily routine of a person such that he/she doesn’t need to take care of the light. This also saves electricity, and hence is known as NLS (Night Light Saver). This microcontroller based project is very useful especially for personal use. The saver turns a night light on and off with preset time. The design features low cost, easy installation, no battery backup and no EMI. The microcontroller used is AT89C2051. The AT89C2051 uses external oscillator generated by Schmitt trigger gate CD4093, ~680kHz. Reference frequency was derived from 50Hz main line. If main line has failed, functioning LED will blink at high rate. Since there is no battery backup, thus repressing the button is then needed. Fig 1: Microcontroller based NLS
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 1

CHAPTER: 1

INTRODUCTION –

Engineering is not only a theoretical study but it is a implementation of all we study for creating

something new and making things more easy and useful through practical study. It is an art

which can be gained with systematic study, observation and practice. In the college curriculum

we usually get the theoretical knowledge of industries, and a little bit of implementation

knowledge that how it is works? But how can we prove our practical knowledge to increase the

productivity or efficiency of the industry?

Just imagine a light which automatically turns ON and

OFF at a particular time. It obviously suits the daily routine of a person such that he/she doesn’t

need to take care of the light. This also saves electricity, and hence is known as NLS (Night

Light Saver). This microcontroller based project is very useful especially for personal use.

The saver turns a night light on and off with preset time. The design features low

cost, easy installation, no battery backup and no EMI. The microcontroller used is AT89C2051.

The AT89C2051 uses external oscillator generated by Schmitt trigger gate CD4093, ~680kHz.

Reference frequency was derived from 50Hz main line. If main line has failed, functioning LED

will blink at high rate. Since there is no battery backup, thus repressing the button is then

needed.

Fig 1: Microcontroller based NLS

Page 2: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 2

CHAPTER: 2

CIRCUIT DIAGRAM –

Fig 1: Circuit Diagram of NLS

Explanation of the circuit operation for each part is as follows:

1) R1 and C1 form a simple current limiting AC source. D1 and D2 converts AC to DC with C2

performing a reservoir. D3 limits voltage across the circuit to ~5V.

2) External oscillator: A reliable Schmitt gate oscillator with R8 and C5 produces clock approx.

680 kHz. One machine cycle is ~18us.

3) 89C2051 circuits: C4, 33uF and R4, 10k forms a reset circuit that need time for raising logic

at least two machines cycle. S1 is a momentary button for setting time to 18:00 by pulling P3.0

to logic low. The functioning LED is connected to P3.7. Q2 is a small Triac MAC97A6, and is

derived by Q1, PNP transistor sinking through P1.7.

4) Reference frequency: R3 and C3 integrate a 50Hz main frequency and unwanted transients

producing triangle-like waveform which is fed to U2 Schmitt gate. The output pin4 is clean 50Hz

square wave tied to int0.

Page 3: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 3

CHAPTER: 3

COMPONENTS LISTING AND DESCRIPTION –

The components used in this project are as following:

C1 0.44 uF 250Vac AC capacitor

C2 330 uF 25V electrolytic capacitor

C3 1uF 16V nonpolar polyester capacitor

C4 33uF 16V electrolytic capacitor

C5 50pF disceramic capacitor

R1 50Ohm 1/4W resistor

R2 1M 1/4W

R3,R4,R8 10k 1/4W

R5 220Ohm 1/4W

R6,R7 1k 1/4W

D1,D2 1N4007 rectifying diode

D3 zener diode 5.1V 1/2W

D4 small LED

Q1 2N2907 PNP transistor

Q2 MAC97A6 triac

U1 AT89C2051 Flash Microcontroller

U2 CD4093 schmitt nand gate

T1 Transformer

Page 4: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 4

Capacitor :

Fig 1: Different types of capacitors: From left: multilayer ceramic, ceramic disc, multilayer polyester film,

tubular ceramic, polystyrene, metalized polyester film, aluminum electrolytic. Major scale divisions are in

centimeters.

A capacitor (formerly known as condenser) is a device for storing electric charge. The forms of

practical capacitors vary widely, but all contain at least two conductors separated by a non-

conductor. Capacitors used as parts of electrical systems, for example, consist of metal foils

separated by a layer of insulating film.

A capacitor is a passive electronic component consisting of a pair

of conductors separated by a dielectric (insulator). When there is a potential difference (voltage)

across the conductors, a static electric field develops across the dielectric, causing positive

charge to collect on one plate and negative charge on the other plate. Energy is stored in the

electrostatic field. An ideal capacitor is characterized by a single constant value, capacitance,

measured in farads. This is the ratio of the electric charge on each conductor to the potential

difference between them.

Page 5: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 5

Resistor :

A resistor is a two-terminal passive electronic

component which implements resistances a

circuit element. When a voltage V is applied

across the terminals of a resistor, a current I

will flow through the resistor in direct

proportion to that voltage. Resistors are

common elements of electrical networks and

electronic circuits and are ubiquitous in most

electronic equipment. Practical resistors can be

made of various compounds and films, as well

as resistance wire (wire made of a high-

resistivity alloy, such as nickel-chrome).

Resistors are also implemented

within integrated circuits, particularly analog

devices, and can also be integrated

into hybrid and printed circuits.

Fig 2: Various types of Resistances

Rectifying Diode :

Rectifier diodes are used in power supplies to convert alternating

current (AC) to direct current (DC), a process called rectification.

They are also used elsewhere in circuits where a large current must

pass through the diode. All rectifier diodes are made from silicon and

therefore have a forward voltage drop of 0.7V. The 1N4001 is suitable

for most low voltage circuits with a current of less than 1A.

Fig 3: Rectifying Diodes

Page 6: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 6

Zener Diode: A Zener diode is a type of diode that

permits current not only in the forward direction like a normal diode,

but also in the reverse direction if the voltage is larger than

the voltage known as "Zener knee voltage" or "Zener voltage". The

device was named after Clarence Zener, who discovered this

electrical property.

Fig 4: Zener Diode

Light Emitting Diode : A light-emitting diode is

a semiconductor light source. LEDs are used as indicator

lamps in many devices and are increasingly used for

other lighting. When a light-emitting diode is

forward biased (switched on), electrons are able

to recombine with electron within the device, releasing

energy in the form of photons. This effect is called

electroluminescence and the color of the light

(corresponding to the energy of the photon) is determined by

the energy gap of the semiconductor.

Fig 5: LED

PNP Transistor : The PNP consists of a layer of N-

doped semiconductor between two layers of P-doped material. A

small current leaving the base is amplified in the collector output.

That is, a PNP transistor is "on" when its base is pulled low relative

to the emitter. The majority current carriers in the PNP transistor are

holes.

Fig 6: PNP Transistor

Page 7: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 7

TRIAC : TRIAC, from Triode for Alternating Current, is

a generalized tradename for an electronic

component which can conduct current in either direction

when it is triggered (turned on), and is formally called

a bidirectional triode thyristor or bilateral triode thyristor.

A TRIAC is approximately equivalent to two

complementary unilateral thyristors (one is anode

triggered and another is cathode triggered SCR) joined

Fig 7: TRIAC

in inverse parallel (paralleled but with the polarity reversed) and with their gates connected

together. It can be triggered by either a positive or a negative voltage being applied to

its gate electrode (with respect to A1, otherwise known as MT1). Once triggered, the device

continues to conduct until the current through it drops below a certain threshold value,

the holding current, such as at the end of a half-cycle of alternating current (AC) mains power.

This makes the TRIAC a very convenient switch for AC circuits, allowing the control of very

large power flows with milliampere-scale control currents. In addition, applying a trigger pulse

at a controllable point in an AC cycle allows one to control the percentage of current that flows

through the TRIAC to the load (phase control).

AT89C2051 Flash Microcontroller : The

AT89C2051 is a low-voltage, high-performance

CMOS 8-bit microcomputer with 2K bytes of

Flash programmable and erasable read only

memory (PEROM). The device is manufactured

using Atmel’s high-density nonvolatile memory

technology and is compatible with the industry-

standard MCS-51 instruction set. By combining a

Fig 8: AT89C2051 Flash Microcontroller

Page 8: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 8

versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C2051 is a powerful

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

control applications.

Features

Compatible with MCS-51 ™ Products

2K Bytes of Reprogrammable Flash Memory – Endurance: 1,000 Write/Erase Cycles

2.7V to 6V Operating Range

Fully Static Operation: 0 Hz to 24 MHz

Two-level Program Memory Lock

128 x 8-bit Internal RAM

15 Programmable I/O Lines

Two 16-bit Timer/Counters

Six Interrupt Sources

Programmable Serial UART Channel

Direct LED Drive Outputs

On-chip Analog Comparator

Low-power Idle and Power-down Modes

Green (Pb/Halide-free) Packaging Option

Page 9: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 9

CD4093 Schmitt Nand Gate : The CD4093B consists

of four Schmitt-trigger circuits. Each circuit functions as a

2-input NAND gate with Schmitt-trigger action on both

inputs. The gate switches at different points for positive and

negative-going signals. The difference between the positive

(VTa) and the negative voltage (VTb) is defined as

hysteresis voltage (VH). All outputs have equal source and

sink currents and conform to standard B-series output drive.

Fig 9: NAND Gate

Transformer : A transformer makes use of Faraday's

law and the ferromagnetic properties of an iron to

efficiently raise or lower AC voltages. It of course

cannot increase power so that if the voltage is raised,

the current is proportionally lowered and vice versa.

Electronic transformers are usually much smaller and

lighter, so tend to lack the "solid quality" feel, but most

are either reasonably or very efficient, typically wasting

less than 10% of the total power. Lower losses mean

less heat and marginally lower power bills. Although

the dissipation of each unit individually may seem

reasonable, when thousands of them are running the

extra loss becomes significant.

Fig 10: Transformer

Page 10: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 10

CHAPTER: 4

PCB DESIGNING –

Layout Formation

Integrated circuit layout, also known IC layout, IC mask layout, or mask design, is the

representation of an integrated circuit in terms of planar geometric shapes which correspond to

the patterns of metal, oxide, or semiconductor layers that make up the components of the

integrated circuit. IC Layout is done with the aid of editor software, or even automatically

using EDA tools, including place and route tools or schematic driven layout tools. For designing

the layout from the circuit diagram we have used the “EAGLE” software.

Fig 1: Layout formation in EAGLE software

Page 11: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 11

The final layout prepared is as following:

Fig 2: Layout of NLS

Layout Masking on Copper Plate

The layout thus drawn is printed on a glossy paper.

Fig 3: Print out of the layout prepared

Page 12: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 12

Then it is masked or pasted on a copper plate. This is done using a red hot iron.

Fig 4: Ironing

After that, etching is done (to remove the unwanted copper) using FeCl3. The final view of PCB

after etching is as following:

Fig 5: Final view of PCB

Drilling

Holes through a PCB are typically drilled with tiny drill bits made of solid tungsten carbide.

The drilling is performed by automated drilling machines with placement controlled by

a drill tape or drill file. These computer-generated files are also called numerically controlled

drill (NCD) files or "Excellon files". The drill file describes the location and size of each

Page 13: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 13

drilled hole. These holes are often filled with annular rings (hollow rivets) to create vias.

Vias allow the electrical and thermal connection of conductors on opposite sides of the PCB.

The PCB after drilling looks like:

Fig 6: View after Drilling

After all these processes, the components are mounted upon the PCB and are thus soldered upon.

Page 14: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 14

CHAPTER: 5

PROGRAMMING THE MICROCONTROLLER –

Microcontrollers were originally programmed only in assembly language, but various high-level

programming languages are now also in common use to target microcontrollers. These languages

are either designed specially for the purpose, or versions of general purpose languages such as

the C programming language. Compilers for general purpose languages will typically have some

restrictions as well as enhancements to better support the unique characteristics of

microcontrollers. Some microcontrollers have environments to aid developing certain types of

applications. Microcontroller vendors often make tools freely available to make it easier to adopt

their hardware.

Here we have used “MICRO C” compiler and have generated the .hex file.

Fig 1: Compiling a program

Page 15: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 15

After the generation of the hex code, the .hex file is burned into the microcontroller using a

burner.

Fig 2: Burning of HEX Code

Page 16: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 16

CHAPTER: 6

SOURCE CODE –

#include c:\mc51\8051io.h

#include c:\mc51\8051reg.h

/*-------- turn lamp on/off after reset time to 18:00 ---------*/

#define onHour1 18 /* 18:00 turn lamp on */

#define onMin1 00

#define offHour1 18 /* 18:01 turn off */

#define offMin1 01

/* every day turn on at 19:00 and and off at 22:00 */

#define onHour2 19

#define onMin2 00

#define offHour2 22

#define offMin2 00

/* set clock to 18:00 when press P3.0 */

#define setHour 18

#define setMin 00

/*-------------------------------------------------------------*/

extern register char cputick;

unsigned register char sec25,sec50,sec,sec5,min,hour,flag1,temp,led,blink_rate;

/* variables description

cputick - increments by one every 20ms

sec25 - half second counter, sec50 - 2*25Hz counter

sec - current second, sec5 - 5 second counter

min - current min, hour - current hour

temp - temp register, led - counter for led on duration (times cputick)

blink_rate 0 = high blink rate, 10 low blink rate

flag1 - intertask signaling (mask byte), flag1.0 - set every 1 second (0x01)

Page 17: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 17

flag1.1 - set every 1 min (0x02), flag1.2 - not use (0x04)

flag1.3 - set every 0.5 second (0x08), flag1.4 - set after P3.2 has been pressed (0x10)

flag1.5 - disable turn on/off 18:00-18:01 if set (0x20), flag1.6-7 (not use)

*/

main()

{

cputick = 0;

hour = 18;

min = 0;

sec = 0;

sec25 = 0;

sec50 = 0;

flag1 = 0;

blink_rate = 0; /* indicate reset time to 18:00 is needed */

asm "LAMP EQU $97"; /* P1.7 */

asm{

SETB $AF /* setb EA */

SETB $A8 /* enable external interrupt */

SETB $88 /* negative edge triggering */

}

while(1)

{

while ( cputick < 1);

cputick = 0; /* 20ms has elapsed */

/*------------- the following tasks execute every 10ms ------*/

time();

comparetime();

cpubeat();

settime();

/* waithigh(); */

Page 18: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 18

}

/*-----------------------------------------------------------*/

}

time ()

/* update real-time clock, date */

{

sec25++;

if (sec25 >= 25) /* now 25 times means half second */

{sec25 = 0;

flag1 |= 0x08; /* set bit 3 every 0.5 s */

sec50++;

if (sec50 >= 2) /* 2 * 25 * 20 ms = 1 s */

{sec50 = 0;

flag1 |= 0x01; /* set bit 0 */

sec++;

if (sec >= 60)

{sec = 0;

flag1 |= 0x02; /* set bit 1 */

min++;

if (min >= 60)

{min = 0;

hour++;

if (hour >= 24)

{hour = 0;

}

}

}

}

}

}

Page 19: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 19

comparetime()

{

if ((flag1 & 0x10) != 0) /* enabled only after P3.2 has been pressed */

{

compareTimeOn_Off();

}

}

compareTimeOn_Off()

{

if ((flag1 & 0x01)!=0)

{

testOnOff();

if(hour == onHour2 && min == onMin2)

asm" CLR LAMP";

if(hour == offHour2 && min == offMin2)

asm" SETB LAMP";

}

}

testOnOff()

{

if ((flag1 & 0x20) == 0)

{

if(hour == onHour1 && min == onMin1)

asm" CLR LAMP";

if(hour == offHour1 && min == offMin1)

{

asm" SETB LAMP";

flag1 |= 0x20; /* disable further test on off */

}

}

Page 20: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 20

}

cpubeat()

{

beat5sec();

livecpu();

}

beat5sec() /* clear P3.7 every blink rate */

{

if ((flag1 & 0x08)!=0)

{

flag1 &= ~0x08; /* clear bit 3 of flag1 */

sec5++;

if (sec5 > blink_rate)

{sec5 = 0;

flag1 |= 0x40; /* set bit 6 of flag1 to signal livecpu task */

asm " clr P3.7"; /* make led on */

led = 2; /* load time on duration times cputick */

}

}

}

livecpu()

{

if ((flag1 & 0x40) != 0)

{

led--;

if (led == 0)

{

asm " setb P3.7";

flag1 &= ~0x40;

}

Page 21: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 21

}

}

settime()

{

if ((P3 & 0x01) == 0) /* reset time to 18:00 if P3.1 low */

{

hour = setHour;

min = setMin;

sec = 0;

sec50 = 0;

flag1 |= 0x10; /* enable compare time on/off */

flag1 &= ~0x20; /* reenable testOnOff after pressing set clock to 18:00 */

blink_rate = 10;

}

}

/*

waithigh()

{

asm" jnb P3.2,*"; pause(2); asm" jnb P3.2,*"; pause(2);

}

pause(j)

int j;

{

int i;

for (i=0;i<j;i++);

}

*/

Page 22: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 22

CHAPTER: 7

BLOCK DIAGRAM AND ITS WORKING – The block diagram of NLS is as

following:

AC

SUPPLY

~ 680 kHz

50 Hz

Fig1: Block Diagram of NLS

WORKING – AC supply through transformer is converted into DC. This DC along with two

other frequencies (generated from the two nand gates), 50 Hz & 680 kHz, is given to the

microcontroller as input. The output from the microcontroller is given to a PNP transistor. And

the output from transistor is again given to the TRIAC. The final output i.e., the bulb glowing, is

obtained on the two legs of the TRIAC.

TRANSFORMER

MICROCON

-TROLLER

AT89C2051

PNP TRANSIS-

TOR TRIAC

BULB (O/P)

NAND GATE

NAND GATE

Page 23: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 23

CHAPTER: 8

TESTING AND MEASURMENT – Whenever an AC supply is given to the circuit, after

pressing the switch, both the LED’s will glow. The red LED indicates that the circuit is in

running mode. The latter LED just glows for a minute and then automatically turns OFF, which

is in accordance with the coding.

If the red LED blinks at a higher rate, it indicates power

failure. The figure below shows the project is in running mode.

Fig 1: Final View of the Circuit along with testing and measurements

Page 24: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 24

CHAPTER: 9

ADVANTAGES, DISADVANTAGES, APPLICATIONS AND FUTURE

ENHANCEMENT –

Advantages :

It saves electricity and energy.

It is cheaper.

It is easy to use.

It is portable.

There is no need of battery.

Disadvantages :

It gets OFF after a fixed interval of time (not according to our wish).

Applications :

Used in homes for saving electricity.

In street lights.

In offices and public places.

Future Enhancement : In future, the source code can be modified to a certain extent and

can be made more user-friendly. Even the AC supply can also be eliminated. By

generating more frequency, bulbs with larger power capability can also glow.

Page 25: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 25

CHAPTER: 10

CONCLUSION –

Finally in conclusion the NLS (Night Light Saver) is a very useful circuit that can be used by

each and every one. Just imagine a light which automatically turns ON and OFF at a particular

time. It obviously suits the daily routine of a person such that he/she doesn’t need to take care of

the light. This also saves electricity, and hence is known as NLS (Night Light Saver). This

microcontroller based project is very useful especially for personal use. It is portable, cheap, easy

to use and it also saves electricity.

Despite being its various advantages, it has a disadvantage that is it

cannot be timed or scheduled by each and every one. Further, in future it can be extended such

that its major drawback of time scheduling may be eliminated.

Page 26: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 26

APPENDIX I

AT89C2051 Microcontroller

Page 27: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 27

Page 28: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 28

Page 29: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 29

APPENDIX II

MAC97A6 Triac –

Page 30: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 30

APPENDIX III

CD4093 Schmitt Nand Gate –

Page 31: Night Light Saver

NLS (NIGHT LIGHT SAVER) 2011

E C E , M I T M A N D S A U R

Page 31

APPENDIX IV

References –

i) www.kmitl.ac.th/~kswichit/saver5/saver5.htm

ii) www.hobbyprojects.com/quick_circuits_reference/microcontroller_circuits/AT89C2051_night_light_saver.html

iii) www.electronicsweekly.com/blogs/gadget-master/2007/07/sleep-easy-with-the-night-light-saver.html iv) www.electronicsinfoline.com/CircuitBook/Microcontroller/Microcontroller_Projects/13655.html

v) www.scribd.com/doc/44970819/Night-Light-Saver-V5-0 vi) www.howcircuits.com/at89c2051-night-light-saver.html vii) www.next.gr/microcontrollers/at89c2051-4051/Night-Light-Saver-II- viii) Minor Project Report by Hitesh Vijayvargiya and Kundan Rathore (Year 2007-08)