You are on page 1of 68

INTRODUCTION

Metro train is a very vast and new technology train. Its understanding is a need of
train in technology and the advancements in the every field. We are here by
developing a complete model based project which will explain the features of Metro
Train.In this train feature are in cost effective . In this Project we will implement the
following features like:-
1. Automatic Platform Approach Detection and Halt.
2. Automatic Braking System and Line hang-ups during Emergency.
3. Automatic Door Opening System.
4. Ticket counters.
5. To avoid the collision of train
These features are not very common simplest train but its not that easy to understand
their implementation and concept behind it. The design of complete concept is
recurrent ideology of MECHATRONICS; it’s a combination of electronics and
mechanical concepts.
The Synchronization of various steps followed in the concept is desired with an edge
as once synchronization will be lost then there will be no symmetry in the complete
project so we have to take proper interrupts at desired levels to implement the
complete concept. The initialization and the end of the project has got symmetry of
steps and followed on after the other.
1.1 PROBLEM DESCRIPTION
This project is a complete microcontroller based collision avoider.
The aim of this project is to develop a microcontroller based IR range sensor which
measures the distance of the closest object that comes in front of it and immediately
sends an interrupt to the microcontroller to stop the metro train if there is a possibility
of a collision.

1
1.2 BLOCK DIAGRAM

LCD ALARM

POWER SUPPLY MCU UNIT LINE DRIVER

PC
IR SENSOR ISOLATION CKT

POWER AMP

RELAY CKT

STEPPER
MOTOR

Fig no:- 1

2
1.3 CIRCUIT DIAGRAM

J 7

1
2
3
4
5
J 6

1
2
3
4
5
U 1 U 2 V C
L C D
C
J 11 4 0
V C
J
C
3
1 3 1 3 2 1 V C C
V I N V O U T V I N V O U T 3 2 P 1 . 0 3 9 1
d 1 d 2 R 6 4 3 P 1 . 1 P 0 3 . 80 2

2
R 7 S W C 1 4 5 4 P 1 . 2 P 0 3 . 71 3

GND

GND
J 1 4 6 5 P 1 . 3 P 0 3 . 62 4
7 6 P 1 . 4 P 0 3 . 53 5
2 C 1 8 7 P 1 . 5 P 0 3 . 44 6
1 P 1 . 6 P 0 3 . 35 7
2

1
8
C 3 9 P 1 . 7 P 0 3 . 26 8
C 2 1 0R E S E T P 0 3 . 17 9
d 4 d 3 D 6 1 1R X DU 3 E A 3/ V0 P 1 0
R 5 1 2T X D A L E / P
1 I3 N T 0 2 9
D 5 1 I4 N T 1 P S E N
1 T5 0
1 6T 1 2 8
1 7W R 8 0 5 1P 2 2 . 77
C 5 R D P 2 2 . 66
1 8 P 2 2 . 55
X 2 P 2 2 . 44
Y 1 1 9 P 2 2 . 33
C 6 X 1 P 2 2 . 22
2 0 P 2 2 . 11
V S S P 2 . 0

C 7

R 1 3 U 9

1 1 5
2 I S IE S N E A N B
R 1 5 3 O U T 11 4
O U O T U2 T 4
4 1 3

1
R 1 7 V S O U T 3 R 2 4 U 7 U 6 U 5 U 4

S E N S O R
5 1 2
R 1 6 R 1 9 I N 1 I N 4 R 2 3 4 N 3 5 4 N 3 5 4 N 3 5
U 8 A
6 1 1
4

3 R 2 0 E N EA N B R 1 8
R 1 0 R 1 1 +

I N P U T
1 7 1 0
2 I N 2 I N 3
-
8 9
G N VD S S

4
5
6

4
5
6

4
5
6

4
5
6
L M 3 R2 41 2
11

L 2 9 8 / M U L T I H
R 4 R 3 R 2 R 1

L 2
R 1 4
D 1 D1 1 D2 1 D3 1 4

V C C
Q 1

1
Q 4 2
1

Q 3 Q 2

M o t o r 2
2

1
2 2
L 1

3
3

3
D 7 D 8 D 9 D 1 0

M o t o r 1

S T E P P E R M O T O R

Fig no:- 2

3
1.4 Working
In this project of metro train are designed and technology used in the driver less
metro train which is used in most of the developed countries like Germany,
France, and Japan etc. These trains are equipped with the CPU, which control
the train. The train is programmed for the specific path. Every station on the path
is defined; stoppage timing of the train and distance between the two stations is
predefined.
In this project we try to give the same prototype for this type of trains. We are
using microcontroller 8052 as CPU. The motion of the train is controlled by the
Stepper Motor, for displaying message in the train we are using Intelligent LCD
Display of two lines. The train is designed for three stations, named as Aligarh,
Ghaziabad & New Delhi. The Stoppage time is of 3 Sec and time between two
consecutive stations is 6 sec. There is a LCD display for showing various
messages in the train for passengers. There are indicators, which are used to
show the train direction i.e. Up path and Down path. Before stopping at station
the train blows the buzzer. It also includes an emergency brake system due to
which the train stops as soon as the sensors are applied and resumes journey
when the emergency situation is over.

4
2. COMPONENT LIST

S. No. COMPONENT SPECIFICATION


1. STEP DOWN TRANSFORMER 220 TO 9 VOLT AC- 750 MA

2. DIODE IN 4007 ( 4)

3. CAPACITOR 1000MFD(2) 16 VOLT

4. REGULATOR 7805 ( 3 PIN REGULATOR) 1A

5. RESISTOR: FIXED 470 OHM.(3)

10 K OHM (11)

4.7 K (8)

6. IR SENSOR

7. LCD 2 BY 16

8. VARIABLE RESISTOR 4. 7 K OHM

9. OPTOCOUPLER 4N35 (2)

10. NPN TRANSITOR (2) BC 548/547

11. PNP TRANSISTOR(2) BC 558/557

12. STEPPER MOTOR GEAR SLOW SPEED 9-12 VOLT-


250 MA

13. CRYSTAL OSCILLATOR 11.0592 MHz

14. DISC CAPACITOR 33 PF (2), 0.1UF

15. PUSH TO ON START SWITCH (1)

16. ATMEL MICROCONTROLLER 8052

5
2.1TOOLS/SOFTWARES /COMPONENTS REQUIRED
• KEIL µ Vision2 Software for programming of Microcontroller.
• I.C Programmer and Software for the burning of the Microcontroller.
• ULTRA SONIC SENSORS.
• Components for designing of the embedded part.
• Soldering kit.
• Measuring Instruments (Multi-meter), etc.

6
3. COMPONENT DESCRIPTION
3.1 POWER SUPPLY DESCRIPTION

TRANSFORMER BRIDGE SHUNT VOLTAGE


RECTIFIER CAPACITOR REGULATOR

The power supply circuit comprises of four basic parts:


The transformer steps down the 220 V a/c. into 12 V a/c. The transformer work on the
principle of magnetic induction, where two coils: primary and secondary are wound
around an iron core. The two coils are physically insulated from each other in such a way
that passing an a.c. current through the primary coil creates a changing voltage in the
primary coil and a changing magnetic field in the core. This in turn induces a varying a/c.
voltage in the secondary coil.
The a.c voltage is then fed to the bridge rectifier. The rectifier circuit is used in most
electronic power supplies is the single-phase bridge rectifier with capacitor filtering,
usually followed by a linear voltage regulator. A rectifier circuit is necessary to convert a
signal having zero average value into a non-zero average value. A rectifier transforms
alternating current into direct current by limiting or regulating the direction of flow of
current. The output resulting from a rectifier is a pulsating D.C. voltage. This voltage is
not appropriate for the components that are going to work through it.

12-0-12 V
7812

IN4007
7805

TRANSFORMER
1000uF

Fig no:-3

7
The ripple of the D.C. voltage is smoothened using a filter capacitor of 1000 microF 25V.
The filter capacitor stores electrical charge. If it is large enough the capacitor will store
charge as the voltage rises and give up the charge as the voltage falls. This has the effect
of smoothing out the waveform and provides steadier voltage output. A filter capacitor is
connected at the rectifier output and the d.c voltage is obtained across the capacitor.
When this capacitor is used in this project, it should be twice the supply voltage. When
the filter is used, the RC charge time of the filter capacitor must be short and the RC
discharge time must be long to eliminate ripple action. In other words the capacitor must
charge up fast, preferably with no discharge.
When the rectifier output voltage is increasing, the capacitor charges to the peak voltage
Vm. Just past the positive peak, the rectifier output voltage starts to fall but at this point
the capacitor has +Vm voltage across it. Since the source voltage becomes slightly less
than Vm, the capacitor will try to send current back through the diode of rectifier. This
reverse biases the diode. The diode disconnects or separates the source the source form
load. The capacitor starts to discharge through load. This prevents the load voltage from
falling to zero. The capacitor continues to discharge until source voltage becomes more
than capacitor voltage. The diode again starts conducting and the capacitor is again
charged to peak value Vm. When capacitor is charging the rectifier supplies the charging
through capacitor branch as well as load current, the capacitor sends currents through the
load. The rate at which capacitor discharge depends upon time constant RC. The longer
the time constant, the steadier is the output voltage. An increase in load current i.e.
decrease in resistance makes time constant of discharge path smaller. The ripple increase
and d.c output voltage V dc decreases. Maximum capacity cannot exceed a certain limit
because the larger the capacitance the greater is the current required to charge the
capacitor.
The voltage regulator regulates the supply if the supply if the line voltage
increases or decreases. The series 78xx regulators provide fixed regulated voltages
from 5 to 24 volts. An unregulated input voltage is applied at the IC Input pin i.e. pin 1
which is filtered by capacitor. The out terminal of the IC i.e. pin 3 provides a regular
output. The third terminal is connected to ground. While the input voltage may vary over
some permissible voltage range, and the output voltage remains constant within specified

8
voltage variation limit. The 78xx IC’s are positive voltage regulators whereas 79xx IC’s
are negative voltage regulators.
These voltage regulators are integrated circuits designed as fixed voltage regulators for a
wide variety of applications. These regulators employ current limiting, thermal shutdown
and safe area compensation. With adequate heat sinking they can deliver output currents
in excess of 1 A. These regulators have internal thermal overload protection. It uses
output transistor safe area compensation and the output voltage offered is in 2% and 4%
tolerance.

9
3.2 THE MICROCONTROLER
In our day to day life the role of micro-controllers has been immense. They are used in a
variety of applications ranging from home appliances, FAX machines, Video games,
Camera, Exercise equipment, Cellular phones musical Instruments to Computers, engine
control, aeronautics, security systems and the list goes on.
3.2.1 MICROCONTROLLERS VERSUS MICROPROCESSORS
What is the difference between a microprocessor and microcontroller? The
microprocessors (such as 8086,80286,68000 etc.) contain no RAM, no ROM and no I/O
ports on the chip itself. For this reason they are referred as general- purpose
microprocessors. A system designer using general- purpose microprocessor must add
external RAM, ROM, I/O ports and timers to make them functional. Although the
addition of external RAM, ROM, and I/O ports make the system bulkier and much more
expensive, they have the advantage of versatility such that the designer can decide on the
amount of RAM, ROM and I/o ports needed to fit the task at hand. This is the not the
case with microcontrollers. A microcontroller has a CPU (a microprocessor) in addition
to the fixed amount of RAM, ROM, I/O ports, and timer are all embedded together on the
chip: therefore, the designer cannot add any external memory, I/O, or timer to it. The
fixed amount of on chip RAM, ROM, and number of I/O ports in microcontrollers make
them ideal for many applications in which cost and space are critical. In many
applications, for example a TV remote control, there is no need for the computing power
of a 486 or even a 8086 microprocessor. In many applications, the space it takes, the
power it consumes, and the price per unit are much more critical considerations than the
computing power. These applications most often require some I/O operations to read
signals and turn on and off certain bits. It is interesting to know that some
microcontrollers manufactures have gone as far as integrating an ADC and other
peripherals into the microcontrollers.

10
3.2.2 MICROCONTROLLER BLOCK DIAGRAM

EXTERNAL
INTERRUPTS

ETC.
ON-CHIP ON-CHIP
INTERRUPT ROM for RAM
CONTROL program code TIMER 0

TIMER 1

CPU

BUS SERIAL
OSC CONTROL 4 I/O PORT
PORTS
TXD RXD

Fig no :-4

11
3.2.3 INTRODUCTION TO 8052:- In 1981, Intel Corporation introduced an 8-bit
microcontroller called the 8052. This microcontroller had 256 bytes of RAM, 4K bytes of
on-chip ROM, two timers, one serial port, and four ports (8-bit) all on a single chip. The
8052 is an 8-bit processor, meaning the CPU can work on only 8- bit pieces to be
processed by the CPU. The 8052 has a total of four I/O ports, each 8- bit wide. Although
8052 can have a maximum of 128K bytes of on-chip ROM, many manufacturers put only
4K bytes on the chip.
The 8052 became widely popular after Intel allowed other manufacturers to make any
flavor of the 8052 they please with the condition that they remain code compatible with
the 8052. This has led to many versions of the 8052 with different speeds and amount of
on-chip ROM marketed by more than half a dozen manufacturers. It is important to know
that although there are different flavors of the 8052, they are all compatible with the
original 8052 as far as the instructions are concerned. This means that if you write your
program for one, it will run on any one of them regardless of the manufacturer. The major
8052 manufacturers are Intel, Atmel, Dallas Semiconductors, Philips Corporation,
Infineon.
3.2.4 AT89C52 FROM ATMEL CORPORATION:-
This popular 8052 chip has on-chip ROM in the form of flash memory. This is ideal for
fast development since flash memory can be erased in seconds compared to twenty
minutes or more needed for the earlier versions of the 8052. To use the AT89C52 to
develop a microcontroller-based system requires a ROM burner that supports flash
memory: However, a ROM eraser is not needed. Notice that in flash memory you must
erase the entire contents of ROM in order to program it again. The PROM burner does
this erasing of flash itself and this is why a separate burner is not needed. To eliminate
the need for a PROM burner Atmel is working on a version of the AT89C52 that can be
programmed by the serial COM port of the PC.

12
3.2.5 FEATURES OF AT89C52:-
- 8K on-chip ROM
- 256 bytes internal RAM (8-bit)
- 32 I/O pins
- Two 16-bit timers
- Six Interrupts
- Serial programming facility
- 40 pin Dual-in-line Package
3.2.6 PIN DESCRIPITION

13
Fig no:-5
The 89C52 have a total of 40 pins that are dedicated for various functions such as I/O,
RD, WR, address and interrupts. Out of 40 pins, a total of 32 pins are set aside for the
four ports P0, P1, P2, and P3, where each port takes 8 pins. The rest of the pins are
designated as Vcc, GND, XTAL1, XTAL, RST, EA, and PSEN. All these pins except
PSEN and ALE are used by all members of the 8051 and 8031 families. In other words,
they must be connected in order for the system to work, regardless of whether the
microcontroller is of the 8052 or the 8031 family. The other two pins, PSEN and ALE are
used mainly in 8031 based systems.
Vcc:Pin 40 provides supply voltage to the chip. The voltage source is +5 V.
GND:Pin 20 is the ground.
XTAL1 and XTAL2:-The 8052 have an on-chip oscillator but requires external clock to
run it. Most often a quartz crystal oscillator is connected to input XTAL1 (pin 19) and
XTAL2 (pin 18). The quartz crystal oscillator connected to XTAL1 and XTAL2 also
needs two capacitors of 30 pF value. One side of each capacitor is connected to the
ground.

C1
XTAL1
XTAL2

C2

GND
It must be noted that there are various speeds of the 8052 family. Speed refers to the
maximum oscillator frequency connected to the XTAL. For example, a 12 MHz chip
must be connected to a crystal with 12 MHz frequency or less. Likewise, a 20 MHz
microcontroller requires a crystal frequency of no more than 20 MHz. When the 8052 is
connected to a crystal oscillator and is powered up, we can observe the frequency on the
XTAL2 pin using oscilloscope.

14
Fig no:- 6
RESET CIRCUIT
RST:- Pin 9 is the reset pin. It is an input and is active high (normally low). Upon
applying a high pulse to this pin, the microcontroller will reset and terminate all
activities. This is often referred to as a power –on reset. Activating a power-on reset will
cause all values in the registers to be lost. Notice that the value of Program Counter is
0000 upon reset, forcing the CPU to fetch the first code from ROM memory location
0000. This means that we must place the first line of source code in ROM location 0000
that is where the CPU wakes up and expects to find the first instruction. In order to
RESET input to be effective, it must have a minimum duration of 2 machine cycles. In
other words, the high pulse must be high for a minimum of 2 machine cycles before it is
allowed to go low.
EA:- All the 8052 family members come with on-chip ROM to store programs. In such
cases, the EA pin is connected to the Vcc. For family members such as 8031 and 8032 in
which there is no on-chip ROM, code is stored on an external ROM and is fetched by the
8031/32. Therefore for the 8031 the EA pin must be connected to ground to indicate that
the code is stored externally. EA, which stands for “external access,” is pin number 31 in
the DIP packages. It is input pin and must be connected to either Vcc or GND. In other
words, it cannot be left unconnected.

15
PSEN:- This is an output pin. PSEN stands for “program store enable.” It is the read
strobe to external program memory. When the microcontroller is executing from external
memory, PSEN is activated twice each machine cycle.
ALE:- ALE (Address latch enable) is an output pin and is active high. When connecting a
microcontroller to external memory, potr 0 provides both address and data. In other
words the microcontroller multiplexes address and data through port 0 to save pins. The
ALE pin is used for de-multiplexing the address and data by connecting to the G pin of
the 74LS373 chip.
I/O port pins and their functions :- The four ports P0, P1, P2, and P3 each use 8 pins,
making them 8-bi ports. All the ports upon RESET are configured as output, ready to be
used as output ports. To use any of these as input port, it must be programmed.
Port 0:- Port 0 occupies a total of 8 pins (pins 32 to 39). It can be used for input or output.
To use the pins of port 0 as both input and output ports, each pin must be connected
externally to a 10K-ohm pull-up resistor. This is due to fact that port 0 is an open drain,
unlike P1, P2 and P3. With external pull-up resistors connected upon reset, port 0 is
configured as output port. In order to make port 0 an input, the port must be programmed
by writing 1 to all the bits of it. Port 0 is also designated as AD0-AD7, allowing it to be
used for both data and address. When connecting a microcontroller to an external
memory, port 0 provides both address and data. The microcontroller multiplexes address
and data through port 0 to save pins. ALE indicates if P0 has address or data. When
ALE=0, it provides data D0-D7, but when ALE=1 it has address A0-A7. Therefore, ALE
is used for de-multiplexing address and data with the help of latch 74LS373.
Port 1:- Port 1 occupies a total of 8 pins (pins 1 to 8). It can be used as input or output. In
contrast to port 0, this port does not require pull-up resistors since it has already pull-up
resistors internally. Upon reset, port 1 is configures as an output port. Similar to port 0,
port 1 can be used as an input port by writing 1 to all its bits.
Port 2:- Port 2 occupies a total of 8 pins (pins 21 to 28). It can be used as input or output.
Just like P1, port 2 does not need any pull-up resistors since it has pull-up resistors
internally. Upon reset port 2 is configured as output port. To make port 2 input, it must be
programmed as such by writing 1s to it.

16
Port 3:- Port 3 occupies a total of 8 pins (pins 10 to 17). It can be used as input or output.
P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although port 3 is
configured as output port upon reset, this is not the way it is most commonly used. Port 3
has an additional function of providing some extremely important signals such as
interrupts. Some of the alternate functions of P3 are listed below:
P3.0 RXD (Serial input)
P3.1 TXD (Serial output)
P3.2 INT0 (External interrupt 0)
P3.3 INT1 (External interrupt 1)
P3.4 T0 (Timer 0 external input)
P3.5 T1 (Timer 1 external input)
P3.6 WR (External memory write strobe)
P3.7 RD (External memory read strobe)
3.2.7 INSIDE THE 89C52
Registers:- In the CPU, registers are used to store information temporarily. That
information could be a byte of data to be processed, or an address pointing to the data to
be fetched. In the 8052 there us only one data type: 8 bits. With an 8- bit data type, any
data larger than 8 bits has to be broken into 8-bit chunks before it is processed.

A
B
R0 DPTR
R1
R2
R3
R4 PC
am Counter
R5
R6
R7 (b) Some 8052 16-bit registers
(a) Some 8052 8-bit registers
The most commonly used registers of the 8052 are A(accumulator), B, R0, R1, R2, R3,
R4, R5, R6, R7, DPTR (data pointer) and PC (program counter). All the above registers
are 8-bit registers except DPTR and the program counter. The accumulator A is used for
all arithmetic and logic instructions.

17
Program Counter and Data Pointer:- The program counter is a 16- bit register and it
points to the address of the next instruction to be executed. As the CPU fetches op-code
from the program ROM, the program counter is incremented to point to the next
instruction. Since the PC is 16 bit wide, it can access program addresses 0000 to FFFFH,
a total of 64K bytes of code. However, not all the members of the 8052 have the entire
128K bytes of on-chip ROM installed. The DPTR register is made up of two 8-bit
registers, DPH and DPL, which are used to furnish memory addresses for internal and
external data access. The DPTR is under the control of program instructions and can be
specified by its name, DPTR. DPTR does not have a single internal address, DPH and
DPL are assigned an address each
3.2.8 MEMORY SPACE ALLOCATION:-
1.Internal ROM :- The 89C52 has a 4K bytes of on-chip ROM. This 4K bytes ROM
memory has memory addresses of 0000 to 0FFFh. Program addresses higher than 0FFFh,
which exceed the internal ROM capacity will cause the microcontroller to automatically
fetch code bytes from external memory. Code bytes can also be fetched exclusively from
an external memory, addresses 0000h to FFFFh, by connecting the external access pin to
ground. The program counter doesn’t care where the code is: the circuit designer decides
whether the code is found totally in internal ROM, totally in external ROM or in a
combination of internal and external ROM.
2.Internal RAM:- The 256 bytes of RAM inside the 8052 are assigned addresses 00 to
7Fh. These 256 bytes can be divided into three different groups as follows:
1. A total of 32 bytes from locations 00 to 1Fh are set aside for register banks and the
stack.
2.A total of 16 bytes from locations 20h to 2Fh are set aside for bit addressable read/write
memory and instructions.
3.A total of 80 bytes from locations 30h to 7Fh are used for read and write storage, or
what is normally called a scratch pad. These 80 locations of RAM are widely used for the
purpose of storing data and parameters by 8052 programmers.

18
3.3 IR SENSOR

Specification
400ST160 Transmitter

Fig no :-7
400SR160 Receiver
Center Frequency 40.0±1.0Khz
Bandwidth (-6dB) 400ST160 2.0Khz
400SR160 2.5Khz
Transmitting Sound Pressure
Level
at 40.0Khz; 0dB re 0.0002μbar
per 10Vrms at 30cm
120dB min.

Receiving Sensitivity
at 40.0Khz 0dB = 1 volt/μbar
-65dB min.

19
Capacitance at 1Khz ±20% 2400 pF
Max. Driving Voltage (cont.) 20Vrms
Total Beam Angle -6dB 55° typical
Operation Temperature -30 to 80°C
Storage Temperature -40 to 85°C

3.4 RELAY CIRCUIT

THE ELECTROMAGNETIC solenoid valve

Fig no:- 8
The electromagnetic relay consists of a multi-turn coil, wound on an iron core, to form an
electromagnet. When the coil is energised, by passing current through it, the core
becomes temporarily magnetised. The magnetised core attracts the iron armature. The
armature is pivoted which causes it to operate one or more sets of contacts.
When the coil is de-energised the armature and contacts are released. The coil can be
energised from a low power source such as a transistor while the contacts can switch high
powers such as the mains supply. The relay can also be situated remotely from the control
source. Relays can generate a very high voltage across the coil when switched off. This

20
can damage other components in the circuit. To prevent this a diode is connected across
the coil

As there are always some chances of high voltage spikes back from the switching circuit
i.e. heater so an optocoupler/isolator MCT2e is used. It provides and electrical isolation
between the microcontroller and the heater. MCT2e is a 6-pin IC with a combination of
optical transmitter LED and an optical receiver as phototransistor. Microcontroller is
connected to pin no 2 of MCT2e through a 470-ohm resistor. Pin no.1 is given +5V
supply and pin no.4 is grounded.
To handle the current drawn by the heater a power transistor BC-369 is used as a current
driver. Pin no.5 of optocoupler is connected to the base of transistor. It takes all it’s
output to Vcc and activates the heater through relay circuit. The electromagnetic relay
consists of a multi-turn coil, wound on an iron core, to form an electromagnet. When the
coil is energized, by passing current through it, the core becomes temporarily
magnetized. The magnetized core attracts the iron armature. The armature is pivoted
which causes it to operate one or more sets of contacts. When the coil is de-energised the
armature and contacts are released. Relays can generate a very high voltage across the
coil when switched off. This can damage other components in the circuit. To prevent this
a diode is connected across the coil. Relay has five points. Out of the 2 operating points
one is permanently connected to the ground and the other point is connected to the
collector side of the power transistor. When Vcc reaches the collector side i.e. signal is
given to the operating points the coil gets magnetized and attracts the iron armature. The
iron plate moves from normally connected (NC) position to normally open (NO) position.
Thus the heater gets the phase signal and is ON. To remove the base leakage voltage
when no signal is present a 470-ohm resistance is used.

21
J4
p ha se
5 NC 1
3 2
D11 4
1 NO HEA TER
2
1 6
5 R4 RELA Y
V CC V CC
2 4 BC-3 6 9
R2 MCT2E

From P3.0 of
microcont roller

Fig no:- 9
3.5 ISOLATION CIRCUIT

As more electronic devices were used to form circuits, the demand to connect circuits
with differing voltage potentials and differing impedances together became more
prevalent. For example, as computers and programmable controllers became more usable
on the factory floor, it became evident that some type of interface would be needed that
could isolate the 220 volt AC and 110 volt AC signals that most machinery used from the
small DC bus voltages found in computers. Isolation is also a problem when larger AC

22
and DC voltages need to be interfaced to TTL logiccircuits.

Fig no:- 10

23
(Electrical block diagram and physical layout of a typical opto-coupler. The optocoupler
is also called an optoisolator and it is usually packaged as a six-pin 1C chip)
The simple solution to this problem is to combine an LED with a phototransistor. The
new device is totally encapsulated so that the light from the LED is focused directly on
the opening in the phototransistor, and no other forms of light could be detected. The
input signal is connected to the LED and the output signal is connected to the transistor.
The device is called an optocoupler or optoisolator.
LED shining light directly on a photodector, which is usually a phototransistor. The
second diagram in the figure shows how the LED is located so its light is focused directly
on the phototransistor.

Fig no:-11
(Pin outline for an optocoupler for a six-pin 1C
A sketch of a six-pin 1C is also shown)

The 1C package may also be called an 1C or a chip. From this diagram you can see that
the anode of the LED is pin 1 and the cathode is pin 2. The emitter of the phototransistor
is pin 4, the collector is pin 5, and the base is pin 6. It is important to note that each type
of optocoupler may use different pin assignments.

24
Fig no:-12

(Electrical diagram of an optocoupler used to interface an annunciator horn to a


computer. The relay coil is connected to the output stage of the optocoupler)

An optocoupler interfacing a computer output signal to a relay coil and the contacts of the
relay are used to energize a 110 volt alarm lamp and annunciator. This circuit allows the
small-voltage signal from the computer to safely energize the high-voltage lamp and horn
without the fear of allowing any high-voltage spikes to get back into the computer.
Optocouplers are also used in programmable logic controller (PLC) 110 volt input and
output modules to provide isolation between the 110 volt signals and PLC bus. In
industrial applications a limit switch on a machine is wired for 110 volt AC so that it is
not bothered by induced electrical noise. The 110 volt AC signal is connected to the
programmable controller input module circuit consisting of a bridge rectifier that
converts the AC signal to DC, a resistor, and the LED for the optocoupler. The transistor
side of the optocoupler is connected to the input bus of the PLC. Since the signal emitted
by the LED is transferred by light, the high and low voltages of the circuit are isolated.

25
Fig no:-13

(Optocoupler used in a PLC input module. When the switch closes, 110 volts AC is
provided to terminal 1. The phototransistor in the Optocoupler is connected to the PLC
input bus.)

26
3.5.1Opto-isolator

Opto-isolator

Fig no:-14

In electronics, an opto-isolator (or optical isolator, optocoupler, photocoupler, or


photoMOS) is a device that uses a short optical transmission path to transfer a signal
between elements of a circuit, typically a transmitter and a receiver, while keeping them
electrically isolated since the signal goes from an electrical signal to an optical signal
back to an electrical signal, electrical contact along the path is broken.

An opto-isolator can also be constructed using a small incandescent lamp in place of the
LED; such a device, because the lamp has a much slower response time than an LED,
will filter out noise or half-wave power in the input signal. In so doing, it will also filter
out any audio- or higher-frequency signals in the input. It has the further disadvantage, of
course, (an overwhelming disadvantage in most applications) that incandescent lamps
have finite life spans. Thus, such an unconventional device is of extremely limited
usefulness, suitable only for applications such as science projects.

They are used to isolate low-current control or signal circuitry from transients generated
or transmitted by power supply and high-current control circuits. The latter are used
within motor and machine control function blocks.

27
Opto-coupler :- it has one IR LED and a photo- transistor. One pin of the LED is
connected to the MCU to get a signal (0 or 1) and the pin is given ground. When the
signal from the MCU is 0, then LED emits light. This light will turn on the npn transistor.
Collector of the transistor is grounded. Emitter is connected to the pnp transistor whose
collector is connected to Vcc and emitter to the relay. P in npn transistor means 1 and n
means 0.

3.6 LINE DRIVER CIRCUIT

28
This circuit uses MAX232, which is an electronic circuit that converts signals from a
serial port to signals suitable for usage in e.g. microprocessor circuits.When
communicating with various micro processors one needs to convert the RS232 levels
down to lower levels, typically 3.3 or 5.0 Volts. Serial RS-232 communication works
with voltages -15V to +15V for high and low. On the other hand, TTL logic operates
between 0V and +5V . Modern low power consumption logic operates in the range of 0V
and +3.3V or even lower.Thus the RS-232 signal levels are far too high TTL electronics,
and the negative RS-232 voltage for high can’t be handled at all by computer logic. To
receive serial data from an RS-232 interface the voltage has to be reduced. Also the low
and high voltage level has to be inverted. The level converter uses a Max232 and five
capacitors .

Fig no:- 15 (MAX232)

29
3.6.Applicability :-This module is primary of interest for people building their own
electronics with an RS-232 interface. Off-the-shelf computers with RS-232
interfaces already contain the necessary electronics, and there is no need to add the
circuitry as described here.

3.6.2 Logic Signal Voltage :-Serial RS-232 (V.24) communication works with voltages
(-15V ... -3V for high [sic]) and +3V ... +15V for low [sic]) which are not
compatible with normal computer logic voltages. On the other hand, classic TTL
computer logic operates between 0V ... +5V (roughly 0V ... +0.8V for low, +2V ...
+5V for high). Modern low-power logic operates in the range of 0V ... +3.3V or
even lower. So, the maximum RS-232
signal levels are far too high for computer logic electronics, and the negative RS-
232 voltage for high can't be grokked at all by computer logic. Therefore, to receive
serial data from an RS-232 interface the voltage has to be reduced, and the low and
high voltage level inverted. In the other direction (sending data from some logic
over RS-232) the low logic voltage has to be "bumped up", and a negative voltage
has to be generated, too.
RS-232 TTL Logic
-----------------------------------------------
-15V ... -3V <-> +2V ... +5V <-> high
+3V ... +15V <-> 0V ... +0.8V <-> low
All this can be done with conventional analog electronics, e.g. a particular power supply
and a couple of transistors or the once popular 1488 (transmitter) and 1489 (receiver) ICs.
However, since more than a decade it has become standard in amateur electronics to do
the necessary signal level conversion with an integrated circuit (IC) from the MAX232
family (typically a MAX232A or some clone). In fact, it is hard to find some RS-232
circuitry in amateur electronics without a MAX232A or some clone.
The MAX232 from Maxim was the first IC which in one package contains the necessary
drivers (two) and receivers (also two), to adapt the RS-232 signal voltage levels to TTL
logic. It became popular, because it just needs one voltage (+5V) and generates the
necessary RS-232 voltage levels (approx. -10V and +10V) internally. This greatly
simplified the design of circuitry. Circuitry designers no longer need to design and build

30
a power supply with three voltages (e.g. -12V, +5V, and +12V), but could just provide
one +5V power supply.
The MAX232 has a successor, the MAX232A. The ICs are almost identical, however, the
MAX232A is much more often used (and easier to get) than the original MAX232, and
the MAX232A only needs external capacitors 1/10th the capacity of what the original
MAX232 needs.
It should be noted that the MAX232(A) is just a driver/receiver. It does not generate the
necessary RS-232 sequence of marks and spaces with the right timing, it does not decode
the RS-232 signal, it does not provide a serial/parallel conversion. All it does is to
convert signal voltage levels.
The MAX232 and MAX232A were once rather expensive ICs, but today they are cheap
MAX232(A)

DIP Package:-

C1+ -|1 16 |- Vcc

V+ -|2 15 |- GND
C1- -| 3 14 |- T1out
C2+ -| 4 13 |- R1in
C2- -| 5 12 |- R1out
V- -| 6 11 |- T1in
T2out -| 7 10 |- T2in
R2in -| 8 9|- R2out

31
MAX232(A) DIP Package Pin Layout
Nbr Name Purpose Signal Voltage
1 C1+ + connector for capacitor C1 capacitor should stand at least 16V
2 V+ output of voltage pump +10V
3 C1- - connector for capacitor C1 capacitor should stand at least 16V
4 C2+ + connector for capacitor C2 capacitor should stand at least 16V
5 C2- - connector for capacitor C2 capacitor should stand at least 16V
6 V- output of voltage pump / inverter -10V
7 T2out Driver 2 output RS-232
8 R2in Receiver 2 input RS-232
9 R2out Receiver 2 output TTL
10 T2in Driver 2 input TTL
11 T1in Driver 1 input TTL
12 R1out Receiver 1 output TTL
13 R1in Receiver 1 input RS-232
14 T1out Driver 1 output RS-232
15 GND Ground 0V
16 VCC Power supply +5V

32
3.7LIQUID CRYSTAL DISPLAY

LCD Display :- Liquid crystal displays (LCD) are widely used in recent
years as compares to LEDs. This is due to the declining prices of
LCD, the ability to display numbers, characters and graphics,
incorporation of a refreshing controller into the LCD, their by
relieving the CPU of the task of refreshing the LCD and also the
ease of programming for characters and graphics. HD 44780
based LCDs are most commonly used.
LCD pin description :-The LCD discuss in this section has the most common connector
used for the Hitatchi 44780 based LCD is 14 pins in a row and modes of operation and
how to program and interface with microcontroller is describes in this section.

1 6 G n d
1 6 1 5
1 5 V c c
1 4 D 7
1 4 1 3
1 3 D 6
1 2 D 5
1 2 1 1
1 1 D 4
1 0 D 3
1 0 9
9 D 2
8 D 1
8 7
7 D 0
6 E
3

6 5
5 R / W
4 R S
4 3
3 C o n t r a 2s t
2 V c c
2 1
1 G n d
1

LCD Pin Description Diagram


Fig no:- 16

VCC, VSS, VEE :- The voltage VCC and VSS provided by +5V and ground respectively while
VEE is used for controlling LCD contrast. Variable voltage between Ground and Vcc is
used to specify the contrast (or "darkness") of the characters on the LCD screen.

33
RS (register select) :- There are two important registers inside the LCD. The RS pin is
used for their selection as follows. If RS=0, the instruction command code register is
selected, then allowing to user to send a command such as clear display, cursor at home
etc.. If RS=1, the data register is selected, allowing the user to send data to be displayed
on the LCD.
R/W (read/write) :- The R/W (read/write) input allowing the user to write information
from it. R/W=1, when it read and R/W=0, when it writing.
EN (enable) :- The enable pin is used by the LCD to latch information presented to its
data pins. When data is supplied to data pins, a high power, a high-to-low pulse must be
applied to this pin in order to for the LCD to latch in the data presented at the data pins.
D0-D7 (data lines) :- The 8-bit data pins, D0-D7, are used to send information to the
LCD or read the contents of the LCD’s internal registers. To displays the letters and
numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins
while making RS =1. There are also command codes that can be sent to clear the display
or force the cursor to the home position or blink the cursor.
We also use RS =0 to check the busy flag bit to see if the LCD is ready to receive the
information. The busy flag is D7 and can be read when R/W =1 and RS =0, as follows: if
R/W =1 and RS =0, when D7 =1(busy flag =1), the LCD is busy taking care of internal
operations and will not accept any information. When D7 =0, the LCD is ready to receive
new information.

34
LCD pin description

Pin Symbol I/O Description


1 VSS - Ground
2 VCC - +5V power supply
3 VEE - Power supply to control contrast
4 RS I RS=0 to select command register, RS=1 to select data
register.
5 R/W I R/W=0 for write, R/W=1 for read
6 E I/O Enable
7 PB0 I/O The 8 bit data bus
8 PB1 I/O The 8 bit data bus
9 DB2 I/O The 8 bit data bus
10 DB3 I/O The 8 bit data bus
11 DB4 I/O The 8 bit data bus
12 DB5 I/O The 8 bit data bus
13 DB6 I/O The 8 bit data bus
14 DB7 I/O The 8 bit data bus

3.7.1 LCD OPERATION :- LCD is finding widespread use replacing LCD`s . This is
due to the following reasons. The LCD has ability to display numbers, characters &
graphics. This is in contrast to LED`s, which are limited to numbers and a few characters.

35
Incorporation of a refereshing controller into the LCD, thereby relieving the CPU of the
task of refereshing the LCD. In contrast, the LED must be refereshed by the CPU (or in
the same other way) to keep displaying the data. Erase the program for characters and
graphics.

3.7.2 LCD Backgorund:-


Frequently, an 8052 program must interact with the outside world using input and output
devices that communicate directly with a human being. One of the most common devices
attached to an 8052 is an LCD display. Some of the most common LCDs connected to
the 8052are 16x2 and 20x2 displays. This means 16 characters per line by 2 lines and 20
characters per line by 2 lines, respectively.
Fortunately, a very popular standard exists which allows us to communicate with the vast
majority of LCDs regardless of their manufacturer. The standard is referred to as
HD44780U, which refers to the controller chip which receives data from an external
source (in this case, the 8052) and communicates directly with the LCD.
44780:-
The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data
bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit
data bus. If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control
lines plus the 4 lines for the data bus). If an 8-bit data bus is used the LCD will require a
total of 11 data lines (3 control lines plus the 8 lines for the data bus).
The three control lines are referred to as EN, RS, and RW. The EN line is called
"Enable." This control line is used to tell the LCD that you are sending it data. To send
data to the LCD, your program should make sure this line is low (0) and then set the other
two control lines and/or put data on the data bus. When the other lines are completely
ready, bring EN high (1) and wait for the minimum amount of time required by the LCD
datasheet (this varies from LCD to LCD), and end by bringing it low (0) again.
The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is
high (1), the data being sent is text data which sould be displayed on the screen. For
example, to display the letter "T" on the screen you would set RS high.

36
The RW line is the "Read/Write" control line. When RW is low (0), the information on
the data bus is being written to the LCD. When RW is high (1), the program is effectively
querying (or reading) the LCD. Only one instruction ("Get LCD status") is a read
command. All others are write commands--so RW will almost always be low.
Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected
by the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2,
DB3, DB4, DB5, DB6, and DB7.
3.7.3 CURSOR POSITIONING:-
The above "Hello Metro" program is simplistic in the sense that it prints its text in the
upper left-hand corner of the screen. However, what if we wanted to display the word
"Hello" in the upper left-hand corner but wanted to display the word "METRO" on the
second line at the tenth character? This sounds simple--and actually, it is simple.
However, it requires a little more understanding of the design of the LCD.
The 44780 contains a certain amount of memory which is assigned to the display. All the
text we write to the 44780 is stored in this memory, and the 44780 subsequently reads
this memory to display the text on the LCD itself. This memory can be represented with
the following "memory map":

In the above memory map, the area shaded in blue is the visible display. As you can see,
it measures 16 characters per line by 2 lines. The numbers in each box is the memory
address that corresponds to that screen position.
Thus, the first character in the upper left-hanad corner is at address 00h. The following
character position (character #2 on the first line) is address 01h, etc. This continues until
we reach the 16th character of the first line which is at address 0Fh.
However, the first character of line 2, as shown in the memory map, is at address 40h.
This means if we write a character to the last position of the first line and then write a
second character, the second character will not appear on the second line. That is because
the second character will effectively be written to address 10h--but the second line begins
at address 40h.

37
Thus we need to send a command to the LCD that tells it to position the cursor on the
second line. The "Set Cursor Position" instruction is 80h. To this we must add the address
of the location where we wish to position the cursor. In our example, we said we wanted
to display "World" on the second line on the tenth character position.
Referring again to the memory map, we see that the tenth character position of the second
line is address 4Ah. Thus, before writing the word "World" to the LCD, we must send a
"Set Cursor Position" instruction--the value of this command will be 80h (the instruction
code to position the cursor) plus the address 4Ah. 80h + 4Ah = C4h. Thus sending the
command C4h to the LCD will position the cursor on the second line at the tenth
character position:
CLR RS
MOV DATA,#0C4h
SETB EN
CLR EN
LCALL WAIT_LCD
The above code will position the cursor on line 2, character 10. To display "Hello" in the
upper left-hand corner with the word "World" on the second line at character position 10
just requires us to insert the above code into our existing "Hello Metro program. This
results in the following:
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT

38
CLR RS
MOV DATA,#0C4h
SETB EN
CLR EN
LCALL WAIT_LCD
MOV A,#'M'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'T'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'O'
LCAL L WRITE_TEXT

3.7.4 Introduction to LCD Programming : Driving 4-bit Mode


This second LCD-tutorial is based on 'Introduction to LCD Programming', so you should
to read that first. In the first tutorial we have seen that character LCD's based on the
HD44780 chip can be driven in 8bits mode, which requires in total 11 lines from you
microcontroller. If we want (or need) to spare some lines for other purposes it is possible
to drive the display in 4bits mode, which requires 7 lines. It is possible to use only 6
lines, in which case R/W is tied to Ground. This configuration is seen many times in
projects. Instead of reading the busy flag (which is somewhat trickier than it is in 8 bit
modus) we have to use delay loops. These delay loops have to be recalculated when using
other oscillator frequencies. In this tutorial we use the somewhat harder solution, making
use of the busy flag and being independent of the oscillator frequency. The only
drawback using 4 bits is that commands and data have to be sent in two nibbles (4bit
parts) to the display, which take slightly more time
INITIALIZING THE LCD :- Before you may really use the LCD, you must initialise and
configure it. This is accomplished by sending a number of initialisation instructions to the

39
LCD. The first instruction we send must tell the LCD we'll be communicating with it
with a 4-bit data bus. We also select a 5x8 dot character font. These two options are
selected by sending the command 28h to the LCD as a command. After powering up the
LCD, it is in 8-bit mode. Because only four bits are connected, the first command has to
be send twice; the first time to switch to 4-bits mode, (the lower 4 bits of the command
are not seen), the second time to send it as two nibbles so the lower part is received, too.

CLR RS
CLR RW
CLR EN
SETB EN
MOV DATA,#28h
CLR EN
LCALL WAIT_LCD
MOV A,#28h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD

the first byte of the initialisation sequence. The second byte of the initialisation sequence
is the instruction 0Eh. Thus we must repeat the initialisation code from above, but now
with the instruction. the next code segment is:

MOV A,#0Eh
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD

command of 0Eh is really the instruction 08h plus 04h to turn the LCD on. To that an
additional 02h is added in order to turn the cursor on. The last byte we need to send is
used to configure additional operational parameters of the LCD. We must send the value
06h.

40
MOV A,#06h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD

The command 06h is really the instruction 04h plus 02h to configure the LCD such that
every time we send it a character, the cursor position automatically moves to the right.
So, in all, our initialisation code is as follows:

INIT_LCD:
CLR RS
CLR RW
CLR EN
SETB EN
MOV DATA,#28h
CLR EN
LCALL WAIT_LCD
MOV A,#28h
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#0Eh
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#06h
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
RET

Having executed this code the LCD will be fully initialised and ready for us to send
display data to it.
CLEARING THE DISPLAY

CLEAR_LCD:
CLR RS

41
MOV A,#01h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD
RET

WRITING TEXT TO THE LCD

WRITE_TEXT:
SETB RS

LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
RET

THE "HELLO METRO" PROGRAM

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'

42
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' M'
LCALL WRITE_TEXT
MOV A,#'E
LCALL WRITE_TEXT
MOV A,#T'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
The above "Hello METRO" program should, when executed, initialise the LCD, clear the
LCD screen, and display "Hello World" in the upper left-hand corner of the display. As
you see, no difference in this routine with the 8bit drive routines.

CURSOR POSITIONING
Let's again, write the word 'world' on the second line now, from the tenth position:

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'

43
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
CLR RS
MOV A,#0C9h
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#M'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'T'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT

4.8STEPPER MOTOR
Motion Control, in electronic terms, means to accurately control the movement of an
object based on either speed, distance, load, inertia or a combination of all these factors.
There are numerous types of motion control systems, including; Stepper Motor, Linear
Step Motor, DC Brush, Brushless, Servo, Brushless Servo and more.
A stepper motor is an electromechanical device which converts electrical pulses into
discrete mechanical movements. Stepper motor is a form of ac. motor .The shaft or
spindle of a stepper motor rotates in discrete step increments when electrical command
pulses are applied to it in the proper sequence. The motors rotation has several direct
relationships to these applied input pulses. The sequence of the applied pulses is directly
related to the direction of motor shafts rotation. The speed of the motor shafts rotation is

44
directly related to the frequency of the input pulses and the length of rotation is directly
related to the number of input pulses applied [39].
For every input pulse, the motor shaft turns through a specified number of degrees, called
a step. Its working principle is one step rotation for one input pulse. The range of step
size may vary from 0.72 degree to 90 degree. In position control application, if the
number of input pulses sent to the motor is known, the actual position of the driven job
can be obtained. A stepper motor differs from a conventional motor (CM) as under:
Input to SM is in the form of electric pulses whereas input to a CM is invariably from a
constant voltage source. A CM has a free running shaft whereas shaft of SM moves
through angular steps.
In control system applications, no feedback loop is required when SM is used but a
feedback loop is required when CM is used. A SM is a digital electromechanical device
whereas a CM is an analog electromechanical device [40].

4.8.1 Open Loop Operation:-


One of the most significant advantages of a stepper motor is its ability to be accurately
controlled in an open loop system. Open loop control means no feedback information
about position is needed. This type of control eliminates the need for expensive sensing
and feedback devices such as optical encoders. Control position is known simply by
keeping track of the input step pulses
Every stepper motor has a permanent magnet rotor (shaft) surrounded by a stator. The
most common stepper motor has four stator windings that are paired with a center-tapped
common. This type of stepper motor is commonly referred to as a four- phase stepper
motor. The center tap allows a change of current direction in each of two coils when a
winding is grounded, thereby resulting in a polarity change of the stator. Notice that

45
while a conventional motor shaft runs freely, the stepper motor shaft moves in a fixed
repeatable increment which allows one to move it to a precise position. This repeatable

FIGno:-17 ( Rotor Alignmen)

fixed movement is possible as a result of basic magnetic theory where poles of the Same
polarity repel and opposite poles attract. The direction of the rotation is dictated by the
stator poles. The stator poles are determined by the current sent through the wire coils. As
the direction of the current is changed, the polarity is also changed causing the reverse
motion of the rotor. The stepper motor used here has a total of 5 leads: 4 leads
representing the four stator windings and 1 common for the center tapped leads. As the
sequence of power is applied to each stator winding, the rotor will rotate. There are
several widely used sequences where each has a different degree of precision. Table
shows the normal 4-step sequence. For clockwise go for step 1 to 4 & for counter
clockwise go for step 4 to 1.

46
W i n d i n g A1
2
3
W i n d i n g B

4
5
6
W i n d i n g W Ci n d i n g D

Stator Windings Configuration Fig no:-18

Step Winding A Winding B Winding C Winding D


1 0 1 1 1
2 1 0 1 1
3 1 1 0 1
4 1 1 1 0

Input Sequence to the Windings

Since the stepper motor is not an ordinary motor and has four separate coils which have to
be energised one by one in a stepwise fashion . We term them as coil A,B,C and D . At a
particular instant the coil a should get supply and then after some delay the coil B should
get a supply and then coil C and then coil D and so on the cycle continues. The more the
delay is introduced between the energisation of the coils the lesser is the speed of the
stepper motor and vice versa .
For such a complex requirement of alternate supplies to the coil of stepper motor we need
a special unit which will perform this operation . Here we are using a PC to perform this
function . How we perform it is explained below:
At the printer port we have 25 pins and out of these 25 pins pin number 2 to 9 are the
output pins which can be used to control any hardware circuit .The pin number 10,12,13
and 15 are input pins which can be used get any input signal from an external

47
hardware.The pin numbers 18to 25 are the ground pins . Since the stepper motor has five
wires ; four out of them corresponding to four coils and one is ground reference , we
will be using four output pins(2,3,4, and 5) of the printer port and any pin out of 18 to 25
for the stepper motor.
What we have done is that we connected each of the output pin of the printer port to the
pin number 1 of a different I.C. (817) known as the optocoupler. It is a four pin I.C. .Its
pin number 2 is connected to the ground reference form the printer port.
Internally at pin number 1 of the optocoupler the p- portion of an LED is connected and
its n- side is connected to the pin number 2 . Now when we want to provide supply to the
coil A of the stepper motor , we activate the pin number 2 of the printer port . This will
make the LED inside the
optocoupler(connected to pin number 2) to glow and its light falls on the base of a
phototransistor which is also mounted inside the optocoupler with its emitter at pin
number 3 and the collectorat its pin number 4 . The falling of light ensures that the base
of the phototransistor starts conducting and the emitter and the collector are virtually
short circuited . We have connected +9 V supply to the emitter of the phototransisitor
which is now being forwarded to the collector . But the output current of the
phototransistor is very low to energise the coil of the stepper motor .
So we feed the output of the stepper motor to a current amplyfying transistor (369) at its
base and its emitter is connected to positive supply . Now the current output will be
sufficient to energise the coil . This output is now fed to the coil A of the stepper motor .
Now after a certain delay we activate the pin number 3 of the printer port . This will
make the LED inside the optocoupler , to which pin number 3 is connected , to glow and
accordingly the amplified output will fed to coil B for its energisation .This process
continues for all the four coils and after that we can say that the motor has taken a step .
If we continue this cycle the motor keeps on rotating.
As we know that the stepper motor comprises of four coils A,B,C, and D . These coils
must be given the supply in the form of steps i.e. firstly coil a should get the supply , then
after a delay coil B gets a supply , then coil C and then coil D.The more delay you
introduce between the passing on of supply from one coil to another the speed of the
motor will be that much slow.

48
Now at the printer port of the computer we have 25 pins and out of them pin number 2 to
9 are output pins which can supply an input to an external hardware , which in yours case
is a stepper motor . As we need to pass on stepwise input only to four coils we will be
using just pin numbers 2,3,4 and 5 of the printer port

5. PROGRAME OF MICRO CONTROLLER


#include<reg51.h> **MC interface with LCD
#define data P3
sbit RS=P0^5;
sbit RW=P0^6;
sbit E =P0^7;
#include<lcd51.h> **LCD Interface with MC &line drive motor
sbit m1=P1^0;
sbit m2=P1^1;
sbit m3=P1^2;
sbit m4=P1^3;
#include<stepper_door.h> ** MC Interface the Stepper motor& buzzer
sbit sensor=P2^0;

49
sbit buzz=P0^4;
void Train_start()
{
m1=0;m3=0;
m2=1;m4=1;
}
void Train_stop()
{
m1=1;m2=1;
m3=1;m4=1;
}
void check()
{
secdelay(1); Programing to check the obstacle
check_obstacle();
secdelay(1);
check_obstacle();
secdelay(1);
check_obstacle();
secdelay(1);
check_obstacle();
secdelay(1);
check_obstacle();
secdelay(1);
check_obstacle();
secdelay(1);
check_obstacle();
secdelay(1);
check_obstacle();
}
void main()

50
{
lcd_initialize(); *** To show the lcd display programming
printstring("Welcome To");
lcd_cmd(0xc0);
printstring("Metro Train");
whistle();
secdelay(4);
clrscr();
lcd_cmd(0x80);
printstring(" Developed By ")
secdelay(2);
clrscr();
lcd_cmd(0x80);
printstring("Malkeet,Jswinder");
lcd_cmd(0xc0);
printstring("Lovepreet singh");
secdelay(5);
clrscr();
while(1)
lcd_cmd(0xc0);
printstring("Welcome To Metro ");
whistle();
Train_start();
check();
lcd_cmd(0x80); *** Show the station of lcd display
printstring("Amritsar");
Train_stop();
secdelay(2);
door();
secdelay(2);
whistle();

51
Train_start();
check();
lcd_cmd(0x80);
printstring("Mohal");
Train_stop();
secdelay(2);
door();
secdelay(2);
whistle();
Train_start();
check();
lcd_cmd(0x80);
printstring("Chandigar ");
Train_stop();
secdelay(2);
door();
secdelay(2);
whistle();
Train_start();
check();
lcd_cmd(0x80);
printstring("Zirakpur");
Train_stop();
secdelay(2);
door();
secdelay(2);
whistle();
Train_start();
check();
lcd_cmd(0x80);
printstring ("Derabassi");

52
lcd_cmd(0xc0);
printstring(" Train stop ");
Train_stop();
secdelay(2);
door();
secdelay(2);
whistle();
}
}

6.APPLICATIONS

• Can be used as an obstacle detector and avoider systems.

• Can be used to avoid collision in case of robotic cars/self guided robots.

• Can be used to find distance and perform automated lane or track shifts.

6.1 ADVANTAGES
1. Very fast
2. Time saving

53
3. Save petrol & fuel
4. To avoid the accident problem

7. REFERENCES

1) http://www.embeded.com
2) www.electroicsforu.com
3) www.atmel.com
4) http://www.wikipedia.com
5) The 8501 microcontroller and Embedded system- Ali Mazidi

54
55
8.DATA SHEET

56
57
58
59
60
61
62
63
64
65
66
67
68

You might also like