Railway accidents happen because obstacles come on railway track.
Many trains cannot stop fast.
This project uses Arduino Uno, ultrasonic sensor, relay and motor or servo to give warning or stop mechanism.
The system checks distance.
If object comes close, relay activates and motor moves barrier or alarm system.
This helps to avoid accidents in simple low-cost way.
This Railway Track Accident Prevention Circuit using Arduino is easy to build.
Arduino Coding:
const int trigPin = 9;
const int echoPin = 10;
const int relayPin = 7;
const int servoPin = 6;
long duration;
int distance;
#include <Servo.h>
Servo myservo;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relayPin, OUTPUT);
myservo.attach(servoPin);
myservo.write(0);
digitalWrite(relayPin, LOW);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.println(distance);
if (distance < 20) {
digitalWrite(relayPin, HIGH);
myservo.write(90);
} else {
digitalWrite(relayPin, LOW);
myservo.write(0);
}
delay(200);
}
Coding Explanation:
- Ultrasonic sensor sends sound pulse.
- Echo pin reads back the signal time.
- Arduino calculates distance from time.
- If distance is less than set value like 20 cm then Arduino turns relay ON.
- Servo also rotates to show barrier movement.
- If distance is safe then relay stays OFF and servo goes back.
- Simple logic control.
Circuit Working:
Parts List:
| Item | Quantity |
|---|---|
| Arduino Uno | 1 |
| Ultrasonic Sensor HC-SR04 | 1 |
| 5V Relay Module | 1 |
| Servo Motor (SG90) | 1 |
| DC Motor | 1 |
Arduino gives 5V power to ultrasonic sensor and to servo.
Trig pin sends pulse.
Echo pin reads reflection.
Relay module gets 5V and signal from Arduino digital pin.
Relay can drive a DC motor or alarm.
When object is detected close then relay activates and motor or alarm starts.
The servo rotates to show gate closing.
All devices share common ground.
Formulas:
Ultrasonic distance formula:
Distance = (time x speed of sound) / 2
Speed of sound in air approx 340 meter per second
In microseconds speed about 0.034 cm per microsecond
So distance = duration x 0.034 / 2
Division by 2 because pulse travels to object and back.
How to Build:
To build a Railway Track Accident Prevention Circuit using Arduino follow the below steps:
- Gather all the parts as shown in circuit diagram.
- Ultrasonic sensor VCC pin go to 5V.
- GND pin go to GND.
- Trig pin go to Arduino pin 9.
- Echo pin go to Arduino pin 10.
- Relay module VCC pin go to 5V.
- GND pin go to GND.
- Signal IN pin go to Arduino pin 7.
- COM pin goes to +5V of Arduino
- Relay output terminals go to motor.
- Servo motor Red wire go to 5V.
- Brown wire go to GND.
- Orange or yellow wire go to Arduino pin 6.
- One wire of the DC motor goes to relay NO (Normally Open) terminal.
- And other end must be connected to Arduino GND.
Conclusion:
This project for Railway Track Accident Prevention Circuit using Arduino gives simple method to avoid railway accidents.
System detects object on track using ultrasonic sensor.
Arduino controls relay and servo to give warning or close barrier.
Cost is low and working is stable.
It can be installed on small rail crossings or demo models.
It increases safety and reduces human error.
