Automatic Railway Gate Controller

The automatic Railway Gate Control System is a simple but very useful project, which help is automatically opening and closing the railway gate upon detecting the arrival or departure of the train.

In general, Railway gates are opened or closed manually by a gatekeeper. The information about the arrival of the train for opening or closing of the door is received from the nearby station. But some railway crossings are totally unmanned and many railway accidents occur at these unmanned level crossings.

To avoid human intervention at level crossings completely, we need to automate the process of railway gate control.

We have two different Automatic Railway Gate Control circuits mentioned in this article: using 8051 and AVR.  


  • Construction and Output Video
  • Principle of Operation
  • Circuit 1 Automatic Railway Gate Control using 8051
    • Circuit Diagram of Automatic Railway Gate Control using 8051
    • Project Components
      • Microcontroller Section
      • Sensor and Load Section
    • Component Description
      • IR Sensor
      • L293D Motor Driver
    • Circuit Design
    • Working
    • Advantages and Applications
    • Limitations
  • Circuit 2 Automatic Railway Gate Controller with High-Speed Alerting System
    • Circuit Diagram of Automatic Railway Gate Controller
    • Circuit Operation

Construction and Output Video

Principle of Operation

The principle of operation behind the working of this project lies in the functioning of the IR Sensor. A Reflective type IR Sensor is used in this project.

The IR transmitter and receiver are arranged side by side in a Reflective Type IR Sensor. Because there are no rays falling on the IR Receiver when there is no impediment in front of the sensor, the IR rays broadcast by the IR Transmitter will go undetected.

If an obstruction stands in front of the IR Transmitter and Receiver pair, the IR Rays are reflected off the object’s surface and incident on the IR Receiver.

This configuration can be designed to detect an object, such as a train, and then utilize the microcontroller to turn on or offloads, such as motors.

Circuit 1 Automatic Railway Gate Control using 8051

Circuit Diagram of Automatic Railway Gate Control using 8051

Automatic Railway Gate

Project Components

Microcontroller Section

  • AT89C51 MCU
  • 11.0592 MHz Quartz Crystal
  • 2 x 33pF Ceramic Capacitor
  • 10µF / 16V Electrolytic Capacitor
  • 10KΩ Resistors x 2
  • AT89C51 Programmer Board

Sensor and Load Section

  • 2 x Reflective Type IR Sensor
  • 2 x 1KΩ Resistor
  • L293D Motor Driver IC
  • Motor

Component Description

IR Sensor

  • An IR sensor is used in this project to sense the arrival and departure of the train.
  • An IR Sensor generally comprises two components: an IR Transmitter and an IR Receiver. An IR Transmitter is a device that emits IR Rays.
  • Similarly, an IR Receiver is a device that detects IR Rays. Photo Diodes are the most commonly used IR Receivers. 
  • The following image shows the circuit of the IR Sensor used in this project. 
Automatic Railway Gate Control IR Sensor

L293D Motor Driver

The L293D motor driver IC is utilized to control the gate motor in this project. The L293D Motor Drive IC is a twin H-bridge motor driver that comes in a 16-pin Dual in-line Package.

We can control two motors at once with this motor driver IC, and each motor can be controlled in both forward and reverse directions.

Motor drivers are typically used to power high-current devices like DC motors, stepper motors, and high-intensity lights, among other things. They work as simple current amplifiers, with a low current signal coming in from a microcontroller and a high current signal coming out to operate the loads.

Circuit Design

The 8051 microprocessor (AT89C51), Reflective Type IR Sensor, L293D Motor Driver IC, and a Motor are the main components of our project.

The oscillator circuit, reset switch, and EA Pin are all required connections for the 8051 MCU.

As an external clock source, a crystal oscillator with a frequency of up to 20MHz can be used. An 11.0592 MHz quartz crystal oscillator is used in this project. Two 33pF capacitors are utilized to complete the external oscillator circuit. Finally, a 10K resistor is used to pull the EA pin high.

Now, let us see the actual connections required to implement the project. That first is the L293D Motor drive. The inputs (IN1 and IN2) to the motor driver (Pins 1 and 2) are given from Port 0 of the microcontroller.

But before connecting them, two 1KΩ resistors are used to pull the Port 0 pins high. Now, connect the motor driver input pins i.e. IN1 and IN2 to the first two pins of Port 0 i.e. P0.0 and P0.1.

A motor is connected to the OUT pins of the motor driver.

Finally connect two IR sensors to the microcontroller: one for detecting the arrival of the train and one for detecting the departure of the train.

So, connect the data outputs of the IR sensors to the pins P2.6 and P2.7 of the microcontroller.


The work of the project is very simple and is explained here.

  • Practically, the two IR sensors are placed at the left and right sides of the railway gate. The distance between the two IR sensors is dependent on the length of the train. In general, we have to consider the longest train in that route.
  • Now we’ll see how this circuit actually works in real-time. In this image, we can see the real-time representation of this project.
real time image1
  • If sensor 1 detects the arrival of the train, the microcontroller starts the motor with the help of the motor driver in order to close the gate.
real time image 2
  • The gate remains closed as the train passes the crossing.
  • When the train crosses the gate and reaches the second sensor, it detects the train and the microcontroller will open the gate.
real time image 3

Advantages and Applications

  • An Automatic Railway Gate Control is implemented with very simple hardware and easy control.
  • Human intervention at level crossings can be removed with the help of this project and many railway level crossing accidents can be prevented.


  • The system can be implemented more efficiently by incorporating a more efficient sensor network.
  • A combination of manual wireless control and sensors-based control can be used for better operation.

Circuit 2 Automatic Railway Gate Controller with High-Speed Alerting System

The automatic Railway Gate Control System with High-Speed Alerting System is an innovative circuit that automatically controls the operation of railway gates detecting the arrival and departure of trains at the gate.

It has detectors at a far away distance on the railway track which allows us to know the arrival and departure of the train. These detectors are given to a microcontroller that activates the motors which open/close the railway gate correspondingly.

Another feature of this circuit is that it has an intelligent alerting system that detects the speed of the train that is arriving. If the speed is found to be higher than the normal speed, then the microcontroller automatically activates the alarm present at the gate.

This alerts the passengers at the railway crossing on the road about this. Also, This circuit has a feature for the Identification of trains from other intruders i.e, animals, etc. This can be implemented in manned level crossings also, as manual errors can be eliminated by automation.

Circuit Diagram of Automatic Railway Gate Controller

Circuit Operation

The operation of the circuit can be clearly explained as follows. Basically, the circuit consists of four IR LED-Photo diode pairs arranged on either side of the gate such that IR LED and photodiodes are on either side of the track as shown in the figure below.

Initially, the transmitter emits an infrared light that is directed at the receiver. When the train arrives, the light landing on the receiver is switched off. Assume the train is approaching from the left; when it crosses the first sensor pair, a counter is started, and when it crosses the second sensor pair, the countdown is stopped. This counter number represents the time period needed to determine the train’s velocity.

The sensor2 output is passed to the microcontroller, which activates the relay, which closes the gate. When the train’s last carriage comes to a stop, the sensor4 microcontroller de-activates the relay, and the gates open.

How does the sensor know the last carriage?

Here as previously mentioned the counter value is used to calculate the velocity of the train, which means that every wheel of the carriage cuts the sensor pair within a small fraction of time based on its velocity. After the last carriage is passed there is no obstacle to the sensor pair within that fraction of time hence it knows that the train has left.

Another feature of this circuit is that it accurately detects trains. If an obstacle (for example, an animal) cuts the sensor, the counter is set to run for a certain period of time (this time period is set considering the train’s possible lowest speed), and if the obstacle does not cut the second sensor before this predefined time, the obstacle is not considered.

Another benefit of calculating the train’s velocity is that if the train’s speed exceeds a certain limit, the passengers are informed by a buzzer.

The system consists of two IR LED – Photodiode pairs that are spaced about 1 meter apart on the railway track, with the transmitter and photodiode of each pair on opposing sides of the track. The block diagram depicts the installation. With a resolution of 0.01 seconds, the system displays the time taken for the train to travel this distance from one pair to the other, from which the vehicle’s speed may be computed as follows:

Speed (kmph) = Distance/Time

As the distance between the sensors is known and constant, the time is counted by the microcontroller and from this information, we can calculate the speed.

This circuit has been designed considering the maximum permissible speed for trains as per the traffic rule.

The microcontroller is used to process the inputs that are provided by the sensors and generate the desired outputs appropriately.



Related Articles

Leave a Reply

Your email address will not be published.

Back to top button