Doc-Automatic Light Control
Doc-Automatic Light Control
1
INTRODUCTION
1.1INTRODUCTION
The project is about automatic switching on of lights.the number lights will switch on will
depend on the intensity of light.light sensor is provided is sense the light.light sensor is
connected to the Analog to digital converter which coverts the sensed analog signal to digital
signal.Analog to digital converter is connected to one of port of microcontroller .when micro
controller receives signal from the analog to digital converter it will sense intensity of light and it
will decide number of lights to be switched on and accordingly it gives signals to the relays
which inturn gives signal to lights and lights will glow accordingly.the maximum and minimum
limits of intensity of lights are mentioned in program dumped in the Micro controller chip.all the
lights will switch on when intensity sensed is less than the minimum limit and all lights will
switch off when the intensity is greater than the maximum limit.
To design a automatic light on and off control system by using microcontroller AT89C51
b)
To design the program (software) for the overall system according to the real world
c)
To integrate the hardware and software in order to simulate the functions of a basic
d)
To build a automatic light on and off model to simulate the actual system
Microcontroller
3. ADC
4.
Relays
1.3.1.LDR-LIGHT SENSOR
It is a device which senses the light intensity of light. It generates analog
signl up on sensing light intensity . Light dependent resistors or LDRs are often used in
circuits where it is necessary to detect the presence orthe level of light. They can be described
by a variety of names from light dependent resistor, LDR, photoresistor ,or even photo cell
(photocell) or photoconductor. Although other devices such as photodiodes or phototransistor can also be used, LDRs are a particularly convenient electronics component to
use. They provide large change in resistance for changes in light level. In view of their low
cost,ease of manufacture, and ease of use LDRs have been used in a variety of different
applications.
At
one
time
LDRs
were used
now they are stillused in a variety of applications where it is necessary to detect light levels.
1.3.2.MICROCONTROLLER
A microcontroller (abbreviated C, uC or MCU) is a single Chip computer on a
single
integrated circuit containing a processor,core, memory, and programmable peripherals
input/output This programmes memory in the form of NOR flash or OTP ROM is also often
included on chip, as well as a typically small amount of RAM. The micro controller program will
be given in the software description
1.3.3 ADC
Analog-to-digitals converters are among the most widely used devices for data acquisition.
Digital computers use binary(discrete) values, but in the physical world everything is analog
(continuous).Temperature, Pressure(wind or liquid),humidity, and velocity are a few examples
4
of physical quantities that we deal with every day. A physical is converted to electrical (voltage,
current) signals using device called a transducer. Transducers are referred to as sensors.
Sensors for temperature, pressure, light, many other natural quantities produce an output that
is voltage (or current).Therefore, we need an analog-to-digital convertor to translate the analog
signals to digital numbers so that the microcontroller can read and process them. An ADC has
n-bit resolution where n can be 8,10,12,16oreven 24 bits. The higher resolution ADC provides
a smaller step size,where step size is the smallest change that can be discerned by an ADC.this
is shown in table. .In addition to resolution ,convertion time is another major factor in judging
an ADC. Convertion time is defined as the time it takes the ADC to convert the analog input to a
digital(binary) number.The ADC CHIPS either parallel or serial.In parallel ADC ,we have only one
pin for data out..MAX1112 is an serial ADC chip.
1.3.4 RELAYS
Relays are used as interface High voltage circuits and Low voltage circuits.
The Relay circuit used in this project is takes low voltage signal from the
Microcontroller output pins and operates the switches of high voltage circuits
i.e., 230 volts circuit.
1.4Software Used
Proteus 7 professional
Keil uvision3
Uc flash+
5
CHAPTER
2
Fig:2.1The block diagram of automatic light control depending on light intensisty using a micro
controller
Micro controller consist of the following components. Those are power supply,
microcontroller, crystal oscillator, ADC 0801,LDR ,light source for testing and relays etc.
The Rectifier circuit is used to convert the AC voltage into its corresponding DC
voltage. There are Half-Wave, Full-Wave and bridge Rectifiers available for this specific
function. The most important and simple device used in Rectifier circuit is the diode. The
simple function of the diode is to conduct when forward biased and not to conduct in
reverse bias.
The Forward Bias is achieved by connecting the diodes positive with positive of
the battery and negative with batterys negative. The efficient circuit used is the full wave
Bridge rectifier circuit. The output voltage of the rectifier is in rippled form, the ripples
from the obtained DC voltage are removed using other circuits available. The circuit used
for removing the ripples is called Filter circuit.
ii) Filter
Capacitors are used as filter. The ripples from the DC voltage are removed and
pure DC voltage is obtained. And also these capacitors are used to reduce the harmonics
of the input voltage. The primary action performed by capacitor is charging and
discharging. It charges in positive half cycle of the AC voltage and it will discharge in
negative half cycle. So it allows only AC voltage and does not allow the DC voltage. This
iii) Regulator Unit
Regulator regulates the output voltage to be always constant. The output voltage is
maintained irrespective of the fluctuations in the input AC voltage. As and then the AC voltage
changes, the DC voltage also changes. Thus to avoid this Regulators are used.
8
2.2.2 LCD
Liquid crystal display (LCD) has material which combines the properties of both liquid
and crystals. They have a temperature range within which the molecules are almost as mobile as
they would be in a liquid, but are grouped together in an order form similar to a crystal
The liquid crystal display is used to visualize the status of the system.
2.2.5 Relay
A relay is an electrically operated switch. Current flowing through the coil of the
relay creates a magnetic field which attracts a lever and changes the switch contacts. The
coil current can be on or off so relays have two switch positions and they are double
throw (changeover) switches.
Relays allow one circuit to switch a second circuit which can be completely
separate from the first. For example a low voltage battery circuit can use a relay to switch
a 230V AC mains circuit. There is no electrical connection inside the relay between the
two circuits, the link is magnetic and mechanical.
(photocell) or photoconductor.Although other devices such as photodiodes or phototransistor can also be used, LDRs are a particularlyconvenient electronics component to
use. They provide large change in resistance for changes in light level.In view of their low
cost,ease of manufacture, and easeof use LDRs have been used in a variety of different
applications.
At
were used
now they are stillused in a variety of applications where it is necessary todetect light levels.
10
CHAPTER
3
MICROCONTROLLER
AND
ANALOG TO DIGITAL CONVERTER(ADC)
11
3.1 INTRODUCTION
A micro-controller can be compared to a small stand alone computer; it is a very
powerful device, which is capable of executing a series of pre-programmed tasks and interacting
with other hardware devices. Being packed in a tiny integrated circuit (IC) whose size and weight
is usually negligible, it is becoming the perfect controller for robots or any machines requiring
some kind of intelligent automation. A single microcontroller can be sufficient to control a small
mobile robot, an automatic washer machine or a security system. Any microcontroller contains
a memory to store the program to be executed, and a number of input/output lines that can be
used to interact with other devices, like reading the state of a sensor or controlling a motor.
Nowadays, microcontrollers are so cheap and easily available that it is common to use
them instead of simple logic circuits like counters for the sole purpose of gaining some design
flexibility and saving some space. Some machines and robots will even rely on a multitude of
microcontrollers, each one dedicated to a certain task. Most recent microcontrollers are 'In
System Programmable', meaning that you can modify the program being executed, without
removing
the
microcontroller
from
3.2 FEATURES
12
its
place.
13
18: P1.0 to P1.7 (Port 1): Each of these pins can be used as either input or output according to
your needs. Port 1 is an 8-bit bi-directional I/O port with internal pull-ups on all pins. Port 1 pins
that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs.
As inputs, port 1 pins that are externally pulled low will source current because of the internal
pull-ups. Each pin of Port1 has an alternate function
14
18-19: XTAL2 and XTAL1 (Crystal input and output): Input and output of internal oscillator.
Quartz crystal controlling the frequency commonly connects to these pins.
20: VSS: Ground
21- 28: P2.0 to P2.7 (Port 2): If external memory is not present, pins of Port 2 act as universal
input/output. If external memory is connected, this is the location of the higher address byte,
i.e. addresses A8 A15. It is important to note that in cases when not all the 8 bits are used for
addressing the memory (i.e. memory is smaller than 64kB), the rest of the unused bits are not
available as input/output.
29: PSEN (Program Store Enable): MCU activates this bit (brings to low state) upon each reading
of byte instruction from program memory. If external ROM is used for storing the program,
PSEN is directly connected to its control pins.
30: ALE (Address Latch Enable): Before each reading of the external memory, MCU sends the
lower byte of the address register (addresses A0 A7) to port P0 and activates the output ALE.
External Chip (eg: 74HC373), memorizes the state of port P0 upon receiving a signal from ALE
pin, and uses it as part of the address for memory chip. During the second part of the MCU
cycle, signal on ALE is off, and port P0 is used as Data Bus. In this way, by adding only one
integrated circuit, data from port can be multiplexed and the port simultaneously used for
transferring both addresses and data.
31: EA (External Access Enable): Bringing this pin to the logical state zero designates the ports
P2 and P3 for transferring addresses regardless of the presence of the internal memory. This
means that even if there is a program loaded in the MCU it will not be executed, but the one
15
from the external ROM will be used instead. Conversely, bringing the pin to the high logical state
causes the controller to use both memories, first the internal, and then the external (if present).
32-39: P0.7 to P0.0 (Port 0): Similar to Port 2, pins of Port 0 can be used as universal
input/output, if external memory is not used. If external memory is used, P0 behaves as address
output (A0 A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin
is at low logical level.
40: VCC: Power +5V
16
When designated as input, pin of Port 0 acts as high impedance offering the infinite input
resistance with no "inner" voltage.
17
When designated as output, pin acts as "open drain". Clearing a port bit grounds the
appropriate pin on the case (0V). Setting a port bit makes the pin act as high impedance.
Therefore, to get positive logic (5V) at output, external "pull up" resistor needs to be
added for connecting the pin to the positive pole.
Therefore, to get one (5V) on the output, external "pull up" resistor needs to be
added for connecting the pin to the positive pole.
Port 1 (P1): Port 1 is I/O port. Having the "pull up" resistor, Port 1 is fully compatible
with TTL circuits. The alternate functions of Port1 are
Port 2 (P2): When using external memory, this port contains the higher address
byte (addresses A8A15), similar to Port 0. Otherwise, it can be used as universal I/O
port.
Port 3 (P3): Beside its role as universal I/O port, each pin of Port 3 has an alternate
function. In order to use one of these functions, the pin in question has to be designated
as input, i.e. the appropriate bit of register P3 needs to be set. By selecting one of the
functions the other one is disabled. From a hardware standpoint, Port 3 is similar to Port
0. The alternate functions of Port 3 is given below
Data Pointer (DPTR) : The Data pointer register is made up of two 8 bit registers,
named DPH (Data Pointer High) and DPL (Data Pointer Low). These registers are used
to give addresses of the internal or external memory. The DPTR is under the control of
program. DPTR is also manipulated as one 16 bit register, DPH & DPL are each assigned
an address. The 89C51 microcontroller has additional DPTR. The dual DPTR structure is
a way by which the chip will specify the address of an external data memory location.
There are two 16-bit DPTR registers that address the external memory, and a single bit
called DPS (bit0 in AUXR1) that allows the program code to switch between them.
Stack Pointer (SP) : The stack refers to an area of internal RAM that is used in
conjunction with certain opcodes to store and retrieve data quickly. The register used to
access the stack is called Stack Pointer. The 8 bit stack pointer register is used by the
89C51 to hold an internal RAM address that is called then top of the stack. The stack
pointer increments before storing the data on the stack. As retrieved from the stack the SP
is decremented by one. The number in Stack Pointer points to the location of the last
18
"valid" address within the Stack. With the beginning of every new routine, Stack Pointer
increases by 1; upon return from routine, SP decreases by 1. Upon reset (or turning the
power on), the stack pointer contains the value07h.
Program Counter (PC): Used to access code memory. Program counter always points
to the address of the next instruction in memory to be executed. Upon reset (or turning
the power on), the program counter resets to the starting location of the program.
Instruction Register: When an instruction is fetched from the Flash memory, it is loaded
in the instruction register.
Timing & Control unit: The timing and control unit synchronizes the operation of the
microcontroller and generates control signals necessary for communication between the
microcontroller and the peripherals
Program Status Word (PSW): The Program Status Word (PSW) register is an 8 bit
register. It is also referred to as the flag register. It contains the math flags, user program
flag F0, and the register select bits that identify which of the four general purpose register
banks is currently in use by the program.
Oscillator: Oscillator circuit is used for providing a microcontroller with a clock. Clock
is needed so that microcontroller could execute a program or program instructions. Stable
pace provided by the oscillator allows harmonious and synchronous functioning of all
other parts of MCU. The manufacturers make available 89C51 designs that can run at
specified maximum and minimum frequencies, typically 1 megahertz to 33 megahertz.
Minimum frequencies imply that some internal memories are dynamic and must always
operate above a minimum frequency or data will be lost.
Interrupts: An interrupt is a signal from a device attached to a computer or from a
program within the computer that causes the main program that operates the computer to
stop and points out what to do next. In general, there are hardware interrupts and software
interrupts. A hardware interrupt is related to the hardware of the system. For example,
when an I/O operation is completed such as reading some data into the computer from a
keyboard interrupt the main program. As the name implies the software interrupts related
to the software of the system. It occurs when an application program terminates or
requests certain services from the operating system.
19
20
Lower
128
bytes
can
be
accessed
by
either
direct
or
indirect
addressing. The Upper 128 bytes can be accessed by indirect addressing only.
The Upper 128 bytes occupy the same address space as the SFR. That means
21
(0033)H
002BH
INTERRUPT
LOCATIONS
8 bytes
0023H
RESET
001BH
must be ORed with value shown for Timer 1. For example, if it is desired to run Timer 0 in mode
1 GATE (external control), and Timer 1 in mode 2 COUNTER, then value that must be loaded into
TMOD is 69H (09H from the table for Timer0, ORed with 60H from the table for Timer 1).
Moreover, it is assumed that the user, at this point, is not ready to turn the timers on
and will do that at a different point in the program by setting bit TRx (in TCON) to 1.
two
devices
is
maintained
because
they
share
the
same
clock.
The clock has another very important role which is to enable the microcontroller
to count timing. Without a precise clock, it would be impossible to build a 'Real Time
System', or any other device that relies on time measurements. It can be deduced that the
precision of the timing of a microcontroller depends on the frequency of its clock.
In the AT89C51 microcontroller, the clock can be fixed to different value by
connecting a crystal to the pins 18 and 19. Those crystals are sold with the frequency
written on them in Mega Hertz. The maximum operating frequency of the AT89C51 is 33
MHz, however other manufacturers like Philips built similar 8051 microcontrollers that
can run at frequencies up to 120 MHz.
23
Step size(mV)
5/256=19.53
5/1024=4.88
5/4096=1.2
5/65536=0.076
step
24
It has 20pins Compatible with 8080 P derivatives no interfacing logic needed access time - 135 ns
Easy interface to all microprocessors, or operates standalone
Differential analog voltage inputs
Logic inputs and outputs meet both MOS and TTL voltage level specifications
Works with 2.5V (LM336) voltage reference
On-chip clock generator
0V to 5V analog input voltage range with single 5Vsupply
No zero adjust required
0.3" standard width 20-pin DIP package
20-pin molded chip carrier or small outline package
Operates ratio metrically or with 5 V DC , 2.5 V DC , or analog span adjusted voltage
reference
Key Specifications:
Resolution 8 bits
Total error 1 4 LSB, 1 2 LSB and 1 LSB
Conversion time 100 s
Pin dagram:
25
3.8.2Pin description:
CS (PIN 1 )
Chip select is an low active low input used to activate the ADC0804 chip.To access the
AC0804,this pin must be low.
RD (read) (PIN 2 )
This is an input signal and is active low.The ADC convertors the analog input to its binary
equivalent and holds it in an internal register.RD is to used to get the converted data out of the
ADC0804 chip. When CS=0,if a high-to-low pulseis applied to the RD pin,the 8-bit digital
output shows up at the D0-D7 data pins.The RD pin is refered is also refered to as output
enable(OE).
WR(write) (PIN 3 )
this is an active low input pin used to inform the ADC0804 to start the conversion process. If
CS=0 when WR makes a low-to-high transition,the ADC0804 starts converting the analog input
value of Vin to an 8-bit digital nuber.The amount of time it takes to convert varies depending on
CLK IN and CLK R values explained below.When the data conversion is complete, the INTR
pin is forced low by the ADC0804.
CLK IN and CLK R(PIN 4 and 19)
CLK IN is an input pin connected to an external clock source when an external clock is used for
timing.However,the 804 has an internal clock generator.To use the internal clock generator (also
called self-clocking) of the ADC0804,the CLK IN and CLK R pins are connected to a capacitor
and a resistor,as shown in figure.in that case the clock frequency is determined by the equation:
F=1/1.1RC
Typical values are R=10k ohms and C=150pf. Substituting in the above equation,we get
f=606kHz.in that case ,the conversion time is 110 us.
INTR(interrupt) (PIN 5):
This is an output pin and is active low.It is a normally high pin and when the conversion is
finished, it goes low to signal the CPU that the converted data is to be picked up.After INTR
goes low, we make CS=0 and send a high-to-low pulse to the RD pin to get data out the data out
of the AC0804 chip.
Vin(+) and Vin(-)(PIN 6 and 7 ):
26
These are the differential analog inputs wherw Vin=Vin(+)-Vin(-).often Vin(-) is connected to
the ground and Vin(+) pin is used as a analog input to be converted to digital.
Vcc(PIN 20 )
This is +5 volts power supply .it is also used as reference voktage when Vref/2 input(pin9) is
open .
Vref/2(PIN 9 )
Pin 9 is an input voltage used for the reference voltage .if this ipin is open ,the analog input
voltage for ADC is in the range of 0-5 volts(same as Vcc pin).However there are many
applications where the analog input is applied toVin needs to be other than 0-5 volts.Vref/2 is
used to implement analog input voltages other than 0-5 volts.For,example if the analog input
range needs 0-4 volts,then Vref/2 is connected to 2 volts.
D0-D7(PIN 17 to 11 ):
D0-D7(D7 is the MSB)are the digital data output pins since ADC is parallel type ADC
chip.these are tristate buffered and converted data is accesed only when CS=0 and RD is forced
low.To caluculate the output vaoltage use the fallowing formula.
Dout=Vin/step size
Where Dout=digital data output (in decimal),Vin =analog input voltage and step size (resolution)
is the smallest change ,which is(2*V ref/2)/256 f0r ADC0804.
The ADC0801 is a CMOS 8-bit successive approximation A/D converter that
differential potentiometric ladder similar to the 256R products.
uses a
3.After the INTR has become low ,we make CS =0 and send a high to low pulse to the RD pin
to get the data out of ADC0801 IC chip.
Clock source for adc 0801 the speed at which an analog input ia converted to the didgital output
Depends on the speed of clock input .according to the ADC 0801 datasheets ,the typical
operating frequency is approximately 640KHz at 5 volts .figures 13.2 and 13.3 provides two
ways of providing clock for adc 0801 .In figure 13-4,notice that the clock in for the ADC 0804
is coming from the crystal of the micro controller .Since this frequency is too high ,we use D-flip
flops (74ls74) to divide the frequency . A single flip flop converts the frequency by 2 if we
connect its Q to the D input . For high frequency crystal ,you can use 4 flip-flops
28
CHAPTER
4
IMPLEMENTATION OF HARDWARE
29
30
4.1.1 Transformer
Fig.4.2 Transformer
When alternating voltage is applied to the primary winding, an alternating current will
flow that will magnetize the magnetic core, first in one direction and then in the other
direction.
This alternating flux flowing around the entire length of the magnetic circuit induces
a voltage in both the primary and secondary windings. Since both windings are linked by the
same flux, the voltage induced per turn of the primary and secondary windings must be
the same value and same direction. This voltage opposes the voltage applied to the primary
winding and is called counter
counter-electromotive force (CEMF).
The low voltage AC output is suitable for lamps, heaters and special AC motors. It is not
suitable for electronic circuits unless they include a rectifier and a ssmoothing
moothing capacitor and
regulator to get pure type of regulated smooth DC signal without any ripples .So after the process
of smoothening this DC signal can be used in various electronic circuits.
31
4.1.3 Filter
Capacitors are used as filter. The ripples from the DC voltage are removed and pure DC
voltage is obtained. And also these capacitors are used to reduce the harmonics of the input
voltage. The primary action performed by capacitor is charging and discharging. It charges in
positive half cycle of the AC voltage and itwill discharge in negative half cycle. So it allows only
AC voltage and does not allow the DC voltage. This filter is fixed before the regulator. Thus the
output is free from ripples.
32
output of the LED, either in photons per second or in mill watts, is linearly proportional to the
current through it. This means that it is useful to think of the LED as a current-operated device.
(Of course, we could think about it as either; but there is a nice relation between the light output,
which is what we ultimately care about, and the current; this is not true for the voltage.)
4.3
Crystal Oscillator
A crystal oscillator is an electronic circuit that uses the mechanical resonance of a
vibrating crystal of piezoelectric material to create an electrical signal with a very precise
frequency. This frequency is commonly used to keep track of time (as in quartz wristwatches), to
provide a stable clock signal for digital integrated circuits, and to stabilize frequencies for radio
transmitters and receivers. The most common type of piezoelectric resonator used is the quartz
crystal, so oscillator circuits designed around them were called "crystal oscillators".
Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of
megahertz. More than two billion (2109) crystals are manufactured annually. Most are small
devices for consumer devices such as wristwatches, clocks, radios, computers, and cell phones.
Quartz crystals are also found inside test and measurement equipment, such as counters, signal
generators, and oscilloscopes
34
4.4
TRANSISTOR
A transistor is simply sandwich of one type of semiconductor material between two
4.5
DIODE
A PN junction is known as diode . the property of a diode is to conduct current in one
direction only and is used as a rectifier. A diode is usually represented by a symbol as shown
below.
4.6
RESISTOR
The property of a material which opposes the flow of the electrons is resistance or the
element is called resistor. The unit of resistance is Ohms. The symbol of resistor is.
4.7 RELAYS
A relay is an electrically operated switch. Current flowing through the coil of the
relay creates a magnetic field which attracts a lever and changes the switch contacts. The
coil current can be on or off so relays have two switch positions and they are double
throw (changeover) switches.
Relays allow one circuit to switch a second circuit which can be completely
separate from the first. For example a low voltage battery circuit can use a relay to switch
a 230V AC mains circuit. There is no electrical connection inside the relay between the
two circuits, the link is magnetic and mechanical.
NC = Normally Closed, COM is connected to this when the relay coil is off.
NO = Normally Open, COM is connected to this when the relay coil is on.
Connect to COM and NO if you want the switched circuit to be on when the
36
The coil of a relay passes a relatively large current, typically 30mA for a 12V relay,
but it can be as much as 100mA for relays designed to operate from lower voltages. Most
ICs (chips) cannot provide this current and a transistor is usually used to amplify the
small IC current to the larger value required for the relay coil.
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
spike of voltage and might cause damage to circuit components Re
Relay
lay coils produce brief high
voltage 'spikes' when they are switched off and this can destroy transistors and ICs in the circuit.
To prevent damage you must connect a protection diode across the relay coil. Transistors and ICs
(chips) must be protected from the brief high voltage 'spike' produced when the relay coil is
switched off. The diagram shows how a signal diode (eg 1N4148) is connected across the relay
coil to provide this protection. Note that the diode is connected 'backwards' so that it will
normally not conduct. Conduction only occurs when the relay coil is switched off, at this moment
current tries to continue flowing through the coil and it is harmlessly diverted through the diode.
Without the diode no current could flow and the coil would produce a da
damaging
maging high voltage
'spike' in its attempt to keep the current flowing.
Relays are a better choice for switching large currents (> 5A).
Disadvantages:
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 chips can provide, so a low power transistor may be
needed to switch the current for the relay's coil. Software must now be as precise as ever while
maintaining a straightforward and intuitive approach to design. The software is designed in such a
way that changes in the hardware platform used imply a minimum reprogramming effort
At
one
time
LDRs
were used
now they are stillused in a variety of applications where it is necessary todetect light levels.
38
39
works
without
delving
consists of the movement of electrons within a material. Good conductors have a large number
of free electrons that can drift in a given direction under the action of a potential difference.
Insulators with a high resistance have very few free electrons, and therefore it is hard to make
the them move and hence a current to flow.An LDR or photoresistor is made any
semiconductor material with a high resistance. It has a high resistance because there are very
few electrons that are free and able to move - the vast majority of the electrons are
locked into the crystal lattice and unable to move.Therefore in this state there is a high
LDR resistance.
As light falls on the semiconductor, the light photons are absorbed by the semiconductor lattice
and some of their energy is transferred to the electrons. This gives some of Them sufficient
energy to break free from the crystal lattice so that they can then conduct electricity.
This results in a lowering of the resistance of the semiconductor and hence the overall LDR
resistance.The process is progressive, and as more light shines on the LDR semiconductor, so
more electrons are released to conduct electricity and the resistance falls further.
LDRs are very useful components that can be used for a variety of light sensing
applications. As the LDR resistance varies over such a wide range, they are particularly
useful, and there are many LDR circuitsavailable beyond any shown here. In order to
utilize these components, it is necessary to know something of how an LDR works, which has
been explained above.
40
CHAPTER
5
SOFTWARE DESIGN
41
Proteus VSM
Keil Vision3
uc-flash
True Mixed Mode simulation based on Berkeley SPICE3F5 with extensions for digital
simulation and true mixed mode operation.
CPU Models available for popular microcontrollers such as the PIC and 8051 series.
Interactive peripheral models include LED and LCD displays, a universal matrix keypad,
an RS232 terminal and a whole library of switches, pots, lamps, LEDs etc.
42
Graph Based Analysis types include transient, frequency, noise, distortion, AC and DC
sweeps and fourier transform. An Audio graph allows playback of simulated waveforms.
To start the ISIS program, click on the Start button and select Programs, Proteus 7
Professional and then the ISIS 7 Professional option. The ISIS schematic editor will then
load and run. Along the top of the screen is the menu bar.
Pick the components you want to use from the device libraries by selecting the
component icon and then using the P button on the Device Selector. You can use any
component with a simulation model and these parts are indicated at the top right of the
schematic preview before the device is select.
Left Click to enter placement mode, move the mouse to the point you want to deposit the
component and click left again to commit.
43
Edit them - double click on the object or right click and select Edit Properties from the
resulting context menu - in order to assign appropriate values and properties.
Delete components by right clicking on the component and selecting Delete from the
resulting context menu.
44
Move components by clicking left to select and then dragging with the left button.
Having selected the parts we need the next thing is to actually place them on the drawing
area the Editing Window and wire them together.
The Animation Control Panel:
Interactive simulations are controlled from a simple VCR like panel that behaves just like
a normal remote control. This control is situated at the bottom right of the screen.
Press the PLAY button to run the simulation.
45
Integrated make facility for assembling, compiling, and linking your embedded applications,
True integrated source-level Debugger with high-speed CPU and peripheral simulator,
Advanced GDI interface for software debugging in the target hardware and for connection to
Keil ULINK,
Flash programming utility for downloading the application program into Flash ROM,
46
A program has been developed according to the connections given by the micro controller and
required operation of the system is converted to assembly language from embedded C language
using Keil Vision3.
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. Vision3 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 cage.c.
Build Project:
You may translate all source files and link the application with a click on the Build
Target toolbar icon. When you build an application with syntax errors, Vision3 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 Vision3 editor
window.
48
49
5.4 UCFLASH+
The ucFlash+ Programmer is an affordable, reliable, and fast programmer for
MCS51/AVR Microcontrollers and 24Cxx I2C EEPROMs. The programmer is designed to operate
with the Intel Pentium-based IBM-compatible desktop computers and notebook computers.
Hardware Features:
1. This programmer includes a 40-pin ZIF socket & supports 8-pin to 40-pin DIP package devices.
2. RS232 Serial Port Interface.
3. Programmer firmware update through computer.
Software Features:
1. Works on MS-WINDOWS 98 \ 2000 \ ME \ NT \ XP Operating System.
2. User-friendly interfaces with pull-down menus, pop-up dialogue box and help.
3. Device insertion test.
4. Support all operations, such as program, verify, blank check, read, secure, erase and so on.
5. Easy to use integrated HEX Editor on main software window..
6. Supports Intel (linear & segmented) HEX (INHX8M).
7. Auto Batch Program function for faster programming i.e. Mass Production mode.
8. Automatic device identification before programming.
9. Support for programming only a selected memory in the microcontroller e.g. Data memory or
Fuse Bits
50
51
3. From the main screen, use the mouse to click on the Function menu, and then click on
the Select Device sub-menu. A window named Select Device will pop out. Select the
type of device and click Select button.
4. The next process is to load the data that you wish to program into the buffer. You may
do this by loading a data file into the buffer, by reading data into the buffer from a master
chip, or by typing the data into the buffer directly.
5. Click on the Function menu from the main screen, and select the Program sub-menu or
click the Program button on the main screen. Your data will then be programmed into the
chip and verified automatically. To double check you can, you can verify it once again by
clicking Verify sub-menu in the Function menu or verify button on the main screen.
6. Similarly you can execute different functions like Blank Check, Erase and Read.
The above steps are used to dump the program into microcontroller using uc flash+.
Test linked application. Now let us start how to work with keil.
52
53
54
Fig5.5 Keil
55
56
CHAPTER
6
PROTEUS CIRCUIT AND RESULTS
57
6.1Circuit Operation :
The above diagram is the schematic of automatic light control using microcontroller ,
The above circuit consists of An ldr with light source, adc0801, micro controller AT89C51,6 relays
With corresponding power required.
58
ADC :
The micro controller does take the input from ldr since it gives analog output.This analog input
is converted into digital data by means of adc.The adc takes the analog output from ldr as input
and gives the digital data as out put which can read by micro controller.The purpose adc is to
convert analog input to digital since micro controller only reads only digital data .Thus ADC is necessary.
Micro controller:
Micro controller reads data from adc and activates the relays according that when light intensity
detected is more it activates less number of relays, and when light intensity detected is less the micro
controller activates more relays . when light intensity detected is zero the micro controller activates
all the relays.when relays activates corresponding LED glows .thus based on light intensity the leds are
switched on and off.
The light source is near the ldr light intensity is more less relays activates i.e less leds glow, The light
source is far from the ldr light intensity is less more relays activates i.e more number of leds glow
The outputs when zero light,medium ,full intensitys are given below:
59
60
61
CHAPTER
SOFTWARE PROGRAMMING
62
SOFTWARE PROGRAMMING
The software program loaded into the micro controller is given as below:#include<reg51.h>
sbit WRITE=P2^5;
sbit READ=P2^6;
sbit INTR=P2^7;
sfr ldata=0x90;
sfr mydata=0xb0;
void delay();void main()
{
char value;ldata=0xFF;
P3=0xff;
INTR=1;
WRITE=1;
READ=1;
while(1)
{
WRITE=0;
//delay();
WRITE=1;
while(INTR==1);
READ=0;
//delay();
63
value=ldata;
if(value<=15&&value>=0)
P3=0x00;
if(value<=20&&value>=15)
P3=0x01;
if(value<=28&&value>=20)
P3=0x03;
if(value<=50&&value>=38)
P3=0x07;
if(value<=90&&value>=50)
P3=0x0f;
if(value<=100&&value>=80)
P3=0x1f;
if(value<=120&&value>=100)
P3=0x3f;
if(value<=200&&value>=168)
P3=0x7f;
if(value<=250&&value>=200)
P3=0xff;
READ=1;
}
}
64
void delay()
{
int i,j;
for(i=0;i<256;i++)
for(j=0;j<256;j++);
}
65
CHAPTER
66
7.2 CONCLUSIONS
This project is used in switch on and switch off street lights automatically
Up on sensing the light intensity.
This circuit has a wide use in many sectors in the day to day world.
67
REFERENCES
[1] Muhammad Ali Mazidi,Janice Gillispie Mazidi & Rolin D.Mcinlay,The 8051
Microcontroller And Embedded Systems Using Assembly And C,2nd edition.
[2] M.H.Rashid,Power Electronics,2nd edition.
Websites
[1] www.wikipedia.com
[2] www.scribd.com
[3] www.globusz.com
68
APPENDIX-A
AT89c51 MICROCONTROLLER DATA SHEET
69
70
71