Sei sulla pagina 1di 30

Railway Monitoring by using GSM


Micro controller
IR receiver

Max 232


reset ckt.

GSM module


Fire sensor T RF
ran ID

IR Transmitter

Obstacle sensor

Micro controller
IR receiver


ce D

Railway Crossing

protectioinmainrail.ToavoidthisweselectourprojectRailway Monitoring by using
GSM.InthisprojectweAssestherailwaybeforeabout1feetfromrailway using
apply break. Again fire break out in the bogie it will be detected using sensor and
1. Microcontrollerunit.
2. distancesensor.
3. max232
4. gsmmodule
5. Regulatedpowersupply
6. LCDdisplay
7. Firesnesor

ultrasonic waves are invisible and operated at 36 kHz freq. this sensor are
when railway cross this beams then it cur beam and give interrupt signal to micro





1) Internal 64K bytes of electrically erasable programmable read only memory for
3) Operating voltage of 3.5 to 6V D.C. which is easily available by using voltage


12MHz quartz ceramic crystal is connected between pin XTAL1, & XTAL2 of


2.3.1 Microcontroller Selection Criteria
1. The first and the foremost criterion for selecting a microcontroller is that it must meet
the task at hand efficiently and cost effectively. In analyzing the need of a
microcontroller based project we must see whether an 8 bit, 16 bit, 32 bit
microcontroller can best handle the computing need of the task most efficiently.
Among other consideration in this category are speed, power consumption, amount of
on chip RAM and ROM, the number of sufficient I/O ports and cost per unit.
2. Second how easy is it to develop product around it. Key considerations are the
availability of an assembler, debugger, emulator and technical support.
3. Its ready availability in needed quantity, both now and in future.
Taking all these considerations we have chosen ATMEL at89c51 microcontroller. Brief History of 8051

In 1981, Intel Corporation introduced an 8 bit microcontroller called 8051, this

had 128 bytes of RAM, 4 bytes of on chip ROM, two timers, one serial port, and 4
ports each 8 bits wide all on a single chip. At this time it was referred to as system on
chip. The 8051 is an 8 bit processor meaning that the CPU can work only on 8 bit at a
time. Data larger than 8 bit has to be broken up into 8 bit pieces to be processed by the
The 8051 became widely popular after Intel allowed other manufacturers to make
and market any flavor of 8051 with the condition that they remain code compatible
with 8051. This has lead to many versions of 8051 with a different speed and amount of
on chip ROM marketed by different companies. ATMEL aat89c51
The AT89c51 is a low-voltage, high-performance CMOS 8-bit microcontroller
with 4K bytes of Flash programmable and erasable read-only memory. The device is
manufactured using Atmels high-density nonvolatile memory technology and is
compatible with the industry-standard MCS-51 instruction set. By combining a
versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89c51 is a powerful
microcontroller which provides a highly-flexible and cost-effective solution to many
embedded control applications.
The AT89c51 provides the following standard features: 4K bytes of Flash, 128
bytes of RAM, 15 I/O lines, two 16-bit timer/counters, a five-vector, two level interrupt
architecture, a full duplex serial port, a precision analog comparator, on-chip oscillator
and clock circuitry. In addition, the AT89c51 is designed with static logic for operation
down to zero frequency and supports two software-selectable power saving modes. The
Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and
interrupt system to continue functioning. The power-down mode saves the RAM
contents but freezes the oscillator disabling all other chip functions until the next
hardware reset.

2.4 Software

As our project required involved the application of software, on consulting with

our project guide we came to the conclusion that we shall use Embedded C for
programming utilizing the Keil software
Use of embedded processors cars, mobile phones, medical equipment, aerospace
systems etc is widespread. The applications of embedded C are exploited through the
Keil software. Keil was founded in 1986 to market add on products for development
tools provided by many of the silicon vendors. It soon became evident that there was a
void in the market placethat must be filled with quality software development tools. It
was then that Keil introduced the first C compiler designed from the ground-up
specifically for 8051 microcontroller.
The literature about Keil was collected from the net as well as some e-books via
the internet. is the link of the site from which the basics
of the software was taken.

The at89c51c51 microcontroller is from the 8051 family of microcontrollers. The
basis features of all the controllers in this family are the same, except for a few
differences from device to device. The features of the Atmel IC at89c51 is discussed in
detail below.

Memory Organization

The basic block diagram of the family of the 80x51 is as shown below in the

Fig. 3.8

All 80x51 devices have separate address spaces for program and data memory.
The logical separation of program and data memory allows the data memory to be
accessed by 8-bit addresses, which can be quickly stored and manipulated by an 8-bit
CPU. Program memory (ROM, EPROM) can only be read, not written to. There can
be up to 64k bytes of program memory. In the at89c51,there is 4K Bytes of
Reprogrammable Flash Memory(Program Memory) and 128 x 8-bit Internal RAM
(Data Memory).


Special Function Registers Description
Special Function Registers (SFRs) ate area of memory that control
functionality of the processor. SFRs are accessed as if they were normal Internal
RAM. The only difference is that Internal RAM is from address 00h through 7Fh
whereas SFR registers exist in the address range of 80h through FFh. Each SFR has
an address (80h through FFh) and a name. The following chart provides a graphical
presentation of the 80Cc51's SFRs, their names, and their address.

Fig. 3.9

As you can see, although the address range of 80h through FFh offer 128 possible
addresses, there are only 19 SFRs in a standard 80C51. All other addresses in the SFR
range (80h through FFh) are considered invalid. Writing to or reading from these
registers may produce undefined values or behavior. There are 3 categories of SFRs
namely I/O, control and other.
Whether a given I/O line is high or low and the value read from the line are
controlled by the I/O SFRs. The control SFRs in some way control the operation or
the configuration of some aspect of the 80x51. For example, TCON controls the
timers, SCON controls the serial port.The remaining SFRs, are "other SFRs." These
SFRs can be thought of as auxillary SFRs in the sense that they don't directly
configure the 80x51 but obviously the 80x51 cannot operate without them. For

example, once the serial port has been configured using SCON, the program may read
or write to the serial port using the SBUF register. Overview of all SFRs
This section will endeavor to quickly overview each of the standard SFRs
found in the above SFR chart map. This section is to just give you a general idea of
what each SFR does.
SP (Stack Pointer, Address 81h): This is the stack pointer of the microcontroller.
This SFR indicates where the next value to be taken from the stack will be read from
in Internal RAM. If you push a value onto the stack, the value will be written to the
address of SP + 1. That is to say, if SP holds the value 07h, a PUSH instruction will
push the value onto the stack at address 08h. This SFR is modified by all instructions
which modify the stack, such as PUSH, POP, LCALL, RET, RETI, and whenever
interrupts are provoked by the microcontroller.
DPL/DPH (Data Pointer Low/High, Addresses 82h/83h): The SFRs DPL and
DPH work together to represent a 16-bit value called the Data Pointer. The data
pointer is used in operations regarding external RAM and some instructions involving
code memory. Since it is an unsigned two-byte integer value, it can represent values
from 0000h to FFFFh (0 through 65,535 decimal).
PCON (Power Control, Addresses 87h): The Power Control SFR is used to
control the power control modes. Certain operation modes allow the to go into a type
of "sleep" mode which requires much less power. These modes of operation are
controlled through PCON. Additionally, one of the bits in PCON is used to double the
effective baud rate of the serial port.
TCON (Timer Control, Addresses 88h, Bit-Addressable): The Timer Control
SFR is used to configure and modify the way in which the two timers operate. This
SFR controls whether each of the two timers is running or stopped and contains a flag
to indicate that each timer has overflowed. Additionally, some non-timer related bits

are located in the TCON SFR. These bits are used to configure the way in which the
external interrupts are activated and also contain the external interrupt flags which are
set when an external interrupt has occured.
TMOD (Timer Mode, Addresses at89c51h): The Timer Mode SFR is used to
configure the mode of operation of each of the two timers. Using this SFR your
program may configure each timer to be a 16-bit timer, an 8-bit autoreload timer, a
13-bit timer, or two separate timers. Additionally, you may configure the timers to
only count when an external pin is activated or to count "events" that are indicated on
an external pin.
TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch): These two SFRs, taken
together, represent timer 0. Their exact behavior depends on how the timer is
configured in the TMOD SFR; however, these timers always count up. What is
configurable is how and when they increment in value.
TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh): These two SFRs, taken
together, represent timer 1. Their exact behavior depends on how the timer is
configured in the TMOD SFR; however, these timers always count up. What is
configurable is how and when they increment in value.
P1 (Port 1, Address 90h, Bit-Addressable): This is input/output port 1. Each bit
of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0
of port 1 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will
send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a
low level.
SCON (Serial Control, Addresses 98h, Bit-Addressable): The Serial Control
SFR is used to configure the behavior of the on-board serial port. This SFR controls
the baud rate of the serial port, whether the serial port is activated to receive data, and
also contains flags that are set when a byte is successfully sent or received.

SBUF (Serial Control, Addresses 99h): The Serial Buffer SFR is used to send
and receive data via the on-board serial port. Any value written to SBUF will be sent
out the serial port's TXD pin. Likewise, any value which it receives via the serial
port's RXD pin will be delivered to the user program via SBUF. In other words,
SBUF serves as the output port when written to and as an input port when read from.
IE (Interrupt Enable, Addresses A8h): The Interrupt Enable SFR is used to
enable and disable specific interrupts. The low 7 bits of the SFR are used to
enable/disable the specific interrupts, where as the highest bit is used to enable or
disable ALL interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled
regardless of whether an individual interrupt is enabled by setting a lower bit.
P3 (Port 3, Address B0h, Bit-Addressable): This is input/output port 3. Each bit
of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0
of port 3 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will
send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a
low level.
IP (Interrupt Priority, Addresses B8h, Bit-Addressable): The Interrupt Priority
SFR is used to specify the relative priority of each interrupt. An interrupt may either
be of low (0) priority or high (1) priority. An interrupt may only interrupt interrupts of
lower priority. For example, if we configure so that all interrupts are of low priority
except the serial interrupt, the serial interrupt will always be able to interrupt the
system, even if another interrupt is currently executing. However, if a serial interrupt
is executing no other interrupt will be able to interrupt the serial interrupt routine
since the serial interrupt routine has the highest priority.
PSW (Program Status Word, Addresses D0h, Bit-Addressable): The Program
Status Word is used to store a number of important bits that are set and cleared by
instructions. The PSW SFR contains the carry flag, the auxiliary carry flag, the
overflow flag, and the parity flag. Additionally, the PSW register contains the register

bank select flags which are used to select which of the "R" register banks are
currently selected.
ACC (Accumulator, Addresses E0h, Bit-Addressable): The Accumulator is one
of the most-used SFRs, since it is involved in so many instructions. The Accumulator
resides as an SFR at E0h, which means the instruction MOV A,#20h is really the
same as MOV E0h,#20h. However, it is a good idea to use the first method since it
only requires two bytes whereas the second option requires three bytes.
B (B Register, Addresses F0h, Bit-Addressable): The "B" register is used in two
instructions: the multiply and divide operations. The B register is also commonly
used by programmers as an auxiliary register to temporarily store values.
3.6.3 Timers/Counters General Description
The MCS-51 has two 16 bit Timer/ Counter register Timer 0 and Timer 1. Both
can be configured to operate either as timers or event counter. Microcontroller can be
used as timer or counter as you need. Microcontroller will act as timer when switch
position on upper and microcontroller will act as counter when switch position on
lower by controlling C/T bit on TMOD register. The diagram below shows the logic
of the timer/counter circuit.

Fig. 3.10

The timer/counter is controlled by the two registers TMOD and TCON. Both the
timers share these registers. The layout of both these registers is given below.
Timer/ Counter Mode Control ( TMOD ) Register








GATE: Gating control when set. Timer/ Counter X is enabled only while INTx
pin is high and TRx control pin is set
C/T : Timer or Counter Selector cleared for Timer operation (input from internal
system clock) and set for counter operation (input from Tx input pin)
M0 M1 : Indicates the mode of the Timer/ Couner
Timer/ Counter Control ( TCON ) Register








TFx: Timer overflow flag. Set by hardware on Timer/Counter overflow. Cleared

by hardware when processor vector to interrupt routine, or clearing the bit in
TRx: Timer Run control bit . Set/ cleared by software to turn Timer/ Counter
IEx: Interrupt Edge flag. Set by hardware when external interrupt edge detected.
Cleared when interrupt processed.
ITx: Interrupt type control bit. Set/ cleared by software to specefy falling edge/
low level trigerred external interrupts Modes of the timer



13 bit Timer, TLx serves as 5 bit prescaler

16 bit Timer/Counter THx and TLx are cascaded, there is no


8 bit auto reaload Timer/ Counter THx holds a value which is tobe
reloaded into TLx each time it overflows

(Timer 0) TL0 is an 8 bit Timer/ Counter controlled by the

standard timer 0 control bits
(Timer 1) Timer/ Counter 1 stopped

Mode 0 (13-bit Timer mode) :

Figure shows the Mode 0 operation as it applies to Timer 1. In this mode,
the Timer register is configured as a 13-bit register. As the count rolls over from all 1s
to all 0s, it sets the Timer interrupt flag TF1. The counted input is enabled to the
Timer when TR1 = 1 and either GATE = 0 or INT1 = 1. (Setting GATE = 1 allows the
Timer to be controlled by external input INT1, to facilitate pulse width
measurements). The 13-bit register consists of all 8 bits of TH1 and the lower 5 bits
of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored. Setting the

run flag (TR1) does not clear the registers. Mode 0 operation is the same for the
Timer 0 as for Timer 1.

Fig. 3.11

Mode 1 (16-bit Timer mode) :

Mode 1 is the same as Mode 0, except that the Timer register is being run
with all 16 bits.

Fig. 3.12

Mode 2 (8-bit Auto Reload):

Mode 2 configures the Timer register as an 8-bit Counter (TL1) with

automatic reload, as shown in Figure. Overflow from TL1 not only sets TF1, but also
reloads TL1 with the contents of TH1, which is preset by software. The reload leaves
TH1 unchanged.

Fig. 3.13

Mode 3 (2 8-bit Counter/Timer):

Timer 1 in Mode 3 simply holds its count. The effect is the same as setting
TR1=0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate counters. The
logic for Mode 3 on Timer 0 is shown in Figure. TL0 uses the Timer 0 control bits:
C/T, GATE, TR0, INT0, and TF0. TH0 is locked into a timer function (counting
machine cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0
now controls the Timer 1 interrupt. Mode 3 is provided for applications requiring
an extra 8-bit timer on the counter. With Timer 0 in Mode 3, an 80 can look like it has
three Timer/Counters. When Timer 0 is in Mode 3, Timer 1 can be turned on and off
by switching it out of and into its own Mode 3, or can still be used by the serial port
as a baud rate generator, or in fact, in any application not requiring an interrupt.

Fig 3.14

4.1.1 MICROCONTROLLER ATMEL ATat89c51 Features

Compatible with MCS51 Products

4K Bytes of Reprogrammable Flash Memory

2.7V to 6V Operating Range

Fully Static Operation: 0 Hz to 24 MHz

Two-level Program Memory Lock

128 x 8-bit Internal RAM

15 Programmable I/O Lines

Two 16-bit Timer/Counters

Six Interrupt Sources

Programmable Serial UART Channel

Direct LED Drive Outputs

On-chip Analog Comparator

Low-power Idle and Power-down Modes

Brown-out Detection

Power-On Reset (POR)





Endurance: 1,000

Write/Erase Cycles

The ATat89c51 is a low-voltage, high-performance CMOS 8-bit

microcontroller with 4K bytes of Flash programmable and erasable read-only

memory. The device is manufactured using Atmels high-density nonvolatile
memory technology and is compatible with the industry-standard MCS-51
instruction set. By combining a versatile 8-bit CPU with Flash on a monolithic
chip, the Atmel ATat89c51 is a powerful microcontroller which provides a highlyflexible and cost-effective solution to many embedded control applications.
The ATat89c51 provides the following standard features: 4K bytes of
Flash, 128 bytes of RAM, 15 I/O lines, two 16-bit timer/counters, a five-vector,
two-level interrupt architecture, a full duplex serial port, a precision analog
comparator, on-chip oscillator and clock circuitry. In addition, the ATat89c51 is
designed with static logic for operation down to zero frequency and supports two
software-selectable power saving modes. The Idle Mode stops the CPU while
allowing the RAM, timer/counters, serial port and interrupt system to continue
functioning. The power-down mode saves the RAM contents but freezes the
oscillator disabling all other chip functions until the next hardware reset.

Pin Diagram

Fig. 4.1

Internal Block Diagram

Fig. 4.2

Pin Description

Supply voltage.

Port 1
Port 1 is an 8-bit bi-directional I/O port. Port pins P1.2 to P1.7 provide internal
pullups. P1.0 and P1.1 require external pullups. P1.0 and P1.1 also serve as the
positive input (AIN0) and the negative input (AIN1), respectively, of the on-chip
precision analog comparator. The Port 1 output buffers can sink 20 mA and can
drive LED displays directly. When 1s are written to Port 1 pins, they can be used
as inputs. When pins P1.2 to P1.7 are used as inputs and are externally pulled low,
they will source current (IIL) because of the internal pullups. Port 1 also receives
code data during Flash programming and verification.
Port 3
Port 3 pins P3.0 to P3.5, P3.7 are seven bi-directional I/O pins with internal
pullups. P3.6 is hard-wired as an input to the output of the on-chip comparator
and is not accessible as a general- purpose I/O pin. The Port 3 output buffers can
sink 20 mA. When 1s are written to Port 3 pins they are pulled high by the
internal pullups and can be used as inputs. As inputs, Port 3 pins that are
externally being pulled low will source current (IIL) because of the pullups. Port 3
also serves the functions of various special features of the ATat89c51 as listed
below: Port 3 also receives some control signals for Flash programming and



Alternate Functions



(serial input port)

(serial output port)
(external interrupt 0)
(external interrupt 1)
(timer 0 external input)
(timer 1 external input)

Reset input. All I/O pins are reset to 1s as soon as RST goes high. Holding the
RST pin high for two machine cycles while the oscillator is running resets the
device. Each machine cycle takes 12 oscillator or clock cycles.
Input to the inverting oscillator amplifier and input to the internal clock operating
Output from the inverting oscillator amplifier.


Planning in phases:
Before commencement of the project it was decided to plan the project in phases so the
following are the phases in which the project will be done:
The very first phase was planning the project and getting the concepts right about the
This involved lot of reading and understanding about the core concepts and the
applications of our project.
Getting to know about the features of various components present in the circuitry.
Learning about various softwares like keil , Eagle 4.11 etc that will be used in our
Procuring the various components required for the project.
Creating the PCB (printed circuit board) for our project.
Interfacing the system with microcontroller.
Implementing the entire project.
Testing the working of the final monitoring system.

16X2 LCD DISPLAY Features

Maximum input voltage: 5.3VDC

Operating input voltage: 5VDC

8-bit interface data bus

Controller: HD47780 equivalent

Character font size: 0.125"W x 0.200"H

16 pin/terminals

Display size: 2.5"L x 0.7"W

Module size: 3.4"L x 1.2"W x 0.5"T Description
This is a 16 character by 2 line display, with the standard HD44780
chipset. It works great with any microcontroller and it is very easy to interface. This LCD
has 8-bit parallel interface. It is possible to use all 8 bits plus 3 control signals or 4 bits
plus the control signals. Pin Diagram

Fig. 4.6

Fig. 4.7 LCD Interfacing diagram

The diagram below gives the interfacing configuration of the LCD with
the microcontroller.

Fig. 4.8


4.1 Problems occurs during development:If you wants to avoid the troubleshooting we must use new and good quality
components and 60/40 type solder. The polarity of component should be strictly
observed. As follows:1. After verifying all the components on bread board and check the whole
operation of the circuitry.
2. After etching PCB make continuity test of all tracks if any one track is
damaged then connect it through wire.
3. After connecting project to battery make sure that supply to all sections
are ok. When power supply at any point is available. Then troubleshooting
following points:-

a) Output at pin no.3 of IC 7805.

b) Check IC 7805.
c) See the values of decoupling capacitor.
d) Check the polarity of wires connected from battery to IC 7805.
4. If output from IC 7805 is less than 5V then replace that IC.
5. If decoder section is ok then check the microcontrollers output pins i.e. 12
to 19 and its connections i.e. VCC and GND.
6. If controller is ok then check connection between decoder and controller.
7. Then the functionality and connection of relay driver, if it is not ok then
replace it.
8. The relay driver needs to be checked that whether it is heating or not if it
occurs then replace it immediately because it is shorting.
9. If all the connections and components are ok then check the battery.

Upon initial inspection of the circuit operation, multiple problems were noted.
The input signal is transmitted from the cell phone but it is not detected by the
receiver. Troubleshooting of the circuit was undertaken to isolate causes of circuit
failure. The original and expected results of various components of the circuit are as
1) Power Supply: - The power supply is mainly used to give the regulated 5V
output to all the components. But due to interference between ground and output
there is glitch in the output. So we have used capacitor to decouple them and
hence the power supply gives the 5V regulated output.
2) Microcontroller:- The microcontroller is mainly used for controlling and
performing the action of motor driver. But due to wrong selection of crystal
oscillator and decoupling. The controller time cycle is disturbed. So by using
capacitor to decouple these problems are solved.
3) Relay Driver:- The relay driver is mainly used for the controlling of the supply
to transformer. The relay driver requires signal from microcontroller to
operate.the relay takes 12v and 20ma. So we have connected it directly to relay
driver ckt cannot connect directly to microcontroller. So that it will satisfy the
surge current requirement of the relay.
4) Result of Debugging:- After debugging the circuits individual modules, it was
found that each of them function as were expected, and with some modifications
the output of each components is right and consistent.

5.1 Conclusion:Overall the project was satisfactorily completed. Components functioned properly
in isolation and with interconnection. There is problem in circuit due to interference
between decoder and motor driver but when we separate the two components apart from
each other then whole circuit works properly.
Generally the commercial project are overpriced, the main goal of this project was
that the low cost with global connectivity and controllability is possible. The total cost
was expected to be less when selecting hardware components clearly this goal has been
Core objective of Railway monitoring using gsm successfully achieved,
microcontroller AT89c51 controller is the main brain and has burned program in it.
The project is a grant success and real time output

have been successfully