Automatic Railway Gate Controller
The Automatic Railway Gate Control System is a straightforward yet highly valuable project designed to automatically open and close railway gates when a train arrives or departs.
Typically, railway gates are manually operated by a gatekeeper, who relies on information from nearby stations to determine when to open or close the gates. However, unmanned railway crossings are susceptible to numerous accidents, emphasizing the need for automating railway gate control to eliminate human intervention.
This article discusses two distinct Automatic Railway Gate Control circuits, one utilizing the 8051 microcontroller and the other employing AVR technology.
Outline
- 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 fundamental principle underlying the functionality of this project hinges on the operation of the IR Sensor, specifically a Reflective type IR Sensor.
In the Reflective Type IR Sensor, the IR transmitter and receiver are positioned in close proximity. When there is no obstacle obstructing the sensor’s path, the IR receiver remains unilluminated as there are no IR rays reaching it from the IR transmitter.
However, when an obstacle, such as a train, enters the sensor’s field, it reflects the IR rays emitted by the IR Transmitter back towards the IR Receiver.
This configuration is devised to detect the presence of an object, such as a train, and subsequently employ the microcontroller to activate or deactivate various components, such as motors.
Circuit 1 Automatic Railway Gate Control using 8051
Circuit Diagram of Automatic Railway Gate Control using 8051
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.

L293D Motor Driver
In this project, the gate motor is regulated using the L293D motor driver IC. The L293D Motor Driver IC is a dual H-bridge motor driver packaged in a 16-pin Dual in-line Package.
This motor driver IC enables the simultaneous control of two motors, allowing each motor to be operated in both forward and reverse directions.
Motor drivers serve the purpose of powering high-current devices, such as DC motors, stepper motors, and high-intensity lights, among others. They function as straightforward current amplifiers, taking in a low-current signal from a microcontroller and delivering a high-current signal to operate the connected loads.
Circuit Design
Our project relies on several key components: the 8051 microprocessor (AT89C51), a Reflective Type IR Sensor, the L293D Motor Driver IC, and a Motor.
For the 8051 microcontroller, it’s essential to establish the oscillator circuit, incorporate a reset switch, and make the necessary connections for the EA Pin.
As an external clock source, a quartz crystal oscillator with a maximum frequency of 20MHz is suitable. In this project, we utilize an 11.0592 MHz quartz crystal oscillator. To complete the external oscillator circuit, two 33pF capacitors are employed. Additionally, a 10K resistor is used to pull the EA pin high.
Now, let’s delve into the specific connections required for the project. Firstly, we address the L293D Motor Driver. The motor driver’s inputs (IN1 and IN2), found on Pins 1 and 2, are connected to Port 0 of the microcontroller. Prior to connecting, two 1KΩ resistors are used to pull the Port 0 pins high. Subsequently, the motor driver input pins (IN1 and IN2) are linked to the first two pins of Port 0, namely P0.0 and P0.1. The motor is then connected to the OUT pins of the motor driver.
Finally, we integrate two IR sensors with the microcontroller: one for detecting train arrivals and another for detecting departures. To achieve this, connect the data outputs of the IR sensors to pins P2.6 and P2.7 of the microcontroller.
Working
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.
- 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.

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

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.
Limitations
- 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 High-Speed Alerting System integrated into the Automatic Railway Gate Control System is an innovative circuit designed to autonomously manage railway gate operations by detecting train arrivals and departures.
This system employs detectors positioned at a considerable distance along the railway track, allowing us to monitor train arrivals and departures effectively. These detectors are connected to a microcontroller, which, in turn, controls the motors responsible for opening and closing the railway gate in response to train movement.
Furthermore, this circuit boasts an intelligent alerting mechanism capable of gauging the approaching train’s speed. If the speed exceeds the standard threshold, the microcontroller automatically triggers an alarm located at the gate. This alarm serves as a warning to pedestrians and motorists at the railway crossing, ensuring their safety.
Additionally, this circuit incorporates a feature for distinguishing trains from other potential intruders, such as animals, further enhancing its applicability. This system can also be deployed in manned level crossings, effectively minimizing the scope for human errors through automation.
Circuit Diagram of Automatic Railway Gate Controller
Circuit Operation
The functioning of the circuit can be elucidated as follows: The circuit comprises four pairs of IR LED and photodiode, strategically positioned on both sides of the gate. This arrangement situates the IR LED and photodiodes on either side of the railway track, as illustrated in the figure below.
Initially, the transmitter emits an infrared light directed towards the receiver. Upon the train’s arrival, the light reaching the receiver is interrupted. Assuming the train approaches from the left, the counter begins when it passes the first sensor pair and stops when it crosses the second sensor pair. This counter value corresponds to the time required to calculate the train’s speed.
The output from sensor2 is transmitted to the microcontroller, which triggers the relay responsible for closing the gate. As the last carriage of the train comes to a halt, sensor4 signals the microcontroller to deactivate the relay, resulting in the gates opening.
How does the sensor know the last carriage?
As previously mentioned, the counter value plays a crucial role in calculating the train’s velocity. This means that as each carriage’s wheel passes the sensor pair, it does so within a brief timespan determined by its speed. Once the last carriage clears the sensor pair, this timespan elapses, signaling that the train has departed.
Another noteworthy feature of this circuit is its precision in detecting trains. In cases where an obstruction (e.g., an animal) interrupts the sensor’s beam, the counter is initiated and runs for a predefined duration, typically set to accommodate the train’s slowest potential speed. If the obstruction fails to clear the second sensor within this predetermined timeframe, it is not considered a train.
Calculating the train’s velocity serves another purpose: it provides a means to alert passengers if the train exceeds a specific speed limit, triggering a buzzer.
The system employs two sets of IR LED-Photodiode pairs positioned approximately one meter apart on the railway track, with each pair’s transmitter and photodiode situated on opposite sides of the track. The block diagram illustrates the setup. The system achieves a time resolution of 0.01 seconds, displaying the time taken for the train to traverse the distance between these pairs. This time data, in conjunction with the known and constant sensor spacing, enables the microcontroller to compute the train’s speed using the formula:
Speed (kmph) = Distance/Time
Given the fixed sensor separation, the microcontroller tracks the time, facilitating speed calculation.
This circuit has been meticulously designed in compliance with the maximum allowable train speed as stipulated by traffic regulations.
The microcontroller serves as the central processing unit, receiving inputs from the sensors and orchestrating the appropriate outputs accordingly.