Sunteți pe pagina 1din 71

E-Automation For Trains

E-AUTOMATION FOR TRAINS

1.1 INTRODUCTION

There are many railway crossings which are unmanned due to lack of man
power needed to fulfill the demands. Hence many accidents occur at such crossings
since there is no one to take care of the functioning of the railway gate when a train
approaches the crossing. This project is a step towards improving the status of such
unmanned railway crossings. Here, the railway gate is closed automatically as train
approaches the crossing and automatically the gate is opened after the train has
crossed. Here the magnetic switches have been utilized to sense the train approach
and departure.
This project is designed using Microcontroller IC 8051,the program is written
and stored in the ROM of the 8051.when the Microcontroller is powered up, the
controller starts working as per the program stored in the IC. To sense the train and to
control the gates, the ports of Microcontroller are utilized. The main advantage of
using Microcontroller, the size of the circuit is minimized to greater extent, consumes
less power, reliable and has high accuracy in its operation.

The two magnetic sensors are placed 1/4th KM away from the railway gate
crossing on either side of the gate .When the train approaches and passes on the
magnetic sensor the gate buzzer produces sound for few seconds , which indicates to
the motor vehicles that gate is about to close and no one should cross the gate.
Similarly once the Train passes on the other sensor kept at other side of the gates will
be opened. The distance of placing sensors can be adjusted. This project is facilitated
with multi options such as anti collision system for trains and it sends indication to the
driver in the train as soon as the track is cut or removed.
The technical aspects of Microcontroller are discussed in detail in the forth
coming chapters.

1
E-Automation For Trains

1.2 BLOCK DIAGRAM OF UNMANNED RAILWAY GATE CONTROL

Fig1.1:Block diagram of microcontroller based unmanned railway gate controlling


system

Fig1.2:showing railway gate coupled to motors

2
E-Automation For Trains

1.3 BLOCK DIAGRAM OF TRACK CUT

Fig1.3: Block diagram of Track cut

1.4 BLOCK DIAGRAM OF ANTI COLLISION

IR LED
DRIVER BUZZER
IR Tx IR Rx CKT

Fig1.4: Block diagram of Anti collision

3
E-Automation For Trains

1.5 BLOCK DIAGRAM EXPLANATION OF


MICROCONTROLLER BASED UNMANNED RAILWAY
GATE CONTROL

Magnetic sensors:
When the magnet is passed on the magnetic switch, it makes the magnetic
switch gets shorted. Using this principle, we can detect the train.
The magnetic sensors are used at either side of the Railway gate in order to
detect the arrival and departure of train at the Railway gate. The sensors has to be
1/4 KM away from the Railway gate on either side, the above distance is not
mandatory, this can be adjusted as per the requirement. The two magnetic switches
are connected to the Microcontroller in order to provide triggering to the ports of
Microcontroller.
Program:
A Microcontroller program is written and stored in chip, whose function of the
program is to open and close the Railway gate on the arrival and departure of the
Train. The program is written such a way that ,before closing the gate the
Microcontroller provides the beeping sound for predetermined time indicating to the
vehicle passers that gate is going to be closed.
Microcontroller:
The program is stored in the flash ROM of Microcontroller, once the power is
made ON, the Microcontroller checks the signals from it ports to detect the train
coming. Depending on the train arrival the ports of microcontroller sends signals to
the microcontroller, the microcontroller enables the port to activate to produce sound
for say 10 seconds, then the gate will be closed. Once the train leaves the gate the gate
will be automatically closed.

Ports:
4
E-Automation For Trains

The ports can be programmed as an input port or output port .In this project
the input port is used to sense the arrival and departure of train, the output ports are
used to bias the driver circuit to produce the
sound from the Buzzer. Similarly another port is also connected to the driver IC in
order to drive the Stepper motor.

Driver Circuit for Stepper motor :


The stepper motor works for 12V DC, where as the o/P of microcontroller is
5V DC which can not drive the motor. A driver IC inputs is connected to the outputs
of Microcontroller and outputs of IC whose output voltage is 12V DC is connected to
the stepper motor.
Driver circuit:
A driver circuit comprises of Darlington amplifier or signal
transistor, which increases the DC level to a required value say (12V).
This 12V is much more enough to operate the Buzzer.

1.6 BLOCK DIAGRAM EXPLANATION OF TRACK CUT:

5
E-Automation For Trains

Track cut Sensing :


To sense the track metal conductors are connected to the tack, when ever the
track is cut the output or track cut sensing circuit becomes high and provides base bias
to the Transistor, the output of transistor is connected to the relay to make the FM Tx
ON.
FM Transmitter :
When track is cut the FM Tx transmits the signal to the space. The
frequency of FM Tx is 27MHz.
FM Rceiver :
The FM receiver is tuned to the frequency of 49MHz, the FM Rx receives the
signal from the FM transmitter demodulates it and fed to the input port of 8051.
Input Port:
The signal is received from the FM Rx and fed to the input port of
8051microcontroller, the function of input port is to receive the signal and feds to the
microcontroller. As we know by default or by reset , the Microcontroller ports acts as
a out put port ,if it is to be used as input port, it must be programmed .
Microcontroller:
The 8051 microcontroller is employed and the program is down loaded in the
ROM, the 8051 receives the signal from the input port and executes the instructions
stored in the ROM and sends the signal through the output port to make the buzzer
On and to display the track cut on the LCD screen.

1.7 BLOCK DIAGRAM EXPLANATION OF


ANTICOLLISION

6
E-Automation For Trains

Power Supply:
A centre tapped fullwave regulated power supply of 9V is
constructed for the operation of IR Tx and IR Rx circuits. In order to get
9V a regulated IC 7809 is employed.
IR Generator and Modulator circuit:
The IR Tx and receiver are placed to detect the any train coming in
opposite direction or any obstacle and the driver gets the beeping sound
and the collision can be avoided. It is an oscillator circuit comprises of
Astable multivibrator circuit constructed with the IC 555 timer. The
output, of 555 timer is a square generator, this oscillations is fed to the
Modulator circuit, whose signal is strengthened and applied to the IR
LED.
IR LED:
It converts the oscillations in to IR rays, these IR rays can not seen
by the eyes and does not affect by sun light and atmosphere.
IR Reciver:
IR receiver is one which senses the IR Rays and converts into
electrical signals.
IR Sensing circuit:
This section provides the biasing to the signal booster circuit
section to smaller value, just like preamplifier in amplifiers.
This section provides the biasing to the signal booster circuit
section to smaller value, just like preamplifier in amplifiers.
IR Signal Booster:
IR signal booster is one which increases the signal strength and fed
to the driver circuit.

Driver circuit:

7
E-Automation For Trains

A driver circuit comprises of Darlington amplifier or signal


transistor, which increases the DC level to a required value say (9V). This
9V is much more enough to operate Buzzer.

2.1 CIRCUIT DIAGRAM OF INTERFACING 8051 WITH


STEPPER MOTOR AND BUZZER

8
E-Automation For Trains

Fig2.1: Circuit of diagram of interfacing 8051 with stepper motor and Buzzer

2.2 WORKING OF CIRCUIT DIAGRAM

VCC:

Pin 40 provides supply voltage to the chip. The voltage source is +5V
9
E-Automation For Trains

GND:
Pin 20 is the ground.
XTAL1 and XTAL2
The 8051 has an on-chip oscillator but requires an external clock to run it.
Most often a quartz crystal oscillator connected to inputs 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
as shown in Circuit diagram
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.
When the Microcontroller is powered up ,the Program stored in the ROM of
Microcontroller starts executing and microcontroller functions as per the Program. In
this project the Microcontroller keeps on checking the signals arriving at the input
port, if there is no signal from it no function is taken Place. If the train is arriving near
to Railway gate say at 1/4 KM the sensor senses that the Train is arriving and gives
Sound for 10sec indicating that Train is arriving and all the Vehicles should stop
passing across the Railway gate ,then the gates are closed automatically, similarly
once the Train leaves the gate the gates are opened automatically. The same process is
repeated for all the Trains.

2.3 CIRCUIT DIAGRAM OF TRACK CUT

10
E-Automation For Trains

Fig2.2: Circuit diagram of Track cut

IC = CD 4011
Q1 = BC 548 (NPN)
R1 = 3.3 KΩ
R2 = 1 KΩ
D1= IN 4007
Relay = 9V, SPDT

2.4 WORKING OF TRACK CUT SENSING CIRCUIT

11
E-Automation For Trains

When the two tracks are connected to tracks, the inputs of U1A become LOW
and the o/p of NAND gate1 becomes high. The o/p of NAND gate1 is connected to
the to the i/p of the NAND gate of U1B, Now the i/p of NAND gates U1B becomes
High and the o/p of NAND gate U1B becomes LOW, the transistor Q1 does not
conduct and the buzzer is OFF.
Similarly, when the track is cut the inputs of UA1 becomes HIGH and the o/p
of NAND gate becomes LOW. The o/p of NAND gate is connected to the to the i/p
of the NAND gate U1B, Now the i/p of NAND gates U1B becomes LOW and the o/p
of NAND gate U1B becomes HIGH, the transistor Q1 conducts and the buzzer is off.

2.5 CIRCUIT DIAGRAM OF FM TRANSMITTER

Fig2.3: Circuit diagram of FM Transmitter

2.6 CIRCUIT DIAGRAM OF FM RECEIVER

12
E-Automation For Trains

Fig2.4: circuit diagram of FM Receiver

2.7 CIRCUIT OPERATION OF FM TRANSMITTER AND


RECEIVER

13
E-Automation For Trains

The IC Tx-2 ,is an low frequency generator, when the switch s1 is connected
to the relay of metal sensor of track cut the FM Tx becomes automatically ON AND
transmits the signal. In FM Tx IC in built oscillator in IC generates frequency at pin
no.9, the pin no.9 is fed to the base of the transistor Q1,the Q1 starts conducting as per
the input signal coming from the pin no9.due to conduction of transistor, the capacitor
starts charging and discharging through the inductor, so the oscillations are generated
at collector of Q1 ,the o/p of Q1 is fed to the is fed to the base of Q2,now the
transistor Q2 starts conducting as per the oscillations, due to change in base current,
the collector current varies and therefore the crystal generates high frequency, the
high frequency is fed the antenna, the antenna converts electrical signal into
electromagnetic signals and transmits into space.
The FM receiver is tuned to receive the frequency of about 49 MHz with the
help of the capacitor C2 and the inductance L1 shown in the circuit diagram. The
signal from the antenna is fed to the base of the Transistor which conducts as per the
input signal, simultaneously the charging and discharging of the capacitor takes place
and this signal frequency is demodulated with the of receiver IC i.e. low frequency
signal is passed to the transistor T2 which amplifies the signal, the function of T3 is
also same as T2, this transistor increases the signal ,the amplified signal operates the
relay. The output of FM Rx is connected to the 8051in order to display the opposite
information

2.8 CIRCUIT DIAGRAM OF INTERFACING 8051 WITH


LCD

14
E-Automation For Trains

Fig2.5: Circuit diagram of Interfacing 8051 with LCD

2.9 WORKING OF CIRCUIT DIAGRAM OF 8051

VCC

15
E-Automation For Trains

Pin 40 provides supply voltage to the chip. The voltage source is


+5V
GND
Pin 20 is the ground.
XTAL1 and XTAL2
The 8051 has an on-chip oscillator but requires an external clock to
run it. Most often a quartz crystal oscillator connected to inputs
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 as shown in
Circuit diagram
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.
When the Microcontroller is powered up ,the Program stored in the
ROM of Microcontroller starts executing and microcontroller functions as
per the Program In this project the Microcontroller keeps on checking the
signals arriving at the input port, if there is no signal from it no function
is taken Place .Depending on the signal coming to the input port the
program in the ROM of 8051 will be executed and the particular operation
takes place i.e and sends the message that the vehicle has got the accident

2.10 CIRCUIT DIAGRAM OF IR TRANSMITTER

16
E-Automation For Trains

Fig2.6: Circuit diagram of IR Transmitter

2.11 CIRCUIT DIAGRAM OF IR RECEIVER

17
E-Automation For Trains

Fig2.7: Circuit diagram of IR Recriver

2.12 WORKING OF IR TRANSMITTER & RECEIVER

18
E-Automation For Trains

The advantages of using IR circuits is, these circuits are unaffected by sunlight
and other artificial lights, range of the this circuit is about 5 meters with out any
lenses. Range can be extended further by using lenses or reflectors with sensors.

WORKING OF IR-TRANSMITTER CIRCUIT:


Transmitter module is based on timer IC.555. It is wired as astable
multivibrator. As we the output of astable multivibrator is an square wave, whose
frequency is given by the formula
f = 1.44/(R1+2R2)C

The frequency of astable multivibrator is nearly 1kHz. The output of astable


multivibrator is a square wave which is fed to the base of the PNP transistor, to
increase the signal strength in order to drive the IR LEDs.

WORKING OF IR-RECEIVER CIRCUIT:


When I.R. Photo diode receives I.R. signals from transmitter, tone signal
amplifier amplifies 1KHz signals. The amplified signals are given to the base of
transistor T4. During negative half cycles of tone signals, T4 conducts. Then
transistor T5 gets base bias. Then it also conducts and the voltage at collector
terminal of T5 becomes 0V. So the transistor T6 will not have base bias, therefore
transistor T6 does not conduct. So the output across diode D5 will be 0V, and buzzer
does not produce any sound.
But when the I.R. beam between transmitter and receiver is interrupted ,
transistors T4 and T5 stop conduction. The voltage at collector terminal of T5 will be
high, therefore the transistor T6 gets base bias and conducts (goes to saturation
region).
The voltage across diode D5 will be 9V and the buzzer produces audio tone.

3.1 CIRCUIT DIAGRAM OF DUAL POWER SUPPLY

19
E-Automation For Trains

Fig3.1: Circuit diagram of Dual Power supply

T1 = Step down Transformer 12-0-12, i=750mA


D1=D2= IN4007
C1= 25V, 1000µF
C2=C3=C4= 104
IC’s = 7809, 7806, 7805

3.2 WORKING OF DUAL POWER SUPPLY


In every project we need different voltages for different circuits.
Some need to construct different power supply of different voltages
employing different voltage transformers, rectifier circuits, filter circuits
and regulator circuits. This type of construction requires many
components (transformers, capacitors regulators.......etc).So the size of the
power supply becomes bulky and costly. To overcome above
disadvantages by using regulator IC’S the different voltages
(12V, 9V, 5V.....etc) can be obtained with only one transformer.
The circuit diagram of Dual power supply is shown in the figure.

The function of each component of the circuit is explained below. The


circuit consists of following stages.
1. Transformer

20
E-Automation For Trains

2. Rectifier
3. Filter and
4. Regulator
TRANSFORMER
It is an electrical device which transfers the power from one
winding to the other winding with isolation. All the electronic gadgets
works for less voltage (normally 3V to 12V).So an step down transformer
is used, whose function is to step down the AC voltage from 230V to
required voltage depending on the need. In this project 12V-0-12V is used.
RECTIFIER CIRCUIT
It employs diodes, which converts AC voltage into DC voltage. The
output of rectifier circuit is not a pure DC. It also consists of some AC
components, which is called ripples. In order to remove these AC
components, filter circuits are employed. So the output of rectifier circuit
is fed to the filter circuit (capacitor).
FILTER CIRCUIT
Filter circuit employee’s electrolytic capacitors in-order to remove
the AC components. As we know the capacitor does not allow DC
components to pass through it because it offers high reactance to the DC
component .And offers less reactance to the AC component so all AC
components will be bypasses through the capacitors to ground.
REGULATOR
Regulator is an electronic circuit whose function is to keep output
always constant though the input is varied. In this project the three
terminal IC regulators of 7809 & 7805 is used for providing output DC
voltages. Eg 7809, the number 78 represents the positive regulator IC and
09 represents the output voltage i.e output is 9V

4.1 PIN DIAGRAM OF 89S51

21
E-Automation For Trains

Fig4.1: Pin diagram of 89S51

Although 8051 family members (e.g., 8751, DS5000) come in


different packages, such as DIP (dual in-line package), QFP (quad flat
package), and LLC (leadless chip carrier), they all have 40 pins that are
dedicated for various functions such as I/O, RD, WR, address, data, and
interrupts.

It must be noted that some companies provide a 20-pin version of


the 8051 with a reduced number of I/O ports for less demanding

22
E-Automation For Trains

applications. However, since the vast majority of developers use the 40-
pin DIP package chip, we will concentrate on that.
Examining Figure 5.1, note that of the 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 V CC , GND, XTAL1, XTAL2,

ALE/PROG, RST, EA, PSEN. Of these 8 pins, six of them (V CC , GND,

XTAL1, XTAL2, RST, and EA) 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 8051 family.
The other two pins, PSEN and ALE, are used mainly in 8031-based
systems. We first describe the function of each pin. Ports are discussed
separately.

4.2 PIN DESCRIPTION OF 89S51


V CC

Pin 40 provides supply voltage to the chip. The voltage


source is +5V.
GND
Pin 20 is the ground.
XTAL1 and XTAL2
The 8051 has an on-chip oscillator but requires an external
clock to run it. Most often a quartz crystal oscillator connected to
inputs 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 as shown in Figure 4.2 (a).

23
E-Automation For Trains

Fig4.2(a): XTAL connection to Fig4.2(b): Connection to an


8051 external clock source

It must be noted that there are various speeds of the 8051


family. Speeds refer to the maximum oscillator frequency
connected to 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 8051 is
connected to a crystal oscillator and is powered up, we can observe
the frequency on the XTAL2 pin using the oscilloscope.
If you decide to use a frequency source other than a crystal
oscillator, such as a TTL oscillator, it will be connected to XTAL1;
XTAL2 is left unconnected, as shown in Figure 5-2 (b).
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.

24
E-Automation For Trains

Fig4.3(a): Power-ON RESET Fig4.3(b): Power-ON RESET


circuit With Debounce

RESET Value of Some 8051 Register


Register Reset Value
PC 0000
ACC 0000

B 0000

PSW 0000

SP 0007

DPTR 0000

Tabel 4.1: RESET Value of Some 8051 Registers


Table 5.1 provides a partial list of 8051 registers and their
values after power-on reset.

Notice that the value of the PC (program counter) is 0 upon


reset, forcing the CPU to fetch the first opcode from ROM memory

25
E-Automation For Trains

location 0000. This means that we must place the first line of
source code in ROM location 0 because that is where the CPU
wakes up and expects to find the first instruction. Figure 4-3 shows
two ways of connecting the RST pin to the power-on reset circuitry.
In order for the 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
The 8051 family members, such as the 8751, 89C51, or
DS5000, all come with on-chip ROM to store programs. In such
cases, the EA pin is connected to V CC . For family members such

as the 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 GND to
indicate that the code is stored externally. EA, which stands for
“external access,” is pin number 31 in the DIP packages. It is an
input pin and must be connected to either V CC or GND. In other

words, it cannot be left unconnected.


In Chapter 14, we will show how the 8031 uses this pin along
with PSEN to access programs stored in ROM memory located
outside the 8031. In 8051 chips with on-chip ROM, such as the
8751, 89C51, EA is connected to V CC .

The pins discussed so far must be connected no matter which


family member is used. The next two pins are used mainly in 8031-
based systems. The following is a brief description of each.
PSEN
This is an output pin. PSEN stands for “program store
enable”. In an 8031-based system in which an external ROM holds
the program code, this pin is connected to the OE pin of the ROM.

26
E-Automation For Trains

ALE
ALE (address latch enable) is an output pin and is active
high. When connecting an 8031 to external memory, port 0
provides both address and data. In other words, the 8031
multiplexes address and data through port 0 to save pins. The ALE
pin is used for demultiplexing 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-bit ports. All the ports upon RESET are configured as
output, ready to be used as output ports. To use any of these ports
as an input port, it must be programmed, as we will explain
throughout this section. First, we describe each port.
Port 0
Port 0 occupies a total of 8 pins (pins 32-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 the fact that P0 is an open drain,
unlike P1, P2, and P3, as we will soon see. In any system using the
8751, 89C51, or DS5000 chips, we normally connect P0 to pull-up
resistors. See Figure 4-4. In this way we take advantage of port 0
for both input and output. With external pull-up resistors connected
upon reset, port 0 is configured as an output port. For example, the
following code will continuously send out to port 0 the alternating
values 55H and AAH.
MOV A, # 55H
BACK: MOV P0, A
ACALL DELAY
CPL A
SJMP BACK

27
E-Automation For Trains

Fig4.4: I/P and O/P Ports

Port 0 as input
With resistors connected to port 0, in order to make it an
input, the port must be programmed by writing 1 to all the bits. In
the following code, port 0 is configured first as an input port by
writing 1s to it, and then data is received from that port and sent to
P1.
MOV A, # OFFH ; A = FF hex
MOV P0, A ; make P0 an input port
; by writing all 1s to it
BACK : MOV A, P0 ; get data from P0
MOV P1, A ; send it to port 1
SJMP BACK ; keep doing it

Dual role of port 0


As shown in Figure 4-1, port 0 is also designated as AD0-
AD7, allowing it to be used for both address and data. When
connecting an 8051/31 to an external memory, port 0 provides both
address and data. The 8051 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 demuliplexing address and data
with the help of a 74LS373 latch

28
E-Automation For Trains

Port 1
Port 1 occupies a total of 8 pins (pins 1 through 8). It can be
used as input or output. In contrast to port 0, this port does not
need any pull-up resistors since it already has pull-up resistors
internally. Upon reset, port 1 is configured as an output port. For
example, the following code will continuously send out to port 1 the
alternating values 55H and AAH.
MOV A, # 55H
BACK : MOV P1, A
ACALL DELAY
CPL A
SJMP BACK
Port 1 as input
To make port 1 an input port, it must programmed as such by
writing 1 to all its bits. In the following code, port 1 is configured
first as an input port by writing 1s to it, then data is received from
that port and saved in R7, R6, and R5.
MOV A, # 0FFH ; A=FF hex
MOV P1, A ; make P1 an input port
; by writing all 1s to it
MOV A, P1 ; get data from P1
MOV R7, A ; save it in reg R7
ACALL DEALY ; wait
MOV A, P1 ; get another data from P1
MOV R6, A ; save it in reg R6
ACALL DELAY ; wait
MOV A, P1 ; get another data from p1
MOV R5, A ; save it in reg R5

29
E-Automation For Trains

Port 2
Port 2 occupies a total of 8 pins (pins 21 through 28). It can be
used as input or output. Just like P1, port 2 does not need any pull-up
resistors since it already has pull-up resistors internally. Upon reset, port
2 is configured as an output port. For example, the following code will
send out continuously to port 2 the alternating values 55H and AAH. That
is, all the bits of P2 toggle continuously.
MOV A, # 55H
BACK : MOV P2, A
ACALL DELAY
CPL A
SJMP BACK

Port 2 as input
To make port 2 an input, it must programmed as such by
writing 1 to all its bits. In the following code, port 2 is configured
first as an input port by writing 1s to it. Then data is received from
that port and is sent to P1 continuously.
MOV A, # 0FFH ; A=FF hex
MOV P2, A ; make P2 an input port by
; writing all 1s to it
BACK : MOV A, P2 ; get data from P2
MOV P1, A ; send it to Port 1
SJMP BACK ; keep doing that

Dual role of port 2


In systems based on the 8751, 89C51, and DS5000, P2 in
used as simple I/O. However, in 8031-based systems, port 2 must
be used along with P0 to provide the 16-bit address for the external
memory.

30
E-Automation For Trains

As shown in Figure 5.4, Port 2 is also designated as A8-A15,


indicating its dual function. Since an 8031 is capable of accessing
64K bytes of external memory, it needs a path for the 16 bits of the
address.
While P0 provides the lower 8 bits via A0-A7, it is the job of
P2 to provide bits A8-A15 of the address. In other words, when the
8031 is connected to external memory, P2 is used for the upper 8
bits of the 16-bit address, and it cannot be used for I/O.
From the discussion so far, we conclude that in systems based
on8751, 89C51, or DS5000 microcontrollers, we have three ports,
P0, P1, and P2, for I/O operations. This should be enough for most
microcontroller. That leaves port 3 interrupts as well as other
signals, as we will see next.
Port 3
Port 3 occupies a total of 8 pins, pins 10 through 17. It can
be used 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 an
output port upon reset, this is not the way it is most commonly
used. Port 3 has the additional function of providing some
extermely important signals such as interrupts. Table 4-2 provides
these alternate functions of P3. This information applies to both
8051 and 8031 chips.
P3.0 and P3.1 are used for the RxD and TxD serial
communications signals. Bits P3.2 and P3.3 are set aside for
external interrupts. Bits P3.4 and P3.5 are used for timers 0 and 1.
Finally, P3.6 and P3.7 are used to provide the WR and RD signals
of external memories connected in 8031-based systems. In systems
based on the 8751, 89C51, or DS5000, pins 3.6 and 3.7 are used for
I/O while the rest of the pins in Port 3 are normally used in the
alternate function role.

31
E-Automation For Trains

5.1 INTRODUCTION OF 555 TIMER


The 8-pin 555 timer must be one of the most useful ICs ever made and it is
used in many projects. With just a few external components it can be used to build
many circuits, not all of them involve timing!
A popular version is the NE555 and this is suitable in most cases where a '555 timer'
is specified. The 556 is a dual version of the 555 housed in a 14-pin package, the two
timers (A and B) share the same power supply pins. The circuit diagrams on this page
show a 555, but they could all be adapted to use one half of a 556.

Fig5.1(a): 555 Timer circuit symbol Fig5.1(b): Actual Pin Arrangements

Low power versions of the 555 are made, such as the ICM7555, but these should only
be used when specified (to increase battery life) because their maximum output
current of about 20mA (with a 9V supply) is too low for many standard 555 circuits.
The ICM7555 has the same pin arrangement as a standard 555.
32
E-Automation For Trains

The circuit symbol for a 555 (and 556) is a box with the pins arranged to suit the
circuit diagram: for example 555 pin 8 at the top for the +Vs supply, 555 pin 3 output
on the right. Usually just the pin numbers are used and they are not labelled with their
function.
The 555 and 556 can be used with a supply voltage (Vs) in the range 4.5 to 15V (18V
absolute maximum).
Standard 555 and 556 ICs create a significant 'glitch' on the supply when their output
changes state. This is rarely a problem in simple circuits with no other ICs, but in
more complex circuits a smoothing capacitor (eg 100µF) should be connected across
the +Vs and 0V supply near the 555 or 556.
The input and output pin functions are described briefly below and there are fuller
explanations covering the various circuits:
• Astable - producing a square wave
• Monostable - producing a single pulse when triggered
• Bistable - a simple memory which can be set and reset
• Buffer - an inverting buffer (Schmitt trigger)

THE 555 TIMER CONSISTS OF TWO COMPONENTS:

1. The upper comparator “A ” is a non-inverting op-amp comparator having two


1
inputs threshold and control. In most applications, the control input (pin no 5)
is not used, so that the control voltage equals + 2vcc/3, which serves as a

reference voltage. Whenever the threshold voltage exceeds the control


voltage, comparator “A1” output changes to high, which sets the flip-flop.

2. The lower comparator “A ” is an inverting op-amp comparator, to which the


2
trigger (pin 2) is applied to the inverting terminal. The non-inverting input of
lower comparator “A2”is at a fixed voltage of +vcc/3. When the trigger input

is slightly less than +vcc/3, the comparator “A2” output changes to high and

the flip-flop is thus reset.

33
E-Automation For Trains

The reference voltage for the two comparators is obtained from an internal
voltage divider consisting of three equal resistors R of 5Kohm each. The
threshold comparator A1 is referenced at +2/3 Vcc and the trigger comparator A2

is referenced at +1/3Vcc.. The output of threshold and the trigger comparator are

connected to S and R inputs of flip-flop respectively.

5.2 THE PINS USED IN 555 IC ARE AS FOLLOWS:

Fig5.2: IC 555 Timer

GENERAL CHARACTERISTICS:

SUPPLY VOLTAGE : 4.5V-15V max

OPERATING TEMPERATURE : 00C-+700C

POWER DISSIPATION : 60mv max


TYPICAL ACCURACY : + 0.5% 100 usec + 2% mints
OUTPUT CURRENT : 200mA Max
PACKAGE : 14 Pin Dip Plastic Packag

1. PIN 1 (Ground)

34
E-Automation For Trains

2. PIN 2 (Trigger): An external trigger plus is applied to this pin. The output of the
timer depends on the amplitude of the trigger pulse. If the trigger voltage is less than
+1/3Vcc,the timer output is high.

3. PIN 3 (output): The output of timer is taken from Q output of SR flip-flop. A load
is connected to this terminal in two ways.
i) The load can be connected between pin 3 and pin 1 (ground). The current
through the ground load is zero, when the output is zero. This is called as normally
off load.
ii) The load can be connected between pin 3 and pin-8 (supply voltage +v cc)

and the load is called as ‘normally on’. When the output is low, the load current
flows through the load into the output terminal and it is called ‘sink current’. On the
other hand, when the output is high, the current through the load is zero.
However, when the output is high, the output terminal supplies current to the
normally off load. This current is called the ‘source current’.

4. PIN 4 (Reset): The 555 timer can be reset by applying a negative pulse to this pin.
When the reset function is not used, it will be connected to +Vcc..

5. PIN 5 (Control): An external dc voltage may be applied to this pin to change the
threshold and trigger voltage level. By varying the control voltage, it is possible to
vary the pulse width of the timer output. If no external dc voltage is used, the control
pin is at +2/3 Vcc and this pin is bypassed to the ground to eliminate the noise.

6. PIN 6 (Threshold): It is the non-inverting input terminal of comparator A 1. The

threshold voltage (the reference voltage of comparator A1) is +2/3 Vcc.When the

voltage at threshold pin is above +2/3 Vcc. When the voltage at threshold pin is

above +2/3 Vcc,the output of comparator A1 goes high, which changes the timer

output to low.

35
E-Automation For Trains

7. PIN 7 (Discharge): This pin is connected internally to the collector of discharge


transistor Q. When the timer output is high, Q is cut-off. When the timer output is
low,Q is saturated.

8. PIN 8 (Vcc): A supply voltage of +5v to +18v is applied to this pin w.r.t. ground

(pin 1).

6.1 POWER SUPPLY SECTION

Transformer 12V-0-12V
Diodes D1, D2=IN 4001
Capacitors C1=1000uf, C2, C3, C4=0.1uf,
IC Regulator IC’s 7809 and & 7805

6.2 MICROCONTROLLER CIRCUIT COMPONENTS

IC1=8051
IC2, IC3=ULN 2803
C1=10uf,C2, C3=33pf
R1=10k ohms R2=1k ohms
LCD
Crystal oscillator 11.0592 MHz
Connectors

6.3 LINE CUT SENSING CIRCUIT COMPONENTS

IC = CD 4011
Q1 = BC 548 (NPN)
R1 = 3.3 KΩ
R2 = 1 KΩ
D1= IN 4007
36
E-Automation For Trains

Relay = 9V

6.4 FM TRANSMITTER COMPONENTS


Semiconductors
Q1-2N 5109 NPN VHF transistor
Resistor:
R1-10k
R2-4.7k
R3-18k
R4-22 ohms
Capacitors:
C1-2.2mf
C2-1mf
C3, C5-100PF
C6-0.01mf
VC1-22pf button trimmer

6.5 FM RECEIVER COMPONENTS

Resistors:
R1-2.7K, R2-33K, R3-100K, R4-22K, R5-22K, R6-1.5K, R7-1.5K,
R8-2.7K, R9-1M, R10-10K, R11-2.7K, R12-1.5K, R13-4.7K,
Capacitors:
C1-100pf, C2-Trimmer, C3-100pf, C4-0.1 f, C5-0.02 f, C6-0.01 f,
C7-0.002f, C8-0.02f, C10-0.02f.
Inductors:
L1=10mH, L2=output transformer
37
E-Automation For Trains

Transistors:
T1=BF 194, T2=BC 558, T3=8050.
D1=D2=LED

6.6 IR TRANSMITTER

Resistors:
R1 = 150K
R2 = 15K
R3 = 41
R4 = 470
R5 = 4K
Capacitors:
C1 = O.1 µF
C2 = 0.1 µF
C3 = 100µF/25V
Transistors:
T1= BD 140
IR LED

6.7 IR RECIEVER

Resistors:
R1 = 1 K, R2 = 47 K, R3 = 470 K, R4 = 2.7 K, R5 = 2.2K, R6 = 1 K
R7 = 100 K, R8 = 130, R9 = 4.7 K, R10 = 4.7 K, R11= 22 K, R12 = 680
Capacitors:
C1 =104 µF, C2 = 104 µF, C3 = 10 µF
C4 = 100 µF, C5 = 100 µF

6.8 SEMICONDUCTOR DEVICES


38
E-Automation For Trains

Transistors:
T1 = BC 547, T2 = BC 547, T3 = BC 557
T4 = BC 459, T5 = BC 459

7.1 TRANSISTORS
Transistors amplify current, for example they can be used to
amplify the small output current from a logic IC so that it can operate a
lamp, relay or other high current device. In many circuits a resistor is used
to convert the changing current to a changing voltage, so the transistor is
being used to amplify voltage.

A transistor may be used as a switch (either fully on with maximum


current, or fully off with no current) and as an amplifier (always partly
on). The amount of current amplification is called the current gain,
symbol h F E
Types of transistor
There are two types of standard
transistors, NPN and PNP, with different
circuit symbols. The letters refer to the
layers of semiconductor material used to
make the transistor. Most transistors used Fig7.1: Transistor circuit symbols
today are NPN because this is the easiest type to make from silicon. If you
are new to electronics it is best to start by learning how to use NPN
transistors.
The leads are labeled base (B), collector (C) and emitter (E).
These terms refer to the internal operation of a transistor but they are not
39
E-Automation For Trains

much help in understanding how a transistor is used, so just treat them as


labels!
A Darlington pair is two transistors
connected together to give a very high
current gain.
In addition to standard (bipolar
junction) transistors, there are field-
effect transistors which are usually
referred to as FETs. Fig7.2: Transistor leads for some
Connecting common case styles.
Transistors have three leads which
must be connected the correct way round. Please take care with this
because a wrongly connected transistor may be damaged instantly when
you switch on.

structure This shows the type of transistor, NPN or PNP. The


polarities of the two types are different, so if you are
looking for a substitute it must be the same type.
Case style There is a diagram showing the leads for some of the
most common case styles in the Connecting section
above. This information is also available in
suppliers' catalogues.
I C max. Maximum collector current.
V C E max. Maximum voltage across the collector-emitter
junction.
You can ignore this rating in low voltage circuits.
hFE This is the current gain (strictly the DC current
gain). The guaranteed minimum value is given
because the actual value varies from transistor to
transistor - even for those of the same type! Note
that current gain is just a number so it has no units.
The gain is often quoted at a particular collector
current I C which is usually in the middle of the

40
E-Automation For Trains

transistor's range, for example '100@20mA' means


the gain is at least 100 at 20mA. Sometimes
minimum and maximum values are given. Since the
gain is roughly constant for various currents but it
varies from transistor to transistor this detail is only
really of interest to experts.
Why h F E ? It is one of a whole series of parameters
for transistors, each with their own symbol. There
are too many to explain here.
P t o t max. Maximum total power which can be developed in the
transistor, note that a heat sink will be required to
achieve the maximum rating. This rating is important
for transistors operating as amplifiers, the power is
roughly I C × V C E . For transistors operating as
switches the maximum collector current (I C max.) is
more important.
Category This shows the typical use for the transistor, it is a
good starting point when looking for a substitute.
Catalogues may have separate tables for different
categories.
Possible substitutes These are transistors with similar electrical
properties which will be suitable substitutes in most
circuits. However, they may have a different case
style so you will need to take care when placing
them on the circuit board.

7.2 RELAY
A relay is an electrically operated switch. Current flowing through
the coil of the relay creates a magnetic field which attracts a lever and
41
E-Automation For Trains

changes the switch contacts. The coil current can be on or off so relays
have two switch positions and most have double throw (changeover)
switch contacts as shown in the diagram.
Relays allow one circuit to switch a second circuit which can be
completely separate from the first. For example a low voltage battery
circuit can use a relay to switch a 230V AC mains circuit. There is no
electrical connection inside the relay between the two circuits, the link is
magnetic and mechanical.
The coil of a relay passes a relatively large current, typically 30mA for a
12V relay, but it can be as much as 100mA for relays designed to operate
from lower voltages. Most ICs (chips) cannot provide this current and a
transistor is usually used to amplify the small IC current to the larger
value required for the relay coil. The maximum output current for the
popular 555 timer IC is 200mA so these devices can supply relay coils
directly without amplification.
Relays are usuallly SPDT or DPDT but they can have many more sets of
switch contacts, for example relays with 4 sets of changeover contacts are
readily available. For further information about switch contacts and the
terms used to describe them please see the page on switches.
Most relays are designed for PCB mounting but you can solder wires
directly to the pins providing you take care to avoid melting the plastic
case of the relay.
The supplier's catalogue should show you the relay's connections. The coil
will be obvious and it may be connected either way round. Relay coils
produce brief high voltage 'spikes' when they are switched off and this can
destroy transistors and ICs in the circuit. To prevent damage you must
connect a protection diode across the relay coil.
The animated picture shows a working relay with its coil and switch
contacts. You can see a lever on the left being attracted by magnetism
when the coil is switched on. This lever moves the switch contacts. There
is one set of contacts (SPDT) in the foreground and another behind them,
making the relay DPDT.

42
E-Automation For Trains

Fig7.3(b): Circuit symbol for a relay

Fig7.3(a): The relay's switch


connections are usually labeled
COM, NC and NO:
COM = Common, always
connect to this; it is the moving part of the switch.
• NC = Normally Closed, COM is connected to this when the relay
coil is off.
• NO = Normally Open, COM is connected to this when the relay coil
is on.
• Connect to COM and NO if you want the switched circuit to be on
when the relay coil is on.
• Connect to COM and NC if you want the switched circuit to be on
when the relay coil is off.

7.3 CAPACITOR
Function
Capacitors store electric charge. They are used with resistors in
timing circuits because it takes time for a capacitor to fill with charge.
They are used to smooth varying DC supplies by acting as a reservoir of
charge. They are also used in filter circuits because capacitors easily pass
AC (changing) signals but they block DC (constant) signals.
Capacitance
This is a measure of a capacitor's ability to store charge. A large
capacitance means that more charge can be stored. Capacitance is
measured in farads, symbol F. However 1F is very large, so prefixes are
used to show the smaller values.
Three prefixes (multipliers) are used, µ (micro), n (nano) and p (pico):
• µ means 10 -6 (millionth), so 1000000µF = 1F
43
E-Automation For Trains

• n means 10 -9 (thousand-millionth), so 1000nF = 1µF


• p means 10 -12 (million-millionth), so 1000pF = 1nF
Capacitor values can be very difficult to find because there are many types
of capacitor with different labelling systems!
There are many types of capacitor but they can be split into two groups,
polarised and unpolarised . Each group has its own circuit symbol.
Polarised capacitors (large values, 1µF +)
Examples:

Circuit symbol:

Electrolytic Capacitors
Electrolytic capacitors are polarised and they must be connected the
correct way round, at least one of their leads will be marked + or -. They
are not damaged by heat when soldering.
There are two designs of electrolytic capacitors; axial where the leads are
attached to each end (220µF in picture) and radial where both leads are at
the same end (10µF in picture). Radial capacitors tend to be a little
smaller and they stand upright on the circuit board.
It is easy to find the value of electrolytic capacitors because they are
clearly printed with their capacitance and voltage rating. The voltage
rating can be quite low (6V for example) and it should always be checked
when selecting an electrolytic capacitor. If the project parts list does not
specify a voltage, choose a capacitor with a rating which is greater than
the project's power supply voltage. 25V is a sensible minimum for most
battery circuits.

Unpolarised capacitors (small values, up to 1µF)

44
E-Automation For Trains

Examples: Circuit symbol:

Small value capacitors are unpolarised and may be connected either way
round. They are not damaged by heat when soldering, except for one
unusual type (polystyrene). They have high voltage ratings of at least 50V,
usually 250V or so. It can be difficult to find the values of these small
capacitors because there are many types of them and several different
labelling systems!
Many small value capacitors have their value printed but
without a multiplier, so you need to use experience to work
out what the multiplier should be! For example 0.1 means
0.1µF = 100nF.
Sometimes the multiplier is used in place of the decimal
point:
For example: 4n7 means 4.7nF.

Capacitor Number Code


A number code is often used on small capacitors where printing is
difficult:
• the 1st number is the 1st digit,
• the 2nd number is the 2nd digit,

45
E-Automation For Trains

• the 3rd number is the number of zeros to give the capacitance in pF.
• Ignore any letters - they just indicate tolerance and voltage rating.
For example: 102 means 1000pF = 1nF (not 102pF!)
For example: 472J means 4700pF = 4.7nF (J means 5% tolerance).

7.4 LIGHT EMITTING DIODES (LEDS)

Example: Circuit symbol:

Function
LEDs emit light when an electric current passes through them.

Connecting and soldering


LEDs must be connected the correct way round, the
diagram may be labelled a or + for anode and k or - for
cathode (yes, it really is k, not c, for cathode!). The
cathode is the short lead and there may be a slight flat on the body of
round LEDs. If you can see inside the LED the cathode is the larger
electrode (but this is not an official identification method).
LEDs can be damaged by heat when soldering, but the risk is small unless
you are very slow. No special precautions are needed for soldering most
LEDs.

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

46
E-Automation For Trains

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

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

The colour of an LED is determined by the semiconductor material, not by


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

Calculating an LED resistor value


An LED must have a resistor connected in
series to limit the current through the LED,
otherwise it will burn out almost instantly.
The resistor value, R is given by:

R = (V S - V L ) /

47
E-Automation For Trains

I
V S = supply voltage
V L = LED voltage (usually 2V, but 4V for blue and white LEDs)
I = LED current (e.g. 10mA = 0.01A, or 20mA = 0.02A)
Make sure the LED current you choose is less than the maximum permitted
and convert the current to amps (A) so the calculation will give the
resistor value in ohms ( ).
To convert mA to A divide the current in mA by 1000 because 1mA =
0.001A.
If the calculated value is not available choose the nearest standard resistor
value which is greater, so that the current will be a little less than you
chose. In fact you may wish to choose a greater resistor value to reduce
the current (to increase battery life for example) but this will make the
LED less bright.
For example
If the supply voltage V S = 9V, and you have a red LED (V L = 2V),
requiring a current I = 20mA = 0.020A,
R = (9V - 2V) / 0.02A = 350 , so choose 390 (the nearest standard value
which is greater).

7.5 DIODES

Example:

Circuit symbol:

48
E-Automation For Trains

Function
Diodes allow electricity to flow in only one direction. The arrow of the
circuit symbol shows the direction in which the current can flow. Diodes
are the electrical version of a valve and early diodes were actually called
valves.

Forward Voltage Drop


Electricity uses up a little energy pushing its
way through the diode, rather like a person
pushing through a door with a spring.

This means that there is a small voltage


across a conducting diode, it is called the
forward voltage drop and is about 0.7V for all normal diodes which are
made from silicon. The forward voltage drop of a diode is almost constant
whatever the current passing through the diode so they have a very steep
characteristic (current-voltage graph).

Reverse Voltage
When a reverse voltage is applied a perfect diode does not conduct, but all
real diodes leak a very tiny current of a few µA or less. This can be
ignored in most circuits because it will be very much smaller than the
current flowing in the forward direction. However, all diodes have a
maximum reverse voltage (usually 50V or more) and if this is exceeded
the diode will fail and pass a large current in the reverse direction, this is
called breakdown.
Ordinary diodes can be split into two types: Signal diodes which pass
small currents of 100mA or less and Rectifier diodes which can pass large
currents. In addition there are LEDs (which have their own page) and
Zener diodes (at the bottom of this page).
49
E-Automation For Trains

Connecting and soldering


Diodes must be connected the correct way round, the
diagram may be labelled a or + for anode and k or -
for cathode (yes, it really is k, not c, for cathode!).
The cathode is marked by a line painted on the body.
Diodes are labelled with their code in small print,
you may need a magnifying glass to read this on small signal diodes!
Small signal diodes can be damaged by heat when soldering, but the risk
is small unless you are using a germanium diode (codes beginning OA...)
in which case you should use a heat sink clipped to the lead between the
joint and the diode body. A standard crocodile clip can be used as a heat
sink.
Rectifier diodes are quite robust and no special precautions are needed for
soldering them.
Testing diodes
You can use a multimeter or a simple tester (battery, resistor and LED) to
check that a diode conducts in one direction but not the other. A lamp may
be used to test a rectifier diode , but do NOT use a lamp to test a
signal diode because the large current passed by the lamp will destroy the
diode!
Signal diodes (small current)
Signal diodes are used to process information (electrical signals) in
circuits, so they are only required to pass small currents of up to 100mA.
General purpose signal diodes such as the 1N4148 are made from silicon
and have a forward voltage drop of 0.7V.
Germanium diodes such as the OA90 have a lower forward voltage drop
of 0.2V and this makes them suitable to use in radio circuits as detectors
which extract the audio signal from the weak radio signal.
For general use, where the size of the forward voltage drop is less
important, silicon diodes are better because they are less easily damaged
by heat when soldering, they have a lower resistance when conducting,
and they have very low leakage currents when a reverse voltage is applied.
50
E-Automation For Trains

Protection diodes for relays


Signal diodes are also used to
protect transistors and ICs from the
brief high voltage produced when a
relay coil is switched off. The
diagram shows how a protection
diode is connected 'backwards'
across the relay coil.
Current flowing through a relay coil creates a magnetic field which
collapses suddenly when the current is switched off. The sudden collapse
of the magnetic field induces a brief high voltage across the relay coil
which is very likely to damage transistors and ICs. The protection diode
allows the induced voltage to drive a brief current through the coil (and
diode) so the magnetic field dies away quickly rather than instantly. This
prevents the induced voltage becoming high enough to cause damage to
transistors and ICs.
Rectifier diodes (large current)
Rectifier diodes are used in power supplies to convert alternating current
(AC) to direct current (DC), a process called rectification. They are also
used elsewhere in circuits where a large current must pass through the
diode.
All rectifier diodes are made from silicon and therefore have a forward
voltage drop of 0.7V. The table shows maximum current and maximum
reverse voltage for some popular rectifier diodes.

Maximum
Maximum
Diode Reverse
Current
Voltage

1N4001 1A 50V

1N4002 1A 100V

1N4007 1A 1000V

1N5401 3A 100V
51
1N5408 3A 1000V
E-Automation For Trains

Tabel 7.1: Maximum current and reverse voltage of Diodes


The 1N4001 is suitable for most low voltage circuits with a current of less
than 1A.
7.6 RESISTORS

Example: Circuit symbol:


Function:Resistors restrict the flow of electric current, for example a
resistor is placed in series with a light-emitting diode (LED) to limit the
current passing through the LED.
Connecting and soldering
Resistors may be connected either way round. They are not damaged by
heat when soldering.

The Resistor
Colour Code
Colour Number
Black 0
Brown 1
Red 2
Orange 3
Resistor values - the resistor colour code Yellow 4
Resistance is measured in ohms, the symbol for ohm is Green 5
an omega . Blue 6
1 is quite small so resistor values are often given in k Violet 7
and M .
Grey 8
1 k = 1000 1 M = 1000000 .
White 9
Resistor values are normally shown using coloured
bands.
Each colour represents a number as shown in the table.
Most resistors have 4 bands:

52
E-Automation For Trains

• The first band gives the first digit.


• The second band gives the second digit.
• The third band indicates the number of zeros.
• The fourth band is used to shows the tolerance (precision) of the
resistor, this may be ignored for almost all circuits but further
details are given below .

This resistor has red (2), violet (7), yellow (4 zeros) and gold bands.
So its value is 270000 = 270 k .
On circuit diagrams the is usually omitted and the value is written 270K.

7.7 CRYSTAL OSCILLATORS


One of the most important features of an oscillator is its Frequency
Stability, or in other words its ability to provide a constant frequency
output under varying conditions. Some of the factors that affect the
frequency stability of an oscillator include: temperature, variations in the
load and changes in the power supply. Frequency stability of the output
signal can be improved by the proper selection of the components used for
the resonant feedback circuit including the amplifier but there is a limit to
the stability that can be obtained from normal LC and RC tank circuits.
For very high stability a quartz crystal is generally used as the frequency
determining device to produce another types of oscillator circuit known
generally as Crystal Oscillators.
When a voltage source is applied to a small thin piece of crystal quartz, it
begins to change shape producing a characteristic known as the Piezo-
electric Effect. This piezo-electric effect is the property of a crystal by
which an electrical charge produces a mechanical force by changing the
shape of the crystal and vice versa, a mechanical force applied to the
crystal produces an electrical charge. Then, piezo-electric devices can be
classed as Transducers as they convert energy of one kind into energy of
another. This piezo-electric effect produces mechanical vibrations or
53
E-Automation For Trains

oscillations which are used to replace the LC tank circuit and can be seen
in many different types of crystal substances with the most important of
these for electronic circuits being the quartz minerals because of their
greater mechanical strength.
The quartz crystal used in Crystal Oscillators is a very small, thin piece or
wafer of cut quartz with the two parallel surfaces metallized to make the
electrical connections. The physical size and thickness of a piece of quartz
crystal is tightly controlled since it affects the final frequency of
oscillations and is called the crystals "characteristic frequency". Then
once cut and shaped the crystal can not be used at any other frequency.
The crystals characteristic or resonant frequency is inversely proportional
to its physical thickness between the two metallized surfaces. A
mechanically vibrating crystal can be represented by an equivalent
electrical circuit consisting of low Resistance, large Inductance and small
Capacitance as shown below.

Quartz Crystal

Fig7.4: Quartz Crystal


A quartz crystal has a resonant frequency similar to that of a electrically
tuned tank circuit but with a much higher Q factor due to its low
resistance, with typical frequencies ranging from 4kHz to 10MHz. The cut

54
E-Automation For Trains

of the crystal also determines how it will behave as some crystals will
vibrate at more than one frequency. Also, if the crystal is not of a parallel
or uniform thickness it have two or more resonant frequencies having both
a fundamental frequency and harmonics such as second or third harmonics.
However, usually the fundamental frequency is more stronger or
pronounced than the others and this is the one used. The equivalent circuit
above has three reactive components and there are two resonant
frequencies, the lowest is a series type frequency and the highest a parallel
type resonant frequency.
We have seen in the previous tutorials, that an amplifier circuit will
oscillate if it has a loop gain greater or equal to 1 and it has positive
feedback.

In a Crystal Oscillator circuit the oscillator will oscillate at the crystals


fundamental series resonant frequency as the crystal always wants to
oscillate when a voltage source is applied to it. However, it is also
possible to "tune" a crystal oscillator to any even harmonic of the
fundamental frequency, (2nd, 4th, 8th etc.) and these are known generally
as Harmonic Oscillators while Overtone Oscillators vibrate at odd
multiples of the fundamental frequency, 3rd, 5th, 11th etc). Generally,
crystal oscillators that operate at overtone frequencies do so using their
series resonant frequency.
Virtually all microprocessors, microcontrollers, PICs and CPU's generally
operate using a Crystal Quartz Oscillator as its frequency determining
device to generate their clock waveform because as we already know,
crystal oscillators provide the highest accuracy and frequency stability
compared to Resistor/Capacitor or Inductor/Capacitor oscillators. The
CPU clock dictates how fast the processor can process the data and a
microprocessor having a clock speed of 1MHz means that it can process
data internally 1 million times a second at every clock cycle. Generally all
that's needed to produce a microprocessor clock waveform is a crystal and
two ceramic capacitors of values ranging between 15 to 33pF.

55
E-Automation For Trains

7.8 RELAY DRIVER CIRCUIT

To drive any output devices like Relay or Buzzer we need the driver circuit to
provide the required output voltage for their working. Here the output section
consists of two sections one speaker with amplifier for alarm purpose and another is
for relay.
Driver circuits to activate the +12 volts relay mechanism. For alarm purpose
we are using a special IC to generate the police siren sound and then it will be
amplified through an audio amplifier.
To activate the AC line, we must introduce a relay in the circuit, as we need to
switch ON/OFF. The power supply to the light etc. For this purpose the output from
the 555 would not have either sufficient voltage or current to operate relay directly.
So we are employing a relay mechanism. The above two NPN transistor with same
resistance network energies the relay mechanism. The above two NPN transistor BC
547 are connected in the form at Darlington pair mode.When a high signal is received
from 555 point, the relay will get energise to switch ON/O

7.9 STEPPER MOTORS


A stepper motor is a widely used device that translates electrical pulses into
mechanical movement. In applications such as disk drives, dot matrix printers, and
robotics, the stepper motor is used for position control. Every stepper motor has a
permanent magnet rotor (also called the shaft) surrounded by a stator (see Figure).

56
E-Automation For Trains

The most common stepper motors have four stator windings that are paired
with a center-tapped common as shown in below figure.

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 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 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.

57
E-Automation For Trains

8.1 LCD operation

In recent years the LCD is finding widespread wide spread use


replacing LED (seven segments LED or other multi segment LED). This
is due to the following reasons:

1. The declining prices of LCD.


2. The ability to display numbers, characters, and graphics. This is in
contrast to LED, which are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LDC, thereby
relieving the CPU of the task of refreshing the LCD. In contrast,
the LED must be refreshed by the CPU (or in some other way) to
keep displaying the data.
4. Ease of programming for characters and graphics.

58
E-Automation For Trains

8.2 Table of Pin Descriptions for LCD

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 to Write
R/W=1 to Read

6 E I/O Enable

7 DB0 I/O The 8 Pin Data Bus

8 DB1 I/O The 8 Pin Data Bus

9 DB2 I/O The 8 Pin Data Bus

59
E-Automation For Trains

10 DB3 I/O The 8 Pin Data Bus

11 DB4 I/O The 8 Pin Data Bus

12 DB5 I/O The 8 Pin Data Bus

13 DB6 I/O The 8 Pin Data Bus

14 DB7 I/O The 8 Pin Data Bus

Tabel 8.1: Pin Descriptions of LCD

8.3 Explanation of Pin Descriptions


The LCD discussed in this section has 14 pins. The function of
each pin is given in Table 8.8. Figure shows the pin positions for various
LCD.
VCC, VSS, and VEE
While V CC and V SS provide +5V and ground, respectively,

V EE is used for controlling LCD contrast.

RS, register select


There are two very 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, allowing the 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
R/W input allows the user to write information to the LCD or
read information from it. R/W=1 when reading; R/W=0 when
writing.
60
E-Automation For Trains

E, 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-to-low pulse must be applied to this pin in order for the LCD
to latch in the data present at the data pins. This pulse must be a
minimum of 450 ns wide.

Data Pins of LCD (D0 - D7)


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 display 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 instruction command codes that can be sent to the
LCD to clear the display or force the cursor to the home position or
blink the cursor. Table 12-2 lists the instruction command codes.
We also use RS = 0 to check the busy flag bit to see if the LCD is
ready to receive information. The busy flag is D7 and can be read
when R/W=1 and RS = 0, as follows: if R/W = 1, RS = 0. When
D7 = 1 (busy flag = 1), the LCD is busy taking care of internal
operations and will not accept any new information. When D7 = 0, the
LCD is ready to receive new information. Note: It is recommended to
check the busy flag before writing any data to the LCD.

61
E-Automation For Trains

8.4 LCD Command Codes

Code Command to LCD Instruction


(Hex) Register
1 Clear display screen
2 Return home
4 Decrement cursor (shift cursor to left)
6 Increment cursor (shift cursor to right)
5 Shift display right
7 Shift display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning of 1st line
62
E-Automation For Trains

C0 Force cursor to beginning of 1st line


38 2 lines and 5x7 matrix

9.1 PROGRAM FOR STEPPER MOTOR


mov p1,#0ffh
up: mov c,p1.0
jnc aclk
sjmp up

back1:mov c,p1.0
jnc clk
sjmp back1

clk: acall delay1


mov a,#11h

up1: mov p2,a


acall delay
rr a
djnz r0,up1
sjmp up

aclk: acall delay1

63
E-Automation For Trains

mov a,#11h

up2: mov p2,a


acall delay
rl a
djnz r1,up2
sjmp back1

delay1: clr p3.0


mov tmod,#10h
mov r3,#125
again: mov tl1,#08
mov th1,#01
setb tr1
back: jnb tf1,back
clr tr1
clr tf1
djnz r3,again
setb p3.0
ret
delay: mov r2,#05fh
mov r3,#0ffh
here: djnz r3, here
djnz r2, here
ret

64
E-Automation For Trains

9.2 PROGRAM TO DISPLAY TRACK CUT

MOV P1,#0FFH
UPP: SETB P1.0, A1
SJMP UPP

A1: MOV A,#38H ; init. LCD 2 lines, 5x7 martix


ACALL COMMAND ; issue command
MOV A, #0EH ; LCD on, cursor on
ACALL COMMAND ; issue command
MOV A, #01H ; clear LCD command
ACALL COMMAND ; issue command
MOV A, #06H ; shift cursor right
ACALL COMMAND ; issue command
MOV A, #86H ; cursor: line 1, pos. 6
ACALL COMMAND ; command subroutine
MOV A, # ‘T’ ;
ACALL DATA _ DISPLAY
MOV A, # ‘R’ ;
ACALL DATA _MDISPLAY
MOV A, # ‘A’ ;

65
E-Automation For Trains

ACALL DATA _MDISPLAY


MOV A, # ‘C’
ACALL DATA _ DISPLAY
MOV A, # ‘K’ ;
ACALL DATA _ DISPLAY
MOV A, # ‘ ’ ;
ACALL DATA _ DISPLAY
MOV A,#’C’

ACALL DATA _ DISPLAY


MOV A, # ‘U’ ;
ACALL DATA _ DISPLAY

MOV A, # ‘T’ ;
ACALL DATA _ DISPLAY
MOV A, # ‘A ’ ;
ACALL DATA _ DISPLAY
MOV A, # ‘H’ ;
ACALL DATA _ DISPLAY
MOV A, # ‘E’ ;
ACALL DATA _ DISPLAY
MOV A, # ‘D’ ;
SJMP UPP

COMMAND: ACALL READY ; is LCD ready?


MOV P0, A ; issue command code
CLR P2. 0 ; RS=0 for command
CLR P2. 1 ; R/W=0 for command
SETB P2. 2 ; E=1 for H-toL pulse
CLR P2. 2 ; E=0, latch in
RET

66
E-Automation For Trains

DATA_DISPLAY:
ACALL READY ; is LCD ready?
MOV P0, A ; issue data
CLR P2. 0 ; RS=1 for data
CLR P2. 1 ; R/W=0 to write to LCD
SETB P2. 2 ; E=1 for H-toL puls

READY:
SETB P0.7 ; make P1.7 input port
CLR P2.0 ; RS=0 access command reg
SETB P2.1 ; R/W=1 read command reg
; read command reg and check
busy flag

BACK: CLR P2.2 ; E=1 for H-to-L pulse


SETB P2.2 ; E=0 H-to-L pulse
JB P1.0, BACK ; stay until busy flag=0
RET
HERE: SJMP HERE ; STAY HERE

67
E-Automation For Trains

10.1 ADVANTAGES

1. Railway accidents is minimised.


2. Man power is reduced and economy of railway department is increased
3. Since Microcontroller is used, it consumes less power
4. More reliable and flexible.
5. More accuracy.

10.2 APPLICATIONS

1. Automatic Railway gate controlling is achieved with no man


2. This can adopted in Homes, factories etc.
3. Automatic parking system
4. It can be used to control cranes.

68
E-Automation For Trains

CONCLUSION

The Project “E-AUTOMATION FOR TRAINS” has been successfully designed and
tested.
It has been developed by integrating fetures of all the hardware components
used.Presence of every module has been reasoned out and placed carefully thus
contributing to the best working of the unit.

69
E-Automation For Trains

REFERENCES

1. www.project.com
2. www.atmel.com
3. www.wikipedia.com
4. www.national.com

70
E-Automation For Trains

BIBILIOGRAPHY

1. Electronic Communication Systems


-- George Kennedy.

2. Radio Engineering
-- G. K. Mithal.

3. Principles of Electronics
-- V. K. Mehta.

4. Programming & Customizing the 8051 Microcontroller


-- Myke Predko.

5. Embedded System Design using 8051 Microcontroller


--Prof. Satish Shah

6. Analog Circuits
-- D. V. Kamat & Sudha Kamat.

71

S-ar putea să vă placă și