Documente Academic
Documente Profesional
Documente Cultură
DHAKA, BANGLADESH
PROJECT ON
AUTOMATIC LIGHT CONTROL BY USING MICROCONTROLLER BASED LDR
BY
FARZANA YASMIN
ID: 103-33-335
&
MD. AL MUHAIMIN SARKAR
ID: 102-33-219
SUPERVISED BY
RIFAT ABDULLAH AKHI
SENIOR LECTURER
FACULTY OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING
Daffodil International University
THIS REPORT PRESENTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
FOR THE DEGREE OF BACHELOR OF SCIENCE IN ELECTRICAL AND ELECTRONIC
ENGINEERING
JUNE 2014
APPROVAL
This project titled Automatic light control by using microcontroller based LDR, submitted by
Farzana Yasmin and Md. Al Muhaimin Sarkar to the Department of Electrical and Electronics
Engineering, Daffodil International University, has been accepted as satisfactory for the partial
fulfillment of the requirements for the degree of B.Sc. in Electrical and Electronics Engineering
and approved as to its style and contents. The presentation has been held on.
BOARD OF EXAMINERS
_______________________
Professor Dr. M. Shamsul Alam
Dean and Professor
Department of EEE
Faculty of Engineering
Daffodil International University
_______________________
Dr. Md. Fayzur Rahman
Professor and Head
Department Of EEE
Faculty of Engineering
Daffodil International University
ACKNOWLEDGEMENT
At first we are greatly praise to almighty Allah for successful completion of our undergraduate
project.
We want to thanks our Project Supervisor Rifat Abdullah Akhi, Senior Lecturer, Department of
Electrical and Electronics Engineering, Faculty of Engineering, Daffodil International
University. For her encouragement and for giving us permission to involve with this electronics
project. We have done our project according to his direction. We are also grateful to our
respected teachers.
We thank all staffs of our departmental lab for their help during working period. We are
extremely grateful to our parents, family member and friends for their support, constant love and
sacrifice.
Finally, we beg pardon for our unintentional errors and omission if any.
~i~
DEDICATION
~ ii ~
ABSTRACT
This paper aims at designing and executing the advanced development in embedded systems for
energy saving of lights. Nowadays, human has become too busy, and is unable to find time even
to switch the lights wherever not necessary. The present system is like the lights will be switched
on in the evening before the sun sets and they are switched off the next day morning after there is
sufficient light on the outside. But the actual timing for these lights to be switched on are when
there is absolute darkness. With this, the power will be wasted up to some extent. This paper
gives the best solution for electrical power wastage. Also the manual operation of the lighting
system is completely eliminated.
~ iii ~
CONTENTS
CONTENT NAME
PAGE
Acknowledgement
Dedication
ii
Abstract
iii
1. CHAPTER-1
INTRODUCTION
1.1Objective
2. CHAPTER-2
HARDWARE IMPLEMENTATION
2.2.1Recovery Rate
2.5 Transistor
2.6 Resistor
10
11
13
2.7 Capacitor
14
2.8 Diode
15
16
2.10 Relay
17
2.11 Connector
18
18
19
19
22
3. CHAPTER-3
25
26
27
33
4 .CHAPTER-4
35
36
36
4.3.1 Advantages
36
4.3.2 Disadvantages
37
37
38
Future Scope
38
Conclusion
39
References
40
LIST OF FIGURE
FIGURE
FIGURE NAME
PAGE
Fig 1.1
Project Block-diagram
Fig 2.1
LDR
Fig 2.1.1
Symbol of LDR
Fig 2.2
Practical LDR
Fig 2.3
12V DC adapter
Fig: 2.4
Fig: 2.5
Fig: 2.6
Fig: 2.7
Resistor
Fig: 2.7.1
Symbol of Resistor
Fig: 2.7.1a
11
Fig: 2.7.1b
13
Fig: 2.8
Electrolytic Capacitor
14
Fig: 2.8.1
Ceramic Capacitor
14
Fig: 2.9
Diode
16
Fig: 2.10
17
Fig: 2.11
18
Fig: 2.11.1
18
Fig: 2.12.1
19
Fig: 2.12.2
19
Fig: 2.12.3
Temporary connector
19
Fig: 2.13
ATMEGA8 Microcontroller
20
Fig: 2.13.1
22
Fig:
3.1
25
Fig: 3.2
26
Fig: 3.3
Operation in LDR.
27
Fig: 3.3.1
28
Fig: 3.4
Output of relay
33
Fig: 3.4.1
34
Fig: 3.4.2
34
Fig:
38
LIST OF TABLE
TABLE
TABLE NAME
PAGE
Table 1
23
Table 2
23
Table 3
24
CHAPTER-1
INTRODUCTION
1.1 OBJECTIVE
We need to save or conserve energy because most of the energy sources we depend on,
like coal and natural gas cant be replaced. Once we use them up theyre gone forever.
Saving power is very important, instead of using the power in unnecessary times it should be
switched off. In this project, we are avoiding the problem by having an automatic system
which turns ON and OFF the lights at given time or when the ambient light falls below a
specific intensity. Each controller has an LDR which is used to detect the ambient light. If
the ambient light is below a specific value the lights are turned ON.
A light dependent sensor is interfaced to the AVR microcontroller it is used to track the
sunlight and when the sensors goes dark the led will be made ON and when the sensors
found light the led will be made OFF.
It clearly demonstrates the working of transistor in saturation region and cut-off region.
The working of relay is also known microcontroller and the code is written in C language in
AVR programmer. Automatic light control is a simple yet powerful concept, which uses
transistor as a switch. By using this system manual works are 100% removed. The aim of
this project is to control the light using LDR. When the light falling occur means resistance
value will be change. There is no light then the resistance value is change. From this
resistance change the voltage variation can be obtained this value is given to ADC of AVR.
AVR is stand for peripheral interface controller.
LDR
TRANSISTOR
RELAY
MICROCONTROLLER
LAMP
CHAPTER-2
HARDWARE IMPLEMENTATION
Power supply
Voltage regulator
ATmega8 Microcontroller
Transistor
Capacitor
Resistor
Diode
Relay
Connector
light. The best-known devices of this type are the light dependent resistor (LDR), the photo
diode and the phototransistors.
Light dependent resistors as the name suggests depend on light for the variation of resistance.
When light falls on the strip, the resistance decreases. In the absence of light the
resistance can be in the order of 10K ohm to 15K ohm and is called the dark resistance.
Depending on the exposure of light the resistance can fall down to value of 500
ohms. The power ratings are usually smaller and are in the range 50mW to 0.5W. Though
very sensitive to light, the switching time is very high and hence cannot be used for high
frequency applications. They are used in chopper amplifiers. Light dependent resistors
are available as disc 0.5cm to 2.5cm. The resistance rises to several Mega ohms under
dark conditions.
The below figure shows that when the torch is turned on, the resistance of the LDR
falls, allowing current to pass through it is shown in figure.
The basic construction and symbol for LDR are shown in above figures
respectively. The device consists of a pair of metal film contacts separated by a snakelike
track of cadmium sulphide film, designed to provide the maximum possible contact area
with the two metal films. The structure is housed in a clear plastic or resin case, to
Daffodil International University
provide free access to external light. Practical LDRs are available in variety of sizes and
packages styles, the most popular size having a face diameter of roughly 10mm. practical
LDR is shown in below figure.
When an LDR is brought from a certain illuminating level into total darkness, the
resistance does not increase immediately to the dark value. The recovery rate is specified does
not increase immediately to the dark value. The recovery rate is specified in k ohm/second and
for current LDR types it is more than 200K ohm/second. The recovery rate is much greater in the
reverse direction, e.g. going from darkness illumination level of 300 lux, it takes less than 10ms
to reach a resistance which corresponds with a light level of 400 lux. A LDR may be connected
either way round and no special precautions are required when soldering.
light
intensity. Two cadmium sulphide (cds) photoconductive cells with spectral response similar to
that of the human eye. The cell resistance falls with increasing light intensity. Some of its
features:
High reliability.
Light weight.
2.5 TRANSISTOR
Solid state switches are one of the main applications for the use of transistors, and
transistor switches can be used for controlling high power devices such as motors, solenoids or
lamps, but they can also used in digital electronics and logic gate circuits. The NPN (PN2222A)
transistor image shown in below figure.
The areas of operation for a transistor switch are known as the Saturation Region and
the Cut-off Region. This means then that we can ignore the operating Q-point biasing and
voltage divider circuitry required for amplification, and use the transistor as a switch by driving
it back and forth between its fully-OFF (cut-off) and fully-ON (saturation) regions as shown
below.
single-pole single-throw (SPST) solid state switch. With a zero signal applied to the Base of
the transistor it turns OFF acting like an open switch and zero collector current flows. With a
positive signal applied to the Base of the transistor it turns ON acting like a closed switch and
maximum circuit current flows through the device.
2.6 RESISTOR
A resistor is a passive two-terminal electrical component that implements electrical
resistance as a circuit element. Resistors act to reduce current flow, and, at the same time, act to
lower voltage levels within circuits. The current through a resistor is in direct proportion to
the voltage across the resistor's terminals. This relationship is represented by Ohm's law:
where I is the current through the conductor in units of amperes, V is the potential difference
measured across the conductor in units of volts, and R is the resistance of the conductor in units
of ohms (symbol: ).
Fig. 2.7FFFF
The ratio of the voltage applied across a resistor's terminals to the intensity of current in the
circuit is called its resistance, and this can be assumed to be a constant (independent of the
voltage) for ordinary resistors working within their ratings.
Resistors are common elements of electrical networks and electronic circuits and are ubiquitous
in electronic equipment. Practical resistors can be composed of various compounds and films, as
well as resistance wires (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.
The electrical functionality of a resistor is specified by its resistance: common commercial
resistors are manufactured over a range of more than nine orders of magnitude. When specifying
that resistance in an electronic design, the required precision of the resistance may require
attention to the manufacturing tolerance of the chosen resistor, according to its specific
application. The temperature coefficient of the resistance may also be of concern in some
precision applications. Practical resistors are also specified as having a maximum power rating
which must exceed the anticipated power dissipation of that resistor in a particular circuit: this is
mainly of concern in power electronics applications. Resistors with higher power ratings are
physically larger and may require heat sinks. In a high-voltage circuit, attention must sometimes
be paid to the rated maximum working voltage of the resistor. While there is no minimum
working voltage for a given resistor, failure to account for a resistor's maximum rating may
cause the resistor to incinerate when current is run through it.
10
resistors, the values of the drop boxes on the ends do not enter into the calculations in any
manner.
11
As can be seen in the above 4 Band Resistor Color Codes chart, the first two color bands have
values of brown = 1, red = 2, orange = 3 and so on.
The third color band is the multiplier of the first 2 bands. Here, black is 1, brown is 10, red is
100 and so on. Putting this in other words, the value of the third band (the multiplier) is the
number 10 raised to the power of the color code. For example, red in the third band is 10 or
100.This third band also has 2 new colors where gold = 0.1 and silver = 0.01.
The 4th band is the resistor's tolerance and shows how precisely the resistor was manufactured.
Gold = 5%, silver = 10% and no band whatsoever = 20%.
Now that we know the values of each color, let's try calculating a few examples of resistance
values.
Resistor 2 has the colors orange orange yellow silver which "translates" into 3 3 10,000 or
330,000 ohms and a tolerance of 10%.
Resistor 3 has the colors yellow violet silver meaning 4 7 .01 or .47 ohms and no fourth band
indicates a 20% tolerance.
12
Use
the
Band
Chart
to
solve
these
next
problems.
For resistor 4, we see the first 3 bands are violet, green and red which
"translate" into 7, 5 and 2. Looking at the fourth band (the multiplier);
we
see
it
is
brown
and
has
value
of
10.
So, the resistance value is 7 5 2 10 which equals 7,520 ohms or 7.52 K ohms. Band 5 is red
which indicates a 2 per cent tolerance and a brown sixth band means that the temperature
coefficient is 100 parts per million (ppm).
Examining resistor 5, the first 3 bands are brown, black and blue and the fourth band (the
multiplier) is green. So, these colors convert into 1 0 6 100,000 which calculates to 10,600,000
ohms or 10.6 Meg ohms. The brown 5th band and the red 6th band mean that the resistor has a
1% tolerance and a 50 ppm temperature coefficient.
Daffodil International University
13
If you've read these instructions, you probably have a good understanding of determining a
resistor's value from its colors. Then again, there's always the calculator which makes things
much easier to solve.
2.7 CAPACITOR
A capacitor (originally known as a condenser) is a passive two-terminal electrical
component used to store energy electrically in an electric field. The forms of practical capacitors
vary widely, but all contain at least two electrical conductors (plates) separated by
a dielectric (i.e., insulator). The conductors can be thin films of metal, aluminum foil or disks,
etc. The 'non-conducting' dielectric acts to increase the capacitor's charge capacity. A dielectric
can be glass, ceramic, plastic film, air, paper, mica, etc. Capacitors are widely used as parts
of electrical circuits in many common electrical devices. Unlike a resistor, a capacitor does not
dissipate energy. Instead, a capacitor stores energy in the form of an electrostatic field between
its plates.
When there is a potential difference across the conductors (e.g., when a capacitor is attached
across a battery), an electric field develops across the dielectric, causing positive charge (+Q) to
collect on one plate and negative charge (-Q) to collect on the other plate. If a battery has been
attached to a capacitor for a sufficient amount of time, no current can flow through the capacitor.
14
However, if an accelerating or alternating voltage is applied across the leads of the capacitor,
a displacement current can flow.
An ideal capacitor is characterized by a single constant value for its capacitance. Capacitance is
expressed as the ratio of the electric charge (Q) on each conductor to the potential difference (V)
between them. The capacitance is greater when there is a narrower separation between
conductors and when the conductors have a larger surface area. In practice, the dielectric
between the plates passes a small amount of leakage current and also has an electric field
strength limit, known as the breakdown voltage. The conductors and leads introduce an under
sired inductance and resistance.
Capacitors which have a value of one Farad or more tend to have a solid dielectric and as One
Farad is such a large unit to use, prefixes are used instead in electronic formulas with capacitor
values given in micro-Farads (F), nano-Farads (nF) and the pico-Farads (pF). For example:
Sub-units of the Farad
microfarad, (F) =
F = 110-6 F
nanofarad, (nF) =
F = 110-9 F
picofarad, (pF) =
F = 110-12 F
2.8 DIODE
A diode is a simple electrical device that allows the flow of current only in one direction. So
it can be said to act somewhat like a switch. A specific arrangement of diodes can convert AC to
pulsating DC, hence it is sometimes also called as a rectifier. It is derived from "di-ode " which
means a device having two electrodes. The symbol of a p-n junction diode is shown below, the
arrowhead points in the direction of conventional current flow. The p-n junction is a basic
building block in any semiconductor device. It is formed by joining a p type (instrinsic
semiconductor doped with a trivalent impurity) and n type semiconductor (intrinsic
semiconductor doped with a pentavalent impurity) together with a special fabrication technique
Daffodil International University
15
such that a p-n junction is formed. Hence it is a device with two elements, the p-type forms
anode and the n-type forms the cathode. These terminals are brought out to make the external
connections.
16
these are the low energy consumption, longer lifetime, strong build, smaller size etc. The LED
images given below.
2.10 RELAY
A relay is usually an electromechanical device that is actuated by an electrical current.
The current flowing in one circuit causes the opening or closing of another circuit. Relays are
like remote control switches and are
used in many applications because of
their relative simplicity, long life, and
proven high reliability.
Relays are used in a wide variety of
applications throughout industry, such
as in telephone exchanges, digital
computers and automation systems. Highly sophisticated relays are utilized to protect electric
power systems against trouble and power blackouts as well as to regulate and control the
generation and distribution of power. In the home, relays are used in refrigerators, washing
machines and dishwashers, and heating and air-conditioning controls. Although relays are
generally associated with electrical circuitry, there are many other types, such as pneumatic and
hydraulic. Input may be electrical and output directly mechanical, or vice versa.
17
These active semiconductor devices use light instead of magnetism to actuate a switch. The light
comes from an LED, or light emitting diode.
All relays contain a sensing unit, the electric coil, which is powered by AC or DC current. When
the applied current or voltage exceeds a threshold value, the coil activates the armature, which
operates either to close the open contacts or to open the closed contacts. When a power is
supplied to the coil, it generates a magnetic force that actuates the switch mechanism. The
magnetic force is, in effect, relaying the action from one circuit to another.
2.11 CONNECTOR
Connectors are used to join subsections of circuits together. Usually, a connector is used
where it may be desirable to disconnect the subsections at some future time: power inputs,
peripheral connections, or boards which may need to be replaced. There are different types of
connectors, In this project we used few of them.
18
as right-angle pins). Such connectors come in a variety of pitches, and may have any number
of individual rows of pins.
The most commonly seen pin headers are .1" single or double row connectors. These come in
male and female versions, and are the connectors used to connect PCB boards and shields
together.
19
memory. Microcontrollers are designed for small or dedicated applications. Microcontrollers are
used in automatically controlled products and devices, such as automobile engine control
systems, remote controls, office machines, appliances, power tools, and toys.
The ATmega8A is a low-power CMOS 8-bit microcontroller based on the AVR RISC
architecture.
By executing powerful instructions in a single clock cycle, the ATmega8A achieves throughputs
approaching 1 MIPS per MHz, allowing the system designer to optimize power consumption
versus processing speed.
It is a High-performance, Low-power AVR 8-bit Microcontroller having Advanced RISC
Architecture
20
21
22
PORTC (PC5:PC0): PORTC is a port I / O two-way (bidirectional) 7-bit with internal pullup resistor can be selected. This port output buffers have symmetrical characteristics when used
as a source or sink. When used as an input, the pull-pin low externally will emit a current if the
pull-up resistor is activated it. PORTC pins will be in the condition of the tri-state when RESET
is active, although the clock is not running.
23
PC6/RESET: If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that
the electrical characteristics of PC6 differ from those of the other pins of Port C. If the
RSTDISBL Fuse is not programmed, PC6 is used as a Reset input. A low level on this pin for
longer than the minimum pulse length will generate a Reset, even if the clock is not running.
Port D (PD7:PD0): Port D is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port D output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port D pins that are externally pulled low will
source current if the pull-up resistors are activated.
24
CHAPTER-3
DESCRIPTION OF CIRCUIT DIAGRAM
This is the total circuit diagram sketching. We will define/ discuss this in three part:
Daffodil International University
25
Here D1 diode is used for give reverse polarity protection to circuit. R3 resistor 10K connected
in series with a LED D2 which indicate the power supply. Diode D3 is used for short circuit
26
protection to microcontroller. The regulated 5V DC supply connected with LDR and ATmega8
microcontroller.
27
Chip type
: ATmega8L
Program type
: Application
: Small
:0
: 256
*****************************************************/
28
#include <mega8.h>
#include <delay.h>
// Standard Input/Output functions
#include <stdio.h>
//////////////////////////////////
//Programmer Setting
#define relay PORTB.1
#define ON 1
#define OFF 0
/////////////////////////////////
////////////////////////////////
//User Setting
#define Dark 800
#define Light 600
/////////////////////////////////
#define ADC_VREF_TYPE 0x00
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
Daffodil International University
29
30
PORTB=0x00;
DDRB=0x02;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// ADC initialization
// ADC Clock frequency: 62.500 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x87;
printf("LDR Based AC Light Control Project\r\n");
Daffodil International University
31
32
This program install in microcontroller. If the light resistivity around 600 then it gives signal to
relay OFF and resistivity 800 then it gives signal to relay ON.
3.4 Part-3(Output of relay):
In this part 12V DC power supply connected with a relay. A transistor is connected with a
output of microcontroller. Transistor is connected in series with a resistor R36 (4.7K). D9 is
connected parallel with relay coil. Temporary Connector J30 is connected with relay contacts.
produced as the magnetic flux collapses within the coil. This induced reverse voltage value may
be very high in comparison to the switching voltage, and may damage any semiconductor device
Daffodil International University
33
such as a transistor, FET or micro-controller used to operate the relay coil. One way of
preventing damage to the transistor or any switching semiconductor device, is to connect a
reverse biased diode across the relay coil.
When the current flowing through the coil is switched OFF, an induced back emf is generated
as the magnetic flux collapses in the coil.
This reverse voltage forward biases the diode which conducts and dissipates the stored energy
preventing any damage to the semiconductor transistor.
When used in this type of application the diode is generally known as a Flywheel Diode, Freewheeling Diode and even Fly-back Diode, but they all mean the same thing.
A LED D24 and resistor R43 (470) connected in series with 12V dc power supply and D24
shows status of relay ON and OFF condition.
CHAPTER-4
PRODUCT COST AND RESULTS
Daffodil International University
34
QUALITY
QUANTITY
Capacitors
C1, C4
100nF
C2
100F
C3, C5
10F
Resistors
R1, R3
10K
R2
100
R36
4.7K
R43
470
1N4007
Diodes
D1,D3,D4
LED(D2, D24)
LDR
LED-GREEN
TORCH-LDR
J1, J4
CONN-SIL2
J2
TBLOCK M-2
J3
CONN-SIL5
J30
TBLOCK I3
Transistor
PN2222
IC 7805
Microcontroller (U1)
ATmega8
Relay
OMIH-SH-124D
Connectors
35
Capacitors
10Tk
Resistors
10Tk
LDR
20Tk
Diodes
10Tk
LED
8Tk
Transistor
ATmega8 microcontroller
10Tk
150Tk
Voltage regulator
20Tk
Connectors
35Tk
Relay
20Tk
Plug
20Tk
12V DC adaptor
100Tk
240Tk
PCB design
200Tk
TOTAL COST
853TK.
LDRs are sensitive, inexpensive and readily available devices. They have good power
and voltage handling capabilities, similar to those of a conventional resistor.
They are small enough to fit into virtually any electronic device and used all around the
world as a basis component in many electrical systems.
36
4.3.2 Disadvantages:
It can be used in some clocks, alarms, and other electronic devices that are dependent
on sunlight.
We can used it outside of house, corridors or industry area, which helps to save
power.
37
FUTURE SCOPE
The above project we can develop solar street light system with Automatic street light
controller. The system can be powered from a battery, which can be charged during day time by
harvesting the solar energy through a solar cell. The solar energy harvested from sunlight can be
stored, inverted from DC voltages to AC voltage using sun tie converter.
Daffodil International University
38
The AC voltage can be stepped down rectified and using the circuit. The above mentioned
strategy will enable us to harvest solar energy in an effective way for the operation of the circuit
and for powering the street light also.
CONCLUSION
This paper elaborates the design and construction of automatic light control system circuit.
Circuit works properly to turn lamp ON/OFF. LDR sensor is the main conditions in working the
circuit. If the conditions have been satisfied the circuit will do the desired work according to
specific program. Each sensor controls the turning ON or OFF the lighting column. The lights
has been successfully controlled by microcontroller. With commands from the controller the
lights will be ON in the places of the movement when it's dark. Finally this control circuit can be
used in various purposes.
39
REFERENCES
Internet sources:
http://www.electronics-tutorials.ws/io/io_5.html
http://www.kanda.com/blog/microcontrollers/avr-microcontrollers/avr-microcontroller/
http://www.circuitstoday.com/category/voltage-regulators
40
41