You are on page 1of 40

CONTENTS

 ACKNOWLEDGEMENT
 CERTIFICATE
 EMBEDDED SYSTEMS
 8051 MICROCONTROLLER
 INTRODUCTION TO LIGHT SENSING ROBOT
 COMPONENTS USED
 P89V51RD2 (8052 DERIVATIVE)
 IC MAX 232
 REGULATOR 7805
 LIGHT EMITTING DIODE (LED)
 RESISTORS
 CAPACITORS
 DC MOTORS
 MOTOR DRIVING IC L293D
 PROGRAM OF MOTOR WITH IC
 LIGHT DEPENDENT RESISTORS (LDR)
 IC PCF8591P(ANALOG TO DIGITAL CONVERTER)
 INTER INTEGRATED CIRCUIT(I2C) PROTOCOL
 PROGRAM OF ADC USING I2C PROTOCOL

 COMPLETE MAIN PROGRAM


 WORKNG OF LIGHT SENSOR ROBOT
 PROJECT APPLICATIONS
 FUTURE MODIFICATIONS
EMBEDDED SYSTEM

An embedded system is a computer system designed to perform one or a few dedicated


functions,often with real-time computing constraints. It is embedded as part of a complete device
often including hardware and mechanical parts. In contrast, a general-purpose computer, such as
a personal computer, is designed to be flexible and to meet a wide range of an end-user's needs.
Embedded systems control many of the common devices in use today.

Embedded systems are controlled by a main processing core that is typically either a
microcontroller or a digital signal processor (DSP)

Since the embedded system is dedicated to specific tasks, design engineers can optimize it,
reducing the size and cost of the product, or increasing the reliability and performance. Some
embedded systems are mass-produced, benefiting from economies of scale.

Physically, embedded systems range from portable devices such as digital watches and MP3
players, to large stationary installations like traffic lights, factory controllers, or the systems
controlling nuclear power plants. Complexity varies from low, with a single microcontroller
chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or
enclosure.

In general, "embedded system" is not an exactly defined term, as many systems have some
element of programmability. For example, Handheld computers share some elements with
embedded systems — such as the operating systems and microprocessors which power them —
but are not truly embedded systems, because they allow different applications to be loaded and
peripherals to be connected.

CHARACTERISTICS

1. Embedded systems are designed to do some specific task, rather than be a general-
purpose computer for multiple tasks. Some also have real-time performance constraints
that must be met, for reasons such as safety and usability; others may have low or no
performance requirements, allowing the system hardware to be simplified to reduce costs.
2. Embedded systems are not always standalone devices. Many embedded systems consist
of small, computerized parts within a larger device that serves a more general purpose.
For example, the Gibson Robot Guitar features an embedded system for tuning the
strings, but the overall purpose of the Robot Guitar is, of course, to play music. [5]
Similarly, an embedded system in an automobile provides a specific function as a
subsystem of the car itself.
3. The program instructions written for embedded systems are referred to as firmware, and
are stored in read-only memory or Flash memory chips. They run with limited computer
hardware resources: little memory, small or non-existent keyboard and/or screen.

USER INTERFACE

Embedded systems range from no user interface at all — dedicated only to one task — to
complex graphical user interfaces that resemble modern computer desktop operating systems.

A more sophisticated devices use graphical screen with touch sensing or screen-edge buttons
provide flexibility while minimizing space used: the meaning of the buttons can change with the
screen, and selection involves the natural behavior of pointing at what's desired. Handheld
systems often have a screen with a "joystick button" for a pointing device.

Some systems provide user interface remotely with the help of serial (e.g. RS-232, USB) or
network (e.g. Ethernet) connection. In spite of installed client software and cables are needed this
approach usually gives a lot of advantages: extends the capabilities of embedded system, avoids
the cost of a display, simplifies BSP, allows to build reach user interface on PC. One of the well
established model in this direction is the combination of embedded web server running on
embedded device and user interface in web browser on PC

VARIETY OF EMBEDDED SYSTEMS

Embedded systems span all aspects of modern life and there are many examples of their
use.Telecommunications systems employ numerous embedded systems from telephone switches
for the network to mobile phones at the end-user. Computer networking uses dedicated routers
and network bridges to route data.

Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile phones,
videogame consoles, digital cameras, DVD players, GPS receivers, and printers. Many
household appliances, such as microwave ovens, washing machines and dishwashers, are
including embedded systems to provide flexibility, efficiency and features. Advanced HVAC
systems use networked thermostats to more accurately and efficiently control temperature that
can change by time of day and season. Home automation uses wired- and wireless-networking
that can be used to control lights, climate, security, audio/visual, surveillance, etc., all of which
use embedded devices for sensing and controlling.

Transportation systems from flight to automobiles increasingly use embedded systems. New
airplanes contain advanced avionics such as inertial guidance systems and GPS receivers that
also have considerable safety requirements. Various electric motors — brushless DC motors,
induction motors and DC motors — are using electric/electronic motor controllers. Automobiles,
electric vehicles, and hybrid vehicles are increasingly using embedded systems to maximize
efficiency and reduce pollution. Other automotive safety systems such as anti-lock braking
system (ABS), Electronic Stability Control (ESC/ESP), traction control (TCS) and automatic
four-wheel drive.

In addition to commonly described embedded systems based on small computers, a new class of
miniature wireless devices called motes are quickly gaining popularity as the field of wireless
sensor networking rises. Wireless sensor networking, WSN, makes use of miniaturization made
possible by advanced IC design to couple full wireless subsystems to sophisticated sensor,
enabling people and companies to measure a myriad of things in the physical world and act on
this information through IT monitoring and control systems. These motes are completely self
contained, and will typically run off a battery source for many years before the batteries need to
be changed or charged.
MICROCONTROLLER 8051

The Intel 8051 is a Harvard architecture, single chip microcontroller (µC) which was developed


by Intel in 1980 for use in embedded systems. Intel's original versions were popular in the 1980s
and early 1990s, but has today largely been superseded by a vast range of faster and/or
functionally enhanced 8051-compatible devices manufactured by more than 20 independent
manufacturers including Atmel, Infineon Technologies, Maxim Integrated Products, NXP,
Nuvoton, ST Microelectronics, Silicon Laboratories, Texas Instruments and Cypress
Semiconductor. Intel's official designation for the 8051 family of µCs is MCS 51.

IMPORATANT FEATURES AND APPLICATION

 It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a


single package
 8-bit ALU, Accumulator and Registers; hence it is an 8-bit microcontroller
 8-bit data bus - It can access 8 bits of data in one operation
 16-bit address bus - It can access 216 memory locations - 64 kiB (65536 locations) each of
RAM and ROM
 On-chip RAM - 128 bytes (data memory)
 On-chip ROM - 4 kiB (program memory)
 Four byte bi-directional input/output port
 UART (serial port)
 Two 16-bit Counter/timers
 Two-level interrupt priority
 Power saving mode

A particularly useful feature of the 8051 core is the inclusion of a boolean processing engine
which allowsbit-level boolean logic operations to be carried out directly and efficiently on
internal registers and RAM. This feature helped to cement the 8051's popularity in industrial
control applications. Another valued feature is that it has four separate register sets, which can be
used to greatly reduce interrupt latency compared to the more common method of storing
interrupt context on a stack.
The 8051 UARTs make it simple to use the chip as a serial communications interface. External
pins can be configured to connect to internal shift registers in a variety of ways, and the internal
timers can also be used, allowing serial communications in a number of modes, both
synchronous and asynchronous. Some modes allow communications with no external
components. A mode compatible with an RS-485 multi-point communications environment is
achievable, but the 8051's real strength is fitting in with existing ad-hoc protocols (e.g., when
controlling serial-controlled devices).
Once a UART, and a timer if necessary, have been configured, the programmer needs only to
write a simple interrupt routine to refill the sendshift register whenever the last bit is shifted out
by the UART and/or empty the full receive shift register (copy the data somewhere else). The
main program then performs serial reads and writes simply by reading and writing 8-bit data to
stacks.
8051 based microcontrollers typically include one or two UARTs, two or three timers, 128 or
256 bytes of internal data RAM (16 bytes of which are bit-addressable), up to 128 bytes of I/O,
512 bytes to 64 kB of internal program memory, and sometimes a quantity of extended data
RAM (ERAM) located in the external data space. The original 8051 core ran at 12 clock cycles
per machine cycle, with most instructions executing in one or two machine cycles. With a
12 MHz clock frequency, the 8051 could thus execute 1 million one-cycle instructions per
second or 500,000 two-cycle instructions per second. Enhanced 8051 cores are now commonly
used which run at six, four, two, or even one clock per machine cycle, and have clock
frequencies of up to 100 MHz, and are thus capable of an even greater number of instructions per
second. All SILabs, some Dallas and a few Atmel devices have single cycle cores.
Even higher speed single cycle 8051 cores, in the range 130 MHz to 150 MHz, are now available
in internet downloadable form for use inprogrammable logic devices such as FPGAs, and at
many hundreds of MHz in ASICs, for example the netlist from www.e8051.com. Top clock
speed 8051 cores reach over 200 MHz in today's FPGA technologies - as an
example www.dcd.pl.
Common features included in modern 8051 based microcontrollers include built-in reset timers
with brown-out detection, on-chip oscillators, self-programmable Flash ROM program memory,
bootloader code in ROM, EEPROM non-volatile data storage, I²C, SPI, and USB host
interfaces, CAN or LIN bus, PWM generators, analog
comparators, A/D and D/A converters, RTCs, extra counters and timers, in-circuit debugging
facilities, more interrupt sources, and extra power saving modes.
PROGRAMMING

There are various high level language compilers for 8051. Several C compilers are available for
the 8051, most of which feature extensions that allow the programmer to specify where each
variable should be stored in its six types of memory, and provide access to 8051 specific
hardware features such as the multiple register banks and bit manipulation instructions. There are
many commercial C compilers. SDCC is a popular open source C compiler. Other high level
languages such as Forth, BASIC, Pascal/Object Pascal, PL/M and Modula 2 are available for the
8051, but they are less widely used than C and assembly.
INTRODUCTION TO LIGHT SENSING
ROBOT
Light Sensing Robot is an electronic device that can sense and follow light. It moves in the
direction where the intensity of light sensed is greater. A user can shine a flashlight at its front
and Light Sensing Robot will respond by following the light source. Its speed is dependent upon
the intensity of the light detected. Light Sensing Robot uses a microcontroller for processing the
sensor readings and responds by controlling the motors.

Light Sensing Robot has two major modes of operation: calibration, and follow. These modes are
controlled by the main state machine. This organization, combined with the need for timed
motor, sensor, and LED control naturally lead to a timed based scheduler program. Only one ISR
was necessary-Timer0 Clear on Compare Match, which interrupts every 1 ms and updates the
timers used in the program.

The basic component which controls the device movements and calculations is the 8051
microcontroller. 8051 microcontroller is a 40 pin IC including pins for +5 volt supply, reset,
crystal oscillator and four ports of eight pins each. These port pins are connected to various
components which are to be controlled by the microcontroller.

Next is used 8 pin IC named MAX232 which is very useful as a translator. It converts the logic 0
& 1 of microcontroller to logic 0 & 1 of CPU so that the programming done according to logic 0
& 1 of microcontroller can be understood by CPU.

Regulator 7805 is also required to convert the incoming voltage of 12V to 5volts. This is
required because 8051 works on +5 volt supply. Hence after converting it to 5 volt, it is send to
1st pin of microcontroller.

D.C. motors are used as the wheels of light sensor robot. These are also connected indirectly to
8051 because they will move either clockwise or anticlockwise depending on the intensity of
light which will be calculated by 8051 only. But one more IC is required to operate them, this is
IC L293D, which is also an 8 pin IC and helps connecting motors to microcontroller.

Another IC required is PCF8591 which is basically an analog to digital converter (ADC). It is


required for the operation of the light sensors. It converts the data (amount of light) sensed by the
sensors to digital form and send it to microcontroller.

These were the basic components required. Other small components are also used like
capacitors, resistors, LED, reset button and so on.
In addition to these, various software’s are also used. These are keil uvision2 required for the
programming of the device in embedded C language. Another is flash magic used for
downloading the hex file of the written program to the device with help of data cable and com
port.

The specifications, description and respective programs of some of the major components used
are described hereafter.
MAX232

Description

The MAX232 is an integrated circuit that converts signals from an RS-232 serial port to signals


suitable for use in TTL compatible digital logic circuits. The MAX232 is a dual driver/receiver
and typically converts the RX, TX, CTS and RTS signals.
It is a dual driver/receiver that includes a capacitive voltage generator to supply TIA/EIA-232-F

voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-F inputs to 5-V
TTL/CMOS levels.

These receivers have a typical threshold of 1.3 V, a typical hysteresis of 0.5 V, and can accept
±30-V inputs.

Each driver converts TTL/CMOS input levels into TIA/EIA-232-F levels. The driver, receiver,
and

voltage-generator functions are available as cells in the Texas Instruments LinASIC library.
FEATURES
 Meets or Exceeds TIA/EIA-232-F and ITU
 Operates From a Single 5-V Power Supply
 With 1.0-_F Charge-Pump Capacitors
 Operates Up To 120 kbit/s
 Two Drivers and Two Receivers
 ±30-V Input Levels
 Low Supply Current . . . 8 mA Typical
 ESD Protection Exceeds JESD 22
 2000-V Human-Body Model (A114-A)
 Upgrade With Improved ESD (15-kV HBM)
and 0.1-_F Charge-Pump Capacitors is

REGULATOR 7805

Description
The MC78XX/LM78XX/MC78XXA series of three terminal positive regulators are available in
the TO-220/D-PAK package and with several fixed output voltages, making them useful in a
wide range of
applications. Each type employs internal current limiting, thermal shut down and safe operating
area protection, making it essentially indestructible. If adequate heat sinking is provided, they
can deliver over 1A output current.
Although designed primarily as fixed voltage regulators,
these devices can be used with external components to
obtain adjustable voltages and currents.
Features

• Output Current up to 1A

• Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24V

• Thermal Overload Protection

• Short Circuit Protection

• Output Transistor Safe Operating Area Protection

LIGHT EMITTING DIODE (LED)


LEDs emit light when an electric current passes through them.

Circuit symbol:   
CONNECTING AND SOLDERING

LEDs must be connected the correct way round, the diagram may be labelled
a or + for anode and k or - for cathode (yes, it really is k, not c, for cathode!).
The cathode is the short lead and there may be a slight flat on the body of
round LEDs. If you can see inside the LED the cathode is the larger electrode
(but this is not an official identification method).

LEDs can be damaged by heat when soldering, but the risk is small unless you are very slow. No
special precautions are needed for soldering most LEDs.

TESTING AN LED
Never connect an LED directly to a battery or power supply!
It will be destroyed almost instantly because too much current will pass through and burn it out.

LEDs must have a resistor in series to limit the current to a safe value,
for quick testing purposes a 1k resistor is suitable for most LEDs if
your supply voltage is 12V or less. Remember to connect the LED the
correct way round.

COLOURS OF LEDS
LEDs are available in red, orange, amber, yellow,
green, blue and white. Blue and white LEDs are
much more expensive than the other colours.

The colour of an LED is determined by the


semiconductor material, not by the colouring of
the 'package' (the plastic body). LEDs of all
colours are available in uncoloured packages
which may be diffused (milky) or clear (often
described as 'water clear'). The coloured packages are also available as diffused (the standard
type) or transparent.
RESISTORS

A resistor is a two-terminal electronic component that produces a voltage across its terminals


that is proportional to the electric current through it in accordance with Ohm's law:

V = IR
Resistors are 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).
The primary characteristics of a resistor are the resistance, the tolerance, maximum working
voltage and the power rating. Other characteristics include temperature coefficient, noise,
and inductance. Less well-known is critical resistance, the value below which power dissipation
limits the maximum permitted current flow, and above which the limit is applied voltage. Critical
resistance depends upon the materials constituting the resistor as well as its physical dimensions;
it's determined by design.

Resistors can be integrated into hybrid and printed circuits, as well as integrated circuits. Size,


and position of leads (or terminals) are relevant to equipment designers; resistors must be
physically large enough not to overheat when dissipating their power.
CAPACITORS

A capacitor or condenser is a passive electronic component consisting of a pair


of conductors separated by a dielectric. When a voltage potential difference exists between the
conductors, an electric field is present in the dielectric. This field stores energy and produces a
mechanical force between the plates. The effect is greatest between wide, flat, parallel, narrowly
separated conductors.

An ideal capacitor is characterized by a single constant value, capacitance, which is measured


in farads. This is the ratio of the electric charge on each conductor to the potential difference
between them. In practice, the dielectric between the plates passes a small amount of leakage
current. The conductors and leads introduce an equivalent series resistance and the dielectric has
an electric field strength limit resulting in a breakdown voltage.
In a way, a capacitor is a little like a battery. Although they work in completely different ways,
capacitors and batteries both store electrical energy. We know that a battery has two terminals.
Inside the battery, chemical reactions produce electrons on one terminal and absorb electrons on
the other terminal. A capacitor is much simpler than a battery, as it can't produce new electrons --
it only stores them.

RANGE OF CAPACITORS USED


 One 10uf 16v electrolytic capacitor
 One 470uf 25v electrolytic capacitor
 Six 10uf 16v capacitors
 Two capacitors of 22pf
DC MOTOR

A DC motor is designed to run on DC electric power. A simple 2-pole DC electric motor (here
red represents a magnet or winding with a "North" polarization, while green represents a magnet
or winding with a "South" polarization).

Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator, commutator, field
magnet(s), and brushes. In most common DC motors (and all that BEAMers will see), the
external magnetic field is produced by high-strength permanent magnets1. The stator is the
stationary part of the motor -- this includes the motor casing, as well as two or more permanent
magnet pole pieces. The rotor (together with the axle and attached commutator) rotate with
respect to the stator. The rotor consists of windings (generally on a core), the windings being
electrically connected to the commutator. The above diagram shows a common motor layout --
with the rotor inside the stator (field) magnets.

By far the most common DC motor types are the brushed and brushless types, which use internal
and external commutation respectively to create an oscillating AC current from the DC source—
so they are not purely DC machines in a strict sense.

BRUSHED DC MOTORS
The classic DC motor design generates an oscillating current in a wound rotor, or armature, with
a split ring commutator, and either a wound or permanent magnet stator. A rotor consists of one
or more coils of wire wound around a core on a shaft; an electrical power source is connected to
the rotor coil through the commutator and its brushes, causing current to flow in it, producing
electromagnetism. The commutator causes the current in the coils to be switched as the rotor
turns, keeping the magnetic poles of the rotor from ever fully aligning with the magnetic poles of
the stator field, so that the rotor never stops (like a compass needle does) but rather keeps
rotating indefinitely (as long as power is applied and is sufficient for the motor to overcome the
shaft torque load and internal losses due to friction, etc.)

Many of the limitations of the classic commutator DC motor are due to the need for brushes to
press against the commutator. This creates friction. At higher speeds, brushes have increasing
difficulty in maintaining contact. Brushes may bounce off the irregularities in the commutator
surface, creating sparks. (Sparks are also created inevitably by the brushes making and breaking
circuits through the rotor coils as the brushes cross the insulating gaps between commutator
sections. Depending on the commutator design, this may include the brushes shorting together
adjacent sections—and hence coil ends—momentarily while crossing the gaps. Furthermore,
the inductance of the rotor coils causes the voltage across each to rise when its circuit is opened,
increasing the sparking of the brushes.) This sparking limits the maximum speed of the machine,
as too-rapid sparking will overheat, erode, or even melt the commutator. The current density per
unit area of the brushes, in combination with their resistivity, limits the output of the motor. The
making and breaking of electric contact also causeselectrical noise, and the sparks additionally
cause RFI. Brushes eventually wear out and require replacement, and the commutator itself is
subject to wear and maintenance (on larger motors) or replacement (on small motors). The
commutator assembly on a large machine is a costly element, requiring precision assembly of
many parts. On small motors, the commutator is usually permanently integrated into the rotor, so
replacing it usually requires replacing the whole rotor.

Large brushes are desired for a larger brush contact area to maximize motor output, but small
brushes are desired for low mass to maximize the speed at which the motor can run without the
brushes excessively bouncing and sparking (comparable to the problem of "valve float" in
internal combustion engines). (Small brushes are also desirable for lower cost.) Stiffer brush
springs can also be used to make brushes of a given mass work at a higher speed, but at the cost
of greater friction losses (lower efficiency) and accelerated brush and commutator wear.
Therefore, DC motor brush design entails a trade-off between output power, speed, and
efficiency/wear.

BRUSHLESS DC MOTORS
Some of the problems of the brushed DC motor are eliminated in the brushless design. In this
motor, the mechanical "rotating switch" or commutator/brushgear assembly is replaced by an
external electronic switch synchronised to the rotor's position. Brushless motors are typically 85-
90% efficient or more (higher efficiency for a brushless electric motor of up to 96.5% were
reported by researchers at the Tokai University in Japan in 2009[16]), whereas DC motors with
brushgear are typically 75-80% efficient.

Midway between ordinary DC motors and stepper motors lies the realm of the brushless DC


motor. Built in a fashion very similar to stepper motors, these often use a permanent magnet
external rotor, three phases of driving coils, one or more Hall effect sensors to sense the position
of the rotor, and the associated drive electronics. The coils are activated, one phase after the
other, by the drive electronics as cued by the signals from either Hall effect sensors or from the
back EMF (electromotive force) of the undriven coils. In effect, they act as three-phase
synchronous motors containing their own variable-frequency drive electronics. A specialized
class of brushless DC motor controllers utilize EMF feedback through the main phase
connections instead of Hall effect sensors to determine position and velocity. These motors are
used extensively in electric radio-controlled vehicles. When configured with the magnets on the
outside, these are referred to by modelists as outrunner motors.

Brushless DC motors are commonly used where precise speed control is necessary, as in
computer disk drives or in video cassette recorders, the spindles within CD, CD-ROM (etc.)
drives, and mechanisms within office products such as fans, laser printers and photocopiers.
L293D Motor Driver IC

The L293D is a quadruple push-pull 4 channel driver capable of delivering 600 mA (1.2
A peak surge) per channel. The L293D is ideal for controlling the
forward/reverse/brake motions of small DC motors controlled by a microcontroller such
as a PIC or BASIC Stamp.

The L293D is a high voltage, high current four channel driver designed to accept
standard TTL logic levels and drive inductive loads (such as relays solenoids, DC and
stepping motors) and switching power transistors. The L293D is suitable for use in
switching applications at frequencies up to 5 KHz.

FEATURES INCLUDE :

 600 mA Output Current Capability Per Driver


 Pulsed Current 1.2 A / Driver
 Wide Supply Voltage Range: 4.5 V to 36 V
 Separate Input-Logic Supply
 NE Package Designed for Heat Sinking
 Thermal Shutdown & Internal ESD Protection
 High-Noise-Immunity Inputs

Pin diagram :
CIRCUIT FOR CONTROLLING DC MOTOR USING IC L293D

This is a very basic circuit.It describes the pin connections of IC L293D i.e. a push pull four
channel driver with diodes. L293D is a monolithic integrated high voltage, high current
four channel driver designed to accept standard DTL or TTL logic levels and drive
inductive loads and switching power transistors.It has 600mA output current capability
per channel and 1.2A peak output current per channel (non repetitive).
Sample Programs:-

/* motor speed control using hyperterminal*/

#include <REG51F.H>

sbit en12=P1^0;

sbit ip1=P1^1;

sbit ip2=P1^2;

unsigned char ch;

void rx();

void tx();

void timer1();

void main()

{ en12=1;

timer1();

while(1)

{ rx();

tx();

if(ch=='A')

{ en12=1;

ip1=1;

ip2=0;

if(ch=='B')

{ en12=0;

ip1=0;

ip2=0;
}

void rx()

{ while(!RI);

ch=SBUF;

RI=0;

void tx()

{ while(!TI);

SBUF=ch;

TI=0;

void timer1()

{ TMOD=0x20;

TH1=0xfd;

TR1=1;

SCON=0x52;

/*varying motor speed*/

#include <REG51F.H>

unsigned char ton;

unsigned char toff;


sbit en12=P1^0;

sbit ip1=P1^1;

sbit ip2=P1^2;

void main()

{ ton=0x10;

toff=0x54;

while(1)

{ if(ton==0)

{ if (toff==0)

{ ton=0x10;

toff=0x54;

else

{ en12=0;

toff--;

else

{ en12=1;

ton--;

ip1=1;

ip2=0;

}
LIGHT DEPENDENT RESISTOR (LDR)

A photoresistor or light dependent resistor is a component that is sensitive to light. When light
falls upon it then the resistance changes. Values of the resistance of the LDR may change over
many orders of magnitude the value of the resistance falling as the level of light increases.

It is not uncommon for the values of resistance of an LDR or photoresistor to be several


megohms in darkness and then to fall to a few hundred ohms in bright light. With such a wide
variation in resistance, LDRs are easy to use and there are many LDR circuits available.

LDRs are made from semiconductor materials to enable them to have their light sensitive
properties. Many materials can be used, but one popular material for these photoresistors is
cadmium sulphide (CdS).

It is relatively easy to understand the basics of how an LDR works without delving into
complicated explanations. It is first necessary to understand that an electrical current 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.
FEATURES

 Case Style:Radial
 Dark Resistance:20Mohm
 Rating Voltage:200V dc
 Resistor Element Type:Light Dependent
 Body Diameter:5.1mm
 External Length / Height:2.3mm
 External Width:4.3mm
 Lead Diameter:0.48mm
 Lead Length:30mm
 Max Operating Temperature:30°C
 Max Resistance @ Lux A:100kohm
 Max Resistance @ Lux B:2000kohm
 Min Resistance @ Lux A:20kohm
 Min Resistance @ Lux B:500kohm
 Peak Spectral Response Wavelength:550nm
 Power Dissipation:60mW
 Resistance @ Lux A:100kohm
 Voltage Rating AC:200V
 Voltage Rating DC:200V
ANALOG TO DIGITAL CONVERTER

An analog-to-digital converter (abbreviated ADC, A/D or A to D) is a device which converts


continuous signals to discrete digital numbers. In lot of embedded systems micro controllers
needs to take analog input. Most of the sensors AND transducers such as temperature, humidity,
pressure, are analog. For interfacing these sensors to micro controllers we require to convert the
analog output of these sensors to digital so that the controller can read it. Some micro controllers
have built in Analog to Digital Converter (ADC) so there is no need of external ADC. For
controllers that don’t have internal ADC external ADC is used. Here we are using IC PCF8951P
as the ADC which is 16 pin IC.

The PCF8591 is a single-chip, single-supply low power 8-bit CMOS data acquisition device with
four analog inputs, one analog output and a serial I2C-bus interface. Three address pins A0, A1
and A2 are used for programming the hardware address, allowing the use of up to eight devices
connected to the I2C-bus without additional hardware. Address, control and data to and from the
device are transferred serially via the two-line bidirectional I2C-bus. The functions of the device
include analog input multiplexing, on-chip track and hold function, 8-bit analog-to-digital
conversion and an 8-bit digital-to-analog conversion. The maximum conversion rate is given by
the maximum speed of the I2C-bus.
PIN DIAGRAM:-
ADDRESSING

Each PCF8591 device in an I2C-bus system is activated by sending a valid address to the device.
The address consists of a fixed part and a programmable part. The programmable part must be
set according to the address pins A0, A1 and A2. The address always has to be sent as the first
byte after the start condition in the I2C-bus protocol. The last bit of the address byte is the
read/write-bit which sets the direction of the following data transfer.

The second byte sent to a PCF8591 device will be stored in its control register and is required to
control the device function. The upper nibble of the control register is used for enabling the
analog output, and for programming the analog inputs as single-ended or differential inputs. The
lower nibble selects one of the analog input channels defined by the upper nibble (see Fig.4). If
the auto-increment flag is set the channel number is incremented automatically after each A/D
conversion. If the auto-increment mode is desired in applications where the internal oscillator is
used, the analog output enable flag in the control byte (bit 6) should be set. This allows the
internal oscillator to run continuously, thereby preventing conversion errors resulting from
oscillator start-up delay. The analog output enable flag may be reset at other times to reduce
quiescent power consumption. The selection of a non-existing input channel results in the highest
available channel number being allocated. Therefore, if the auto-increment flag is set, the next
selected channel will be always channel 0. The most significant bits of both nibbles are reserved
for future functions and have to be set to 0. After a Power-on reset condition all bits of the
control register are reset to 0. The D/A converter and the oscillator are disabled for power saving.
The analog output is switched to a high-impedance state.
CONNECTIONS OF ADC WITH MICROCONTROLLER
INTER INTEGRATED CIRCUIT (I2C)
I2C bus often used to communicate across circuit-board distances. I2C bus provides good
support for communication with various slow,on-board peripheral devices that are access
intermittently. It is a simple, low bandwidth, short-distance protocol. I2C is easy to use to link
multiple devices together since it has a built-in addressing scheme.

I2C PINS
• SCL = Serial Clock – This signal will always be driven by the 8051in our example (8051
is always the master).

• SDA = Serial Data – This signal is driven by either the micro or the I2C peripheral chip.

• Both SCL and SDA are open-drain when output on the micro and on all I2C peripheral
chips.

START AND STOP CONDITION


Both data and clock lines remain HIGH when the bus is not busy. A HIGH-to-LOW transition of
the data line, while the clock is HIGH, is defined as the start condition (S). A LOW-to-HIGH
transition of the data line while the clock is HIGH, is defined as the stop condition (P).

TRANSFERRING OF BITS
One data bit is transferred during each clock pulse. The data on the SDA line must remain stable
during the HIGH period of the clock pulse as changes in the data line at this time will be
interpreted as a control signal.

A/D CONVERSION

The A/D converter makes use of the successive approximation conversion technique. The on-
chip D/A converter and a high-gain comparator are used temporarily during an A/D conversion
cycle.An A/D conversion cycle is always started after sending a valid read mode address to a
PCF8591 device. The A/D conversion cycle is triggered at the trailing edge of the acknowledge
clock pulse and is executed while transmitting the result of the previous conversion. Once a
conversion cycle is triggered an input voltage sample of the selected channel is stored on the chip
and is converted to the corresponding 8-bit binary code. The conversion result is stored in the
ADC data register and awaits transmission. If the auto-increment flag is set the next channel is
selected. The first byte transmitted in a read cycle contains the conversion result code of the
previous read cycle. After a Power-on reset condition the first byte read is a hexadecimal 80. The
maximum A/D conversion rate is given by the actual speed of the I2C-bus.
I2C-BUS PROTOCOL
After a start condition a valid hardware address has to be sent to a PCF8591 device. The
read/write bit defines the direction of the following single or multiple byte data transfer. For the
format and the timing of the start condition (S), the stop condition (P) and the acknowledge bit
(A) refer to the I2C-bus characteristics. In the write mode a data transfer is terminated by
sending either a stop condition or the start condition of the next data transfer.

CONDITIONS
ACKNOWLEDGE (ACK)-: NO ACKNOWLEDGE (NAK)-:

RET

RET
START CONDITION-: STOP CONDITION-:

YES

COMPLETE MAIN PROGRAM

#include <REG51F.H>

#include<intrins.h>

void start();

void stop();

void shout(unsigned char);

void ack();

void nak();
void m_d();

int shin();

void read_byte_adc();

sbit en1 = P1^0;

sbit dc1 = P1^1;

sbit dc2 = P1^2;

sbit dc3 = P1^3;

sbit dc4 = P1^4;

sbit en2 = P1^5;

unsigned char value,value1,value2;

sbit sda = P0^0;

sbit scl = P0^1;

bit flag = 0;

void main()

{ while(1)

{ read_byte_adc();

m_d();

void m_d()

{ if (value > value1)

{ en2=1;

en1=1;
dc1=dc3=1;

dc2=dc4=0;

else

{ if (value1 > value)

{ en2=1;

en1=1;

dc1=dc3=0;

dc2=dc4=1;

void read_byte_adc()

{ start();

shout(0x90);

if (flag)

P0=0xf3;

else

{ shout(0x04);

if (flag)

P0=0xf1;

else
{ start();

shout(0x91);

if (flag)

P0=0xf2;

else

{ shin();

ack();

value=shin();

ack();

value1=shin();

// ack();

// value2=shin();

nak();

stop();

stop();

void start()

{ sda=1;

_nop_();

scl=1;

_nop_();

_nop_();
sda=0;

_nop_();

_nop_();

scl=0;

void stop()

{ sda=0;

scl=1;

_nop_();

_nop_();

sda=1;

_nop_();

_nop_();

scl=0;

void shout(unsigned char dat)

{ unsigned char k,j=0x80;

for(k=0;k<8;k++)

{ sda = (dat & j);

j = j>>1;

scl = 1;

_nop_();

_nop_();

_nop_();

_nop_();
scl = 0;

sda = 1;

scl = 1;

_nop_();

_nop_();

flag = sda;

_nop_();

_nop_();

scl = 0;

int shin()

{ unsigned char i, q=0x00,c=0x80;

sda=1;

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

{ scl=1;

_nop_();

_nop_();

_nop_();

_nop_();

flag = sda;

if(flag)

q = (q|c);

c = c>>1;

_nop_();
_nop_();

_nop_();

_nop_();

scl=0;

return q;

void ack()

{ sda=0;

scl=1;

_nop_();

_nop_();

_nop_();

_nop_();

scl=0; }

void nak()

{ sda=1;

scl=1;

_nop_();

_nop_();

_nop_();

_nop_();

scl=0;

}
PROJECT APPLICATIONS

TINY LIGHT SENSOR WITH LOGIC OUTPUT DRAWS LESS THAN 10ΜA

A light-sensing circuit that consumes very little power can serve as an automatic Backlight
sensor in portable instruments. This function is easily implemented with a logic gate or Schmitt-
trigger inverter, but those approaches draw a considerable amount of supply current.This light
sensor provides a low-to-high output transition at a light level determined by the value of R1.

LIGHT-CONTROLLED POND PUMP


This circuit was constructed to control the pump in a garden pond, so that it automatically turns
on at dawn and off again at dusk. Not only does this mean that we don’t have to get cold and wet
when turning the pump on or off manually but it’s also one less job for our kind neighbours then
we go away on holidays!

WATCH DOG ROBOT


It could be a watch dog robot which send you an email to your cell phone when it detects a light
in your house which should be off.

LIGHT DETECTION USING A PHOTOTRANSISTOR AND VOLTAGE COMPARATOR


This page describes an example project that turns on a red LED when light is dim and a green
LED when light is bright. Or more to the point, changes color when objects.

Because the lighting required to enable either LED is controlled by individual potentiometers,
they can be set such that either, neither, or both LEDs turn on. That is, the red LED doesn't have
to turn on simply because the green LED turned off.

You might also like