You are on page 1of 45

A

Major Project Report


On
Microcontroller Based Elevator System
Submitted in partial fulfillment of the requirement for the award of the
Degree of Bachelor of Technology
in
Electronics and Communication Engineering

Submitted By:- Guided By:-


Prateek Nepalia Er.Yogendra Aboti
Rahul Vyas Er. Giriraj Vyas
Pranay Thanvi
BE(Final Year) ECE

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING


MARWAR ENGINEERING COLLEGE AND RESEARCH CENTRE
JODHPUR(RAJASTHAN)
RAJASTHAN TECHNICAL UNIVERSITY,KOTA(RAJASTHAN)
2010-2011
ACKNOWLEDGEMENT
A Research owes its success from commencement to completion to people
involved with researcher at various stages. We acknowledge with due courtesy our
regards to all the persons and sources consulted during the development of this
project and preparation of this project. We are grateful from the core of our heart to
our guide Er. Giriraj Vyas for his valuable time, help and motivation which kept us
going to the fulfillment of this project.

Also, it gives us immense pleasure to express our profound gratitude and


thankfulness to Er.Yogendra Aboti to help us to facilitate us with his experience,
guidance and instructions to accomplish this project successfully.

Finally, we also acknowledge the entire development of Electronics and


Communication for their constructive criticism, support and cooperation, which
has helped us to give our level best

Group Members
Prateek Nepalia
Rahul Vyas
Pranay Thanvi
CERTIFICATE
This is to certify that the work which is being presented in the Major Report
entitled “Microcontroller Based Elevator System” submitted by Prateek Nepalia,
Rahul Vyas and Pranay Thanvi of B.Tech 8th semester (Final Year) of Electronics
and Communication Engineering in partial fulfillment for the award of degree of
Bachelor of Engineering is being a record of student’s work carried out by them
under my supervision and guidance.

Project Incharge Project Guide


Er. Yogendra Aboti Er.Giriraj Vyas
Senior Lecturer Lecturer
Deptt. of ECE Deptt. of ECE
MECRC,Jodhpur MECRC,Jodhpur

Date:-

Place:- Jodhpur
PREFACE
As per the curriculum of RAJASTHAN TECHNICAL UNIVERSITY IV Year
Bachelor’s Degree in Technology,we completed our major project entitled
“Microcontroller Based Elevator System”.
This is our Project which contains a detailed description of the Microcontroller
used in Elevators. While Completing this project we gained lot about the
………….. which is completely new and challenging field for a student of
electronics.
The major sources of material for preparing this report to e-books and other
internet tutorials. This Project report is initiated by providing a general
introduction to the project and the components and fundamentals implemented to
develop the same. After that a detailed view of the remote control circuit and the
hardware developed follows.
INDEX
S.No. Chapter Page No.
1 Introduction
1.1 Electric Motor
1.2 Principle
1.3 Comparison Of DC Motor
2 Motor Speed Control
2.1 Speed Control
2.2 Basic Principle
2.3 PWM Speed Control
2.4 Speed Encoders
2.5 Inverted Pulse Width Modulation
3 Basic Circuit Component
3.1 Capacitor
3.1.1 Energy Storage
3.1.2 Current-voltage relation
3.1.3 DC circuits
3.1.4 AC circuits
3.1.5 Capacitor types
3.1.6 Dielectric Materials
3.1.7 Electrolytic capacitors
3.2 Resistor
3.2.1 Resistor marking
3.2.2 Four-Band resistors
3.3 Voltage Regulator IC 7805
3.4 Terminal Box
3.5 Power Switch
3.6 Reset Switch
3.7 Liquid Crystal Display
3.7.1 LCD Connector
3.8 Motor Driver IC L293D
3.9 Microcontroller(AT Mega32)
3.9.1 PIN Description
4 Designing of PCB
5 Circuit Description
6 Circuit Operation
7 Errors and Precaution
8 Conclusion and future expansion
9 Appendix- coding
10 References and Bibliography

CHAPTER-1
INTRODUCTION
1.1 Electric Motor
An electric motor uses electrical energy to produce mechanical energy, very typically through
the interaction of magnetic fields and current-carrying conductors. The reverse process,
producing electrical energy from mechanical energy, is accomplished by a generator or dynamo.
Many types of electric motors can be run as generators, and vice versa. For example a
starter/generator for a gas turbine or Traction motors used on vehicles often perform both tasks.

Electric motors are found in applications as diverse as industrial fans, blowers and pumps,
machine tools, household appliances, power tools, and disk drives. They may be powered by
direct current (e.g., a battery powered portable device or motor vehicle), or by alternating current
from a central electrical distribution grid. The smallest motors may be found in electric
wristwatches. Medium-size motors of highly standardized dimensions and characteristics provide
convenient mechanical power for industrial uses. The very largest electric motors are used for
propulsion of large ships, and for such purposes as pipeline compressors, with ratings in the
millions of watts. Electric motors may be classified by the source of electric power, by their
internal construction, by their application, or by the type of motion they give.

The brushed Dc motor generates torque directly from Dc power supplied to the motor by using
internal commutation, stationary permanent magnets and rotating electrical magnets. It works on
the principle of Lorentz force , which states that any current carrying conductor placed within an
external magnetic field experiences a torque or force known as Lorentz force. Advantages of a
brushed DC motor include low initial cost ,high reliability and simple control of motor speed.

1.2 The Principle


The conversion of electrical energy into mechanical energy by electromagnetic means was
demonstrated by the British scientist Michael Faraday in 1821. A free-hanging wire was dipped
into a pool of mercury, on which a permanent magnet was placed. When a current was passed
through the wire, the wire rotated around the magnet, showing that the current gave rise to a
circular magnetic field around the wire.
1.3 Comparison of DC Motor

Type Advantages Disadvantages Typical Typical Drive


Application
AC Induction Least expensive Rotation slips Fans Uni/Poly-phase
(Shaded Pole) Long life from frequency AC
high power Low starting
torque
AC Induction High power Rotation slips Appliances Uni/Poly-phase
(split-phase high starting from frequency AC
capacitor) torque
Universal motor High starting Maintenance Drill, blender, Uni-phase AC or
torque, compact, (brushes) vacuum cleaner, Direct DC
high speed Medium lifespan insulation
blowers
AC Synchronous Rotation in-sync More expensive Industrial motors Uni/Poly-phase
with freq Clocks AC
long-life Audio turntables
(alternator) tape drives
Stepper DC Precision High initial cost Positioning in DC
positioning Requires a printers and
High holding controller floppy drives
torque
Brushless DC Long lifespan High initial cost Hard drives DC
low maintenance Requires a CD/DVD players
High efficiency controller electric vehicles
Brushed DC Low initial cost Maintenance Treadmill DC
Simple speed (brushes) exercisers
control Medium lifespan automotive
motors (seats,
blowers,
windows)
Pancake DC Compact design Medium cost Office Equip Direct DC or
Simple speed Medium lifespan Fans/Pumps PWM
control
The purpose of this project is to control the speed of the motor with PWM control using optical
Encoder and Decoder.

CHAPTER-2
MOTOR SPEED CONTROL

2.1 Speed Control


The purpose of a motor speed controller is to take a signal representing the demanded speed, and
to drive a motor at that speed. The controller may or may not actually measure the speed of the
motor. If it does, it is called a Feedback Speed Controller or Closed Loop Speed Controller, if
not it is called an Open Loop Speed Controller. Feedback speed control is better, but more
complicated, and may not be required for a simple robot design. Motors come in a variety of
forms, and the speed controller's motor drive output will be different dependent on these forms.
The speed controller presented here is designed to drive a simple cheap starter motor from a car,
which can be purchased from any scrap yard. These motors are generally series wound, which
means to reverse them, they must be altered slightly.

2.2 Basic Principle


The speed of a DC motor is directly proportional to the supply voltage, so if we reduce the
supply voltage from 12 Volts to 6 Volts, the motor will run at half the speed. How can this be
achieved when the battery is fixed at 12 Volts?

The speed controller works by varying the average voltage sent to the motor. It could do this by
simply adjusting the voltage sent to the motor, but this is quite inefficient to do. A better way is
to switch the motor's supply on and off very quickly. If the switching is fast enough, the motor
doesn't notice it, it only notices the average effect.

When you watch a film in the cinema, or the television, what you are actually seeing is a series
of fixed pictures, which change rapidly enough that your eyes just see the average effect -
movement. Your brain fills in the gaps to give an average effect.

As the amount of time that the voltage is on increases compared with the amount of time that it is
off, the average speed of the motor increases. The time that it takes a motor to speed up and slow
down under switching conditions is dependant on the inertia of the rotor (basically how heavy it
is), and how much friction and load torque there is. The graph below shows the speed of a motor
that is being turned on and off fairly slowly.
You can see that the average speed is around 150, although it varies quite a bit. If the supply
voltage is switched fast enough, it won’t have time to change speed much, and the speed will be
quite steady. This is the principle of switch mode speed control. Thus the speed is set by PWM –
Pulse Width Modulation.

2.3 PWM Speed Control

By controlling analog circuits digitally, system costs and power consumption can be drastically
reduced. What’s more , many microcontrollers and DSP’s already include on-chip PWM
controllers , making implementation easy.

In a nutshell, PWM is a way of digitally encoding analog signal levels. Through the use of high
resolution counters , the duty cycle of a square wave is modulated to encode a specific analog
signal level. The PWM signal is either fully on or fully off. The voltage or current source is
supplied to the analog load by means of a repeating series of on and off pulses. The on-off time
during within DC supply is applied to the load, and the off-time is period during which that
supply is switched off. Given a sufficient bandwidth , any analog value can be encoded with
PWM.

One of the advantages of PWM is that the signal remains digital all the way from the processor
to the controlled system; no digital-to –analog conversion is necessary. By keeping the signal
digital, noise effects are minimized. Noise can only affect a digital signal if it is strong enough to
change a logic-1 to a logic-0 or vice versa.

To control the speed of a d.c. motor we need a variable voltage d.c. power source. However if
you take a 12V motor and switch on the power to ot, the motor will start to speed up: motors do
not respond so it will take small time to reach full speed. If we switch the power off sometime
before the motor reaches full speed, then the motor will start to slow down.If we switch the
power on and off quickly enough , the motor will run at some speed part way between zero and
full speed. This is exactly what a PWM Controller does: it switches the motor on in a series of
pulses. To control the motor speed it varies the width of the pulses – hence Pulse Width
Modulation.

To perform the same function as described above in software requires that the software has
digital representation of the speed of each wheel, and can finely control the width of the PWM
signal sent to a wheel .To get the speed of each wheel , an optical encoder must be used as in the
analogue method, but the output of t must be sent to the microcontroller. This is achieved using a
counter, clocked by the speed controller , which the microcontroller can read and can clear. At
regular intervals, the microcontroller must read the counter then clear it. The interval depends on
the maximum speed of the robot , the diameter of the wheel ,the number of slots in the speed
encoders disc and the number of bits of the counter.

2.4 Inverted Pulse Width Modulation


The fast Pulse Width Modulation or fast PWM mode (WGM21:0=3) provides a high frequency
PWM waveform generation option. The fast PWM differs from the other PWM option by its
single slope operation. The counter counts from BOTTOM to MAX then restarts from
BOTTOM. In non-inverting compare output mode, the output compare (OC2) is cleared on the
compare match between TCNT2 and OCR@ and set at BOTTOM. In inverting Compare Output
mode, the output is set on compare match and cleared at BOTTOM. Due to the single-slope
operation, the operating frequency of the fast PWM mode can be twice as high as the phase
correct PWM mode well that uses dual-slope operation. This high frequency makes the PWM
mode well suited for power regulation, and DAC applications. High frequency allow physically
small size external components (coils, Capacitors), and therefore reduces total system cost. In
fact PWM mode, the counter is incremented until the counter value matches the MAX value .The
counter is then cleared at the following timer clock cycle .The TCNT2 value is in the timing
diagram shown as a histogram for illustrating the single –slope operation .The diagram includes
non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT2 slopes
represent compare matches between OCR2 and TCNT2 The Timer/Counter Overflow Flag
(TOv2) is set each time the counter reaches MAX.If the interrupt is enabled handler routine can
be used updating the compare value.

In fast PWM mode, the compare unit allows generation of PWM waveforms on the CO pin.
Setting the COM2:0 bits to 2 will produce a non – inverted PWM and an inverted PWM output
can be generated by setting the COM21:0to 3 .The actual OC2 value will only be visible on the
port pin if the data direction for the port is set asoutput.The PWM waveform is generated by
setting (or clearing) the OC2 Register at the compare match between OCR2 and TCNT, and (or
setting) the OC2 Register at the timer clock cycle the counter (changes from MAX to BOTTO).
The extreme value for the OCR2 Register represent special cases when generating a PWM
waveform output in the fast PWM mode. If the OCR2 is set equal to BOTTOM, the output will
be a narrow spike for each MAX+1 timer clock cycle. Setting the ORC2 equal to MAX will
result in a constantly high or low output (depending on the polarity of the output set by the
COM21:0 bits.)

A Frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by
setting OC2 o toggle its logical level on each compare match (COM21:0=1). The waveform
generated will have maximum frequency of foc2 = fclk_I/O/2 when OVR2 is set to zero.This
feature is similar to the OC2 toggle in CTC mode, expect the double buffer feature of the output
compare unit is enable in the fast PWM mode.
CHAPTER-3
BASIC CIRCUIT COMPONENT
3.1 Capacitor

A capacitor (formerly known as condenser) is a passive electronic component consisting of a


pair of conductors separated by a dielectric (insulator). When a potential difference (voltage)
exists across the conductors, an electric field is present in the dielectric. This field stores energy
and produces a mechanical force between the conductors. The effect is greatest when there is a
narrow separation between large areas of conductor, hence capacitor conductors are often called
plates.

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.

Capacitors are widely used in electronic circuits to block direct current while allowing
alternating current to pass, to filter out interference, to smooth the output of power supplies, and
for many other purposes. They are used in resonant circuits in radio frequency equipment to
select particular frequencies from a signal with many frequencies.

A capacitor consists of two conductors separated by a non-conductive region.[8] The non-


conductive substance is called the dielectric medium, although this may also mean a vacuum or a
semiconductor depletion region chemically identical to the conductors. A capacitor is assumed to
be self-contained and isolated, with no net electric charge and no influence from an external
electric field. The conductors thus contain equal and opposite charges on their facing surfaces,[9]
and the dielectric contains an electric field. The capacitor is a reasonably general model for
electric fields within electric circuits.

An ideal capacitor is wholly characterized by a constant capacitance C, defined as the ratio of


charge ±Q on each conductor to the voltage V between them

Sometimes charge buildup affects the mechanics of the capacitor, causing the capacitance to
vary. In this case, capacitance is defined in terms of incremental changes:
In SI units, a capacitance of one farad means that one coulomb of charge on each conductor
causes a voltage of one volt across the device.[10]

3.1.1 Energy storage

Work must be done by an external influence to move charge between the conductors in a
capacitor. When the external influence is removed, the charge separation persists and energy is
stored in the electric field. If charge is later allowed to return to its equilibrium position, the
energy is released. The work done in establishing the electric field, and hence the amount of
energy stored, is given by:[11]

3.1.2 Current-voltage relation

The current i(t) through a component in an electric circuit is defined as the rate of flow of the
charge q(t) that has passed through it. Physical charges cannot pass through the dielectric layer of
a capacitor, but rather build up in equal and opposite quantities on the electrodes: as each
electron accumulates on the negative plate, one leaves the positive plate. Thus the accumulated
charge on the electrodes is equal to the integral of the current, as well as being proportional to
the voltage (as discussed above). As with any antiderivative, a constant of integration is added to
represent the initial voltage v (t0). This is the integral form of the capacitor equation,[12]

Taking the derivative of this, and multiplying by C, yields the derivative form,[13]

The dual of the capacitor is the inductor, which stores energy in the magnetic field rather than the
electric field. Its current-voltage relation is obtained by exchanging current and voltage in the
capacitor equations and replacing C with the inductance L.
3.1.3 DC circuits

A simple resistor-capacitor circuit demonstrates charging of a capacitor.

A series circuit containing only a resistor, a capacitor, a switch and a constant DC source of
voltage V0 is known as a charging circuit.[14] If the capacitor is initially uncharged while the
switch is open, and the switch is closed at t = 0, it follows from Kirchhoff's voltage law that

Taking the derivative and multiplying by C, gives a first-order differential equation,

At t = 0, the voltage across the capacitor is zero and the voltage across the resistor is V0. The
initial current is then i (0) =V0 /R. With this assumption, the differential equation yields

where τ0 = RC is the time constant of the system.


As the capacitor reaches equilibrium with the source voltage, the voltage across the resistor and
the current through the entire circuit decay exponentially. The case of discharging a charged
capacitor likewise demonstrates exponential decay, but with the initial capacitor voltage
replacing V0 and the final voltage being zero.

3.1.4 AC circuits

Impedance, the vector sum of reactance and resistance, describes the phase difference and the
ratio of amplitudes between sinusoidally varying voltage and sinusoidally varying current at a
given frequency. Fourier analysis allows any signal to be constructed from a spectrum of
frequencies, whence the circuit's reaction to the various frequencies may be found. The reactance
and impedance of a capacitor are respectively

where j is the imaginary unit and ω is the angular velocity of the sinusoidal signal. The - j phase
indicates that the AC voltage V = Z I lags the AC current by 90°: the positive current phase
corresponds to increasing voltage as the capacitor charges; zero current corresponds to
instantaneous constant voltage, etc.

Note that impedance decreases with increasing capacitance and increasing frequency. This
implies that a higher-frequency signal or a larger capacitor results in a lower voltage amplitude
per current amplitude—an AC "short circuit" or AC coupling. Conversely, for very low
frequencies, the reactance will be high, so that a capacitor is nearly an open circuit in AC
analysis—those frequencies have been "filtered out".

3.1.5 Capacitor types

Practical capacitors are available commercially in many different forms. The type of internal
dielectric, the structure of the plates and the device packaging all strongly affect the
characteristics of the capacitor, and its applications.

3.1.6 Dielectric materials

Most types of capacitor include a dielectric spacer, which increases their capacitance. These
dielectrics are most often insulators. However, low capacitance devices are available with a
vacuum between their plates, which allows extremely high voltage operation and low losses.
Variable capacitors with their plates open to the atmosphere were commonly used in radio tuning
circuits. Later designs use polymer foil dielectric between the moving and stationary plates, with
no significant air space between them.

In order to maximize the charge that a capacitor can hold, the dialectric material needs to have as
high a permittivity as possible, while also having as high a breakdown voltage as possible.

Several solid dielectrics are available, including paper, plastic, glass, mica and ceramic materials.
Paper was used extensively in older devices and offers relatively high voltage performance.
However, it is susceptible to water absorption, and has been largely replaced by plastic film
capacitors. Plastics offer better stability and aging performance, which makes them useful in
timer circuits, although they may be limited to low operating temperatures and frequencies.
Ceramic capacitors are generally small, cheap and useful for high frequency applications,
although their capacitance varies strongly with voltage and they age poorly. They are broadly
categorized as class 1 dielectrics, which have predictable variation of capacitance with
temperature or class 2 dielectrics, which can operate at higher voltage. Glass and mica capacitors
are extremely reliable, stable and tolerant to high temperatures and voltages, but are too
expensive for most mainstream applications. Electrolytic capacitors and super capacitors are
used to store small and larger amounts of energy, respectively, ceramic capacitors are often used
in resonators, and parasitic capacitance occurs in circuits wherever the simple conductor-
insulator-conductor structure is formed unintentionally by the configuration of the circuit layout.

Fig. 3.1.6 Capacitors

Capacitor materials. From left: multilayer ceramic, ceramic disc, multilayer polyester film,
tubular ceramic, polystyrene, metalized polyester film, aluminum electrolytic. Major scale
divisions are in centimeters.
3.1.7 Electrolytic capacitors

Electrolytic capacitors are use an a aluminum or tantalum plate with an oxide dielectric layer.
The second electrode is a liquid electrolyte, connected to the circuit by another foil plate.
Electrolytic capacitors offer very high capacitance but suffer from poor tolerances, high
instability, gradual loss of capacitance especially when subjected to heat, and high leakage
current. Poor quality capacitors may leak electrolyte, which is harmful to printed circuit boards.
The conductivity of the electrolyte drops at low temperatures, which increases equivalent series
resistance. While widely used for power-supply conditioning, poor high-frequency
characteristics make them unsuitable for many applications. Electrolytic capacitors will self-
degrade if unused for a period (around a year), and when full power is applied may short circuit,
permanently damaging the capacitor and usually blowing a fuse or causing arcing in rectifier
tubes. They can be restored before use (and damage) by gradually applying the operating
voltage, often done on antique [[vacuum tube] equipment over a period of 30 minutes by using a
variable transformer to supply AC power. Unfortunately, the use of this technique may be less
satisfactory for some solid state equipment, which may be damaged by operation below its
normal power range, requiring that the power supply first be isolated from the consuming
circuits. Such remedies may not be applicable to modern high-frequency power supplies as these
produce full output voltage even with reduced input.

Tantalum capacitors offer better frequency and temperature characteristics than aluminum, but
higher dielectric absorption and leakage.[21] OS-CON (or OC-CON) capacitors are a polymerized
organic semiconductor solid-electrolyte type that offer longer life at higher cost than standard
electrolytic capacitors.

3.2 Resistor

A resistor is a two-terminal electronic component that produces a voltage across its terminals
that is proportional to the electric current passing 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 is determined by the design, materials and dimensions of the resistor.
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.

Fig.3.2 Resistors

3.2.1 Resistor marking

Most axial resistors use a pattern of colored stripes to indicate resistance. Surface-mount resistors
are marked numerically, if they are big enough to permit marking; more-recent small sizes are
impractical to mark. Cases are usually tan, brown, blue, or green, though other colors are
occasionally found such as dark red or dark gray.

Early 20th century resistors, essentially uninsulated, were dipped in paint to cover their entire
body for color coding. A second color of paint was applied to one end of the element, and a color
dot (or band) in the middle provided the third digit. The rule was "body, tip, dot", providing two
significant digits for value and the decimal multiplier, in that sequence. Default tolerance was
±20%. Closer-tolerance resistors had silver (±10%) or gold-colored (±5%) paint on the other end.

3.2.2 Four-band resistors

Four-band identification is the most commonly used color-coding scheme on resistors. It consists
of four colored bands that are painted around the body of the resistor. The first two bands encode
the first two significant digits of the resistance value, the third is a power-of-ten multiplier or
number-of-zeroes, and the fourth is the tolerance accuracy, or acceptable error, of the value. The
first three bands are equally spaced along the resistor; the spacing to the fourth band is wider.
Sometimes a fifth band identifies the thermal coefficient, but this must be distinguished from the
true 5-color system, with 3 significant digits.

For example, green-blue-yellow-red is 56×104 Ω = 560 kΩ ± 2%. An easier description can be as


followed: the first band, green, has a value of 5 and the second band, blue, has a value of 6, and
is counted as 56. The third band, yellow, has a value of 104, which adds four 0's to the end,
creating 560,000 Ω at ±2% tolerance accuracy. 560,000 Ω changes to 560 kΩ ±2% (as a kilo- is
103).

3.3 Voltage Regulator IC 7805

The voltage regulators employ built-in the current limiting, thermal shutdown and safe operating
area protection which makes them virtually immune to damage from output overload.7805 is a
three terminal positive voltage regulator.With adequate heat sinking , it can deliver an excess of
0.5 A output current. Typical application would include local(on-card)regulators which can
eliminated the noise and degraded performance associated with single point regulation.

7805 Regulator come from the 78xx family of self-contained fixed linear voltage regulator
integrated circuit.The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply, due to their ease of use and relative cheapness.When
specifying individual ICs within this family , the xx is replaced with two digit number , which
indicate the output voltage the particular device is designed to provide (for example, the 7805
voltage regulator has a 5 volt output, while the 7812 produce the 12 volts).The 78xx line are
positive voltage regulator, meaning that they are designed to produce a voltage that is positive
relative to a common ground.There is a related line of 79xx device which are complementary
negative voltage regulators.78xx and 79xx ICs can be used in combination to provide supply
voltage in the same circuit if necessary.

Fig. 3.3 Voltage Regulator IC 7805


7805 ICs have three terminal and are most commonly found in the TO220 from factors although
smaller surface mount and larger TO3 package are also available from some manufactures.These
device typically support an input voltage which can be anywhere couple of volts over the
intended output voltage, up to a maximum of 35 or 40 volts,and can typically provide upto
around 1 or 1.5 amps of currents(through smaller or larger package may have a lower or higher
current rating).

3.4 Terminal Box

An enclosure which includes, mounts, and protects one or more terminals or terminal boards; it
may include a cover and such accessories as mounting hardware, brackets, locks, and conduit
fittings. Terminal Box(2 Pin) is used here to connect the 12V supply (battery/battery eliminator)
to provide to the circuit.

3.5 Power Switch

Power switch used here is a push to ON PCB mount switch to switch ON and OFF
the power supply for microcontroller.

3.6 Reset Switch

Reset Switch is used to reset the microcontroller switch. It is a PCB mount switch.

3.7 Liquid Crystal Display

A liquid crystal display (LCD) is a thin, flat electronic visual display that uses the light
modulating properties of liquid crystals (LCs). LCs do not emit light directly.

They are used in a wide range of applications including: computer monitors, television,
instrument panels, aircraft cockpit displays, signage, etc. They are common in consumer devices
such as video players, gaming devices, clocks, watches, calculators, and telephones. LCDs have
displaced cathode ray tube(CRT) displays in most applications. They are usually more compact,
lightweight, portable, and less expensive. They are available in a wider range of screen sizes than
CRT and other flat panel displays.

LCDs are more energy efficient and offer safer disposal than CRTs. Its low electrical power
consumption enables it to be used in battery-powered electronic equipment. It is an
electronically-modulated optical device made up of any number of pixels filled with liquid
crystals and arrayed in front of a light source (backlight) or reflector to produce images in colour
or monochrome. The earliest discovery leading to the development of LCD technology, the
discovery of liquid crystals, dates from 1888. By 2008, worldwide sales of televisions with LCD
screens had surpassed the sale of CRT units.

Fig 3.3 LCD

LCDs with a small number of segments, such as those used in digital watches and pocket
calculators, have individual electrical contacts for each segment. An external dedicated circuit
supplies an electric charge to control each segment. This display structure is unwieldy for more
than a few display elements.

Small monochrome displays such as those found in personal organizers, or older laptop screens
have a passive-matrix structure employing super-twisted nematic (STN) or double-layer STN
(DSTN) technology—the latter of which addresses a colour-shifting problem with the former—
and colour-STN (CSTN)—wherein colour is added by using an internal filter. Each row or
column of the display has a single electrical circuit. The pixels are addressed one at a time by
row and column addresses. This type of display is called passive-matrix addressed because the
pixel must retain its state between refreshes without the benefit of a steady electrical charge. As
the number of pixels (and, correspondingly, columns and rows) increases, this type of display
becomes less feasible. Very slow response times and poor contrast are typical of passive-matrix
addressed LCDs.

High-resolution color displays such as modern LCD computer monitors and televisions use an
active matrix structure. A matrix of thin-film transistors (TFTs) is added to the polarizing and
color filters. Each pixel has its own dedicated transistor, allowing each column line to access one
pixel. When a row line is activated, all of the column lines are connected to a row of pixels and
the correct voltage is driven onto all of the column lines. The row line is then deactivated and the
next row line is activated. All of the row lines are activated in sequence during a refresh
operation. Active-matrix addressed displays look "brighter" and "sharper" than passive-matrix
addressed displays of the same size, and generally have quicker response times, producing much
better images.

3.7.1 LCD Connector

The 16 pin male header at left top is standard HD44780LCD module compatible connector.Just
fix any standard HD44780LCD module to control it through AVR.The connections to the
microcontroller and LCD are as below

a) RS-PB.0.
b) RW-PB.1
c) EN-PB.3
d) D0-PB.4
e) D1-PB.5
f) D2-PB.6
g) D3-PB.7
h) Brightness control potentiometer is also provided to adjust brightness of LCD.
i) Module
j) Remove the LCD to use there pins as normal I/O pins.

3.8. Motor Driver IC L293D

Motor Drivers

a) Motor Driver is using L293D integrated IC.


b) Two L293D motor driver can control upto 4 DC motors ot 2 Stepper motors.
c) Motor Output connectors are at the right side of the board.
d) Two DC motors can also be controlled by PWM of AVR or at full speed by PWM1 and
PWM2 selection jumpers.
e) Put jumpers PWM1 and PWM2 in rightside two pins to avoid speed control and achieve
maximum speed.
f) Put jumper PWM1 and PWM2 in left side ywo pins for speed control through
OC1A(PD5) and OC1B(PD4).
g) If PWM is not used PD4 and PD 5 can be used as normal I/O pins.
h) Motor1 can be controlled by PC0 and PC1 if speed control is activated by.
i) PWM1 jumper then speed can be controlled by OC1A pin.
j) Motor2 can be controlled by PC2 and PC3 if speed control is activated by.
k) PWM2 jumper then speed can be controlled by OC1B pin.
l) Motor3 can be controlled by PC4 and PC5.
m) Motor4 can be control by PC6 and PC7.

Fig.3.8 Motor Driver IC L293D

3.9 Microcontroller (AT mega 32)


The AVR core combines a rich instruction set with 32 general purpose working registers. All the
32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two
independent registers to be accessed in one single instruction executed in one clock cycle. The
resulting architecture is more code efficient while achieving throughputs up to ten times faster
than conventional CISC microcontrollers. The ATmega32 provides the following features: 32K
bytes of In-System Programmable Flash Program memory with Read-While-Write capabilities,
1024 bytes EEPROM, 2K byte SRAM, 32 general purpose I/O lines, 32 general purpose working
registers, a JTAG interface for Boundary scan, On-chip Debugging support and programming,
three flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial
programmable USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC
with optional differential input stage with programmable gain (TQFP package only), a
programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software
selectable power saving modes. The Idle mode stops the CPU while allowing the USART, Two-
wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to
continue functioning. The Power-down mode saves the register contents but freezes the
Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset.
In Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a
timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the
CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise
during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the
rest of the device is sleeping. This allows very fast start-up combined with low-power
consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer
continue to run. The device is manufactured using Atmel’s high density nonvolatile memory
technology. The On chip ISP Flash allows the program memory to be reprogrammed in-system
through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-
chip Boot program running on the AVR core. The boot program can use any interface to
download the application program in the Application Flash memory. Software in the Boot Flash
section will continue to run while the Application Flash section is updated, providing true Read-
While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable
Flash on a monolithic chip, the Atmel ATmega32 is a powerful microcontroller that provides a
highly-flexible and cost-effective solution to many embedded control applications. The
ATmega32 AVR is supported with a full suite of program and system development tools
including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators,
and evaluation kits.

Fig.3.9.1 Microcontroller ATmega32


Fig.3.9.2 Pin Diagram
3.9.1 PIN description

VCC Digital supply voltage.

GND Ground.

Port A (PA7..PA0) Port A serves as the analog inputs to the A/D Converter. Port A also serves
as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal
pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive
characteristics with both high sink and source capability. When pins PA0 to PA7 are used as
inputs and are externally pulled low, they will source current if the internal pull-up resistors are
activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock
is not running.

Port B (PB7..PB0) PortB is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port B output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port B pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running.

Port B Pins Alternate Functions

Port Pin Alternate Functions


PB7 SCK (SPI Bus Serial Clock)
PB6 MISO (SPI Bus Master Input/Slave Output)
PB5 MOSI (SPI Bus Master Output/Slave Input)
PB4 SS (SPI Slave Select Input)
PB3 AIN1 (Analog Comparator Negative Input)
OC0 (Timer/Counter0 Output Compare Match Output)
PB2 AIN0 (Analog Comparator Positive Input)
INT2 (External Interrupt 2 Input)
PB1 T1 (Timer/Counter1 External Counter Input)
PB0
T0 (Timer/Counter0 External Counter Input)
XCK (USART External Clock Input/output)

The alternate pin configuration is as follows:


• SCK – Port B, Bit 7
SCK: Master Clock output, Slave Clock input pin for SPI. When the SPI is enabled as a Slave,
this pin is configured as an input regardless of the setting of DDB7. When the SPI is enabled as a
Master, the data direction of this pin is controlled by DDB7. When the pin is forced by the SPI to
be an input, the pull-up can still be controlled by the PORTB7 bit.

• MISO – Port B, Bit 6


MISO: Master Data input, Slave Data output pin for SPI. When the SPI is enabled as a Master,
this pin is configured as an input regardless of the setting of DDB6. When the SPI is enabled as a
Slave, the data direction of this pin is controlled by DDB6. When the pin is forced by the SPI to
be an input, the pull-up can still be controlled by the PORTB6 bit.

• MOSI – Port B, Bit 5


MOSI: SPI Master Data output, Slave Data input for SPI. When the SPI is enabled as a Slave,
this pin is configured as an input regardless of the setting of DDB5. When the SPI is enabled as a
Master, the data direction of this pin is controlled by DDB5. When the pin is forced by the SPI to
be an input, the pull-up can still be controlled by the PORTB5 bit.

• SS – Port B, Bit 4
SS: Slave Select input. When the SPI is enabled as a Slave, this pin is configured as an input
regardless of the setting of DDB4. As a Slave, the SPI is activated when this pin is driven low.
When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB4. When
the pin is forced by the SPI to be an input, the pull-up can still be controlled by the PORTB4 bit.

Port C (PC7..PC0) Port C is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port C output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port C pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset
condition becomes active, even if the clock is not running. If the JTAG interface is enabled, the
pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset
occurs. The TD0 pin is tri-stated unless TAP states that shift out data are entered.

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. The Port D pins are tri-stated when a reset
condition becomes active, even if the clock is not running.

Alternate Functions of Port D


Port D Pins Alternate Functions
Port Pin Alternate Function
PD7 OC2 (Timer/Counter2 Output Compare Match Output)
PD6 ICP1 (Timer/Counter1 Input Capture Pin)
PD5 OC1A (Timer/Counter1 Output Compare A Match Output)
PD4 OC1B (Timer/Counter1 Output Compare B Match Output)
PD3 INT1 (External Interrupt 1 Input)
PD2 INT0 (External Interrupt 0 Input)
PD1 TXD (USART Output Pin)
PD0 RXD (USART Input Pin)

• OC2 – Port D, Bit 7


OC2, Timer/Counter2 Output Compare Match output: The PD7 pin can serve as an external
output for the Timer/Counter2 Output Compare. The pin has to be configured as an output
(DDD7 set (one)) to serve this function. The OC2 pin is also the output pin for the PWM mode
timer function.

• OC1A – Port D, Bit 5


OC1A, Output Compare Match A output: The PD5 pin can serve as an external output for the
Timer/Counter1 Output Compare A. The pin has to be configured as an output (DDD5 set (one))
to serve this function. The OC1A pin is also the output pin for the PWM mode timer function.

• OC1B – Port D, Bit 4


OC1B, Output Compare Match B output: The PD4 pin can serve as an external output for the
Timer/Counter1 Output Compare B. The pin has to be configured as an output (DDD4 set (one))
to serve this function. The OC1B pin is also the output pin for the PWM mode timer function.

RESET 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. Shorter pulses are not guaranteed to generate a
reset.

XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating
circuit.

XTAL2 Output from the inverting Oscillator amplifier.

AVCC A VCC is the supply voltage pin for Port A and the A/D Converter. It should be
externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be
connected to VCC through a low-pass filter.

AREF AREF is the analog reference pin for the A/D Converter.

Configuring the Pin Each port pin consists of three register bits: DDxn, PORTxn, and PINxn.
the DDxn bits are accessed at the DDRx I/O address, the PORTxn bits at the PORTx I/O
address, and the PINxn bits at the PINx I/O address. The DDxn bit in the DDRx Register selects
the direction of this pin. If DDxn is written logic one, Pxn is configured as an output pin. If
DDxn is written logic zero, Pxn is configured as an input pin. If PORTxn is written logic one
when the pin is configured as an input pin, the pull-up resistor is activated. To switch the pull-up
resistor off, PORTxn has to be written logic zero or the pin has to be configured as an output pin.
The port pins are tri-stated when a reset condition becomes active, even if no clocks are running.
If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven
high (one). If PORTxn is written logic zero when the pin is configured as an output pin, the port
pin is driven low (zero). When switching between tri-state ({DDxn, PORTxn} = 0b00) and
output high ({DDxn, PORTxn} = 0b11), an intermediate state with either pull-up enabled
({DDxn, PORTxn} = 0b01) or output low ({DDxn, PORTxn} = 0b10) must occur. Normally, the
pull-up enabled state is fully acceptable, as a high-impudent environment will not notice the
difference between a strong high driver and a pull-up. If this is not the case, the PUD bit in the
SFIOR Register can be set to disable all pull-ups in all ports.

Pin Description

Pin Number Description

1 (XCK/T0) PB0
2 (T1) PB1
3 (INT2/AIN0) PB2
4 (OC0/AIN1) PB3
5 (SS) PB4
6 (MOSI) PB5
7 (MISO) PB6
8 (SCK) PB7
9 RESET
10 VCC
11 GND
12 XTAL2
13 XTAL1
14 (RXD) PD0
15 (TXD) PD1
16 (INT0) PD2
17 (INT1) PD3
18 (OC1B) PD4
19 (OC1A) PD5
20 (ICP1) PD6
21 (OC2) PD7
22 (SCL) PC0
23 (SDA) PC1
24 (TCK) PC2
25 (TMS) PC3
26 (TDO) PC4
27 PC5 (TDI)
28 PC6 (TOSC1)
29 PC7 (TOSC2)
30 AVCC
31 GND
32 AREF
33 PA7 (ADC7)
34 PA6 (ADC6)
35 PA5 (ADC5)
36 PA4 (ADC4)
37 PA3 (ADC3)
38 PA2 (ADC2)
39 PA1 (ADC1)
40 PA0 (ADC0)

CHAPTER-4
DESIGNING OF PCB
Steps of circuit Design
Stage-1:Initial Stage
In this stage a rough sketch is prepared deciding the components and their connection.
This rough sketch is further modified and a final layout is decided which is to be implemented
using Eagle Software, Commonly used for designing the circuit . In eagle software first the
schematics layout is prepared selecting the desired component. The Schematic Editor without
Layout Editor is applicable for drawing electrical wiring diagrams(connection scheme, contact
plans….).The Schematic editor comes , as well as the layout editor ,with the full library editor
for designing. The Schematic layout is switched to board with a option “Switch to Board”
provided in the File Menu. The next step is to arrange the component on the board according to
the circuit. Then we use the option of DRC for setting the wire width and other connection. The
circuit is optimized accordingly then by removing the jumpers and replacing the components by
its leg size dot plus space for soldering. Thus the figure-4.2 shows the PCB layout with all the
component, connection and jumpers.

Stage-II Printing the circuit on PCB


The final layout i.e. the BOARD CIRCUIT given by the software Eagle is then printed on
a glossy paper. The print on the glossy paper is then transferred to the printed Circuit Board by
continuously ironing the glossy paper with a thick cloth on the top for 15 to 20 minutes. The
minor image printed on the PCB is darkened with the help of permanent marker.

Stage-III:Etching the PCB


Etching is the process of attacking and removing the unprotected copper from the PCB to
yield the desired conductor pattern. Several commercial etchant and techniques are available for
processing PC Boards. These materials and method attack the unprotected copper yet to do affect
the adhesive , supporting laminate and photoresist.The most common chemicals used by industry
as an etchant are ferric and cupric chloride. Of these, ferric chloride is commonly ,used since it is
less expensive and potentially the least dangerous.

Stage-IV:Cleaning the PCB


In this stage we took a thinner in order to remove the marks of the marker and thus PCB
is cleaned and ready with the copper tracks on it.

Stage V:Drilling the PCB


We next took the Precision Hand Drill and did holes in the PCB at the required places.
Subsequently we solder the deficiencies of the copper track to complete the circuit.
Stage VI:Assembly and Soldering the Components
We assemble the various components onto the PCB and soldered the component solidly
on the PCB and check the soldering with the multimeter for the continuity of the circuit.

Stage-VII:Mounting the PCB


To give a neat look we place the PCB LCD key pad and motor on the wooden board and
fix it with the help of machine screws.And the Circuit is finally ready to work and perform iys
duty of operation.

CHAPTER – 5
5.1 CIRCUIT DESCRIPTION
The circuit is given 12v supply with the help of terminal box. To reduce the spikes and to filter
the incoming 12V de Voltage the it is passed through a filter circuit which comprises of one
Electrolytic Capacitor (1000, µF, 25V) and two ceramic capacitor (104). A switch is provided at
the input which when pressed indicate the supply by glowing a LED in series with a resistance.
The Micro Controller (AT mega 32), used in this project works at a particular voltage of 5V.To
provide this voltage to Micro controller we use a voltage regulator IC 7805.It has there terminals
which are input, output and ground .12V input DC voltage is provided at the input terminals of
the IC 7805 and this IC regulates the voltage of 5v which is required for the operation of the
Micro Controller. This 5V is provided is the Vcc terminal of the microcontroller and the Ground
is provided at GND terminal as show in the circuit diagram .A reset switch is provided to reset
the microcontroller to the initial state. A 16x2LCD display is connected at the PORT B of the
Micro Controller to display the speed and the direction of the motor with the help of the program
burn into Micro Controller .The program is fed into the Micro Controller with the help of
Robotic USB Burner and software AVR studio. A 2x5 Key Pad is provided at the Port C for
controlling the speed and direction of motor. The output of the key pad is provided to the motor
driver IC L293D which is used to drive the motor this L293D gets the input signal in from 0 and
1 from the controller and drive the motor in either direction i.e. Forward or Reverse. The speed
of the motor is controller with the principle of pulse Width Modulation Using Optical Encoder
and Decoder. The operating voltage of motor is 12 V DC which is provided directly from the
input to the motor through a switch. From this circuit we can simultaneously drive two motors if
required.

The figure below show the circuit diagram depicting various components of the project and their
inter Connections.
5.2 CIRCUIT OPERATION
The 12V input DC supply used for staring the circuit is provided through the terminal box and is
filtered through the filter circuit comprising capacitors. The input is indicated through LED in
series with the resistance .As the micro Controller works on 5V, the voltage is lowered down
with the help of 7805 voltage regulator IC.The Micro controller provides digital signals for the
operations of LCD and the motor .The LCD and the LED in the LCD are provided with their
respective VCC and GND .Program is burn in to the Micro controller with the help of AVR
Studio Software and Robotic USB Programmer .The respective programs for LCD Display,
Direction and Speed Control of Motor are fed in to the Micro controller .Firstly the LCD is
initialize and a string is displayed on the LCD panel. The next step is to register the data
direction with the help data direction register which is done in Hexa-Decimal Code. This is used
to register 1 for output port and 0 for output port. Initially the LCD screen is cleared and it
display a string “LCD IS READY” and with a delay of 2000ms it display a string “PRESS ANY
KEY” and further it again clear the LCD screen and display “???KEY” with a delay of
2000ms.The Enable pin of the motor driver IC is set to 1(Enable) or 0(Disable)for different
duration of the time through the pin 5 of the port D(OC1A).This procedure of varying the on
time of decoders is known as Pulse Width Modulation. When the Enable Pin of the motor driver
IC is set to 1 i.e. enabled its check either Pin of Controller (PC0 or PC1) which key is pressed. It
display a string “MOTOR IN REVERSE DIRECTION” if the first key is pressed and set to the
pin 6 of the Port D to 1 and Pin 7 to 0.When other key is pressed LCD display “MOTOR IN
FORWARD DIRECTION” by setting pin 7 of Port D to 1 and pin 6 of Port D to 0.When the
digital signal 00 or 11 is passed to pin 6 and 7 of Port D Motor will stop and LCD displays a
message “MOTOR IS STOPPED”.

The figure below illustrates the connection diagram.


CHAPTER – 6
ERRORS & PRECAUTIONS
The various precautions and area of errors to be taken into account while working on the
following circuit are as follows

1. Sufficient amount of darkening should be done while drawing the PCB layout over the
copper plate

2. Copper plate should be stirred well enough amount of FeCl3 solution

3. The DC supply of the battery should be connected by taken care of the polarities
otherwise the voltage regulator IC 7805 blows off..

4. While providing supply AC adaptor red wire should go to V DD terminal and while wire
should go to the GND terminal.

5. In case the polarities are not correct the regulator IC 7805 may blow causing direct
supply to the micro Controller (ATmega32) and damage it also.

6. Also the incorrect connection would result in burning of motor driver IC L239D

7. The on boars connection of ISP should be correct otherwise no detection of device will
be related by Win AVR and hence the program will not get executed.
CHAPTER – 7
CONCLUSION & FUTURE EXPANSION
7.1 Conclusion
From this project “Microcontroller based Elevator System” we conclude that an effective speed
control can be achieved by varying the width of the pulse efficiently. The reason why this
method is more effective than other method is that the regulation achieved in this method is
sharp, accurate and we can get variety of range of speed above and below the rated speed.

We successfully achieved the objective of the project with the effective speed control and
displaying the speed on the motor on RPM along with the direction of rotation on LCD panel.

7.2 Future Expansion

The Future expansion of the project could be that, now in this project the speed is
control is done by the keypad by using keys .In future we are planning to control
the speed using a wireless device (Remote) and a wireless module. The range
speed can be indicated by the LED. Thus many motor can be controlled from the
one location with the help of Remote.
CHAPTER-8
APPENDIX
CODING
#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#include<compat/deprecated.h> // HEADER FILE FOR FUNCTIONS LIKE SBI AND CBI
#include<avr/pgmspace.h>
#include<stdlib.h>
#include “lcd.h”
#define OC1A_PIN PD5 //OC1A pin
#define OC1B_PIN PD 6 //OC1B pin
#define OC1_DDR DDRD //OC1 DDR
Void lcd_putint(int i);
Void motor_speed(void );
Void lcd_putint(int i) //print integer on lcd(no auto linefeed)
{
char buffer[7];
itoa(i,buffer,10); //convert integer into string(decimal format)
lcd_puts(buffer); //and transmit string to LCD
} // lcd_putint
int i=0,j=0;
void motor_speed()
{
for(int k=0;k==0;)
{
if(bit_is_clear(PINC,0)) //if INT0 switch is passed to increase
{
i=i+10;
if(i>255)
i=255;
lcd_clrscr(); //clear display and home cursor
lcd_puts(“0 pressed”);
lcd_putint(i);
j=255-I;
if(i<=10)
j=255;
OCR1AL=j;
OCR1BL=j;
_delay_ms(250);
_delay_ms(250);
}
else
if(bit_is_clear(PINC,1)) //if INT1 switch is pressed to decrease speed
{
i=i-10;
if(i<=0)
i=1;
lcd_clrscr(); //clear display and home cursor
lcd_puts(“1 pressed”);
lcd_putint(i);
j=255-i;
if(i<=10)
j=255;
OCR1AL=j;
OCR1BL=j;
_delay_ms(250);
_delay_ms(250);
}
}
}
int main(void)
{
DDRB=0XFB; //Set Data Direction Register
//Set 1 for Output Port
//Set 0 for Input Port
DDRD=0XFF; //Set Data Direction Register
//Set 1 for Output Port
//Set 0 for Input Port
DDRC=0x00;
DDRA=0x00;
sbi(PORTD,5); //Motor1 Enable
sbi(PORTC,0); //Motor1 Enable
sbi(PORTC,1); //Motor1 Enable
OC1_DDR|=_BV(OC1A_PIN)+_BV(OC1B_PIN);
//Set OC1A and OC1B pin as output,required for output toggling
TCCR1A=_BV(WGM10) |_BV(COM1A1)|_BV(COM1A0) | _BV(COM1B1) |_BV(COM1B0);
//enable 8 bit PWM,select inverted PWM
//timer1 running on 1/8MCU clock with clear timer/counter1 on Compare Match
//PWM frequency will be MCU clock /8/512,e.g. with 1 MHz Crystal 244 Hz.
TCCR1B=_BV(CS11) |_BV(WGM12);
lcd_init(LCD_DISP_ON); //initialize display,cursor off
lcd_clrscr()(); //clear display and home cursor
lcd_puts(“LCD is Ready\n”); //put string to display (line1) with line feed
_delay_ms(2000);
lcd_clrscr(); //clear display and home cursor
lcd_puts(“???Key”); //cursor is now on second line , write second line
_delay_ms(2000);
for(;;)
{
lcd_puts(“SELECT DIRECTION\n”);
lcd_puts(“1:-UP 2:- DOWN ”);
if(bit_is_clear(PINC,0))
{
lcd_clrscr(); //clear display and home cursor
lcd_puts(“Motor in Forward\n”);
lcd_puts(“Direction\n”);
_delay_ms(2000);
sbi(PORTD,6);
cbi(PORTD,7);
motor_speed();
}
else
{
if(bit_is_clear(PINC,1))
{
lcd_clrscr(); //clear display and home cursor
lcd_puts(“Motor in Reverse\n”);
lcd_puts(“Direction\n”);
_delay_ms(2000);
sbi(PORTD,7);
cbi(PORTD,6);
motor_speed();
}
else
{
cbi(PORTD,7);
cbi(PORTD,7);
}
}
}
Return 0;
}
CHAPTER-9
REFERENCES AND BIBLOGRAPHY
1. Working with win AVR
2. Robotics trainer Manual
3. let us C-By-Yashwant Kanetkar
4. www.wikipedia.com
5. www.google.com
6. http://en.wikipedia.org/wiki/Resistor
7. http://personal.ee.surrey.ac.uk/Personal/H.M/UGLabs/images/resistor_packages.jpg
8. http://en.wikipedia.org/wiki/Capacitor
9. http://en.wikipedia.org/wiki/Linear_regulator
10. http://en.wikipedia.org/wiki/Liquid_crystal_display
11. http://en.wikipedia.org/wiki/Electric_motor
12. http://www.futurlec.com/Atmel/ATMEGA32.shtml

You might also like