• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Circuit Ideas for You

Get free circuit ideas online.

  • Home
  • Privacy Policy
  • About
Home » Railway Track Accident Prevention Circuit using Arduino

Railway Track Accident Prevention Circuit using Arduino

Last updated on 18 November 2025 by Admin-Lavi Leave a Comment

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:

Railway Track Accident Prevention Circuit Diagram using Arduino

Parts List:

ItemQuantity
Arduino Uno1
Ultrasonic Sensor HC-SR041
5V Relay Module1
Servo Motor (SG90)1
DC Motor1

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.

References:

Prevention of Railway Accident using Arduino Based Safety System: A case Study of Addis Ababa Light Rail Transit

Filed Under: Arduino Projects, Sensors and Detectors

About Admin-Lavi

Lavi is a B.Tech electronics engineer with a passion for designing new electronic circuits. Do you have questions regarding the circuit diagrams presented on this blog? Feel free to comment and solve your queries with quick replies

Previous Post: « Arduino Based Pulse Monitoring Circuit
Next Post: Rain Detector Circuit using Arduino »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar




Categories

  • Alarm Circuits (45)
  • Amplifier Circuits (67)
  • Arduino Projects (99)
  • Audio Circuits (114)
  • Automobile Circuits (19)
  • Battery Charger Circuits (65)
  • Free Energy (13)
  • Heater and Temperature Controllers (13)
  • High Voltage (1)
  • Indicator Circuits (45)
  • Inverter Circuits (20)
  • IoT projects (1)
  • LDR Circuits (26)
  • LED and Lamps (148)
  • Meters and Testers (30)
  • Motor Controllers (22)
  • Oscillator Circuits (39)
  • Power Supply Circuits (104)
  • Remote Control Circuits (10)
  • Security and Protection (29)
  • Sensors and Detectors (126)
  • Solar Circuits (29)
  • Timer Circuits (41)
  • Transistor Circuits (87)
  • Transmitter Circuit (17)
  • Tutorials (8)
  • Water Level Controller (6)

Recent Posts

  • 12V Battery Low Voltage Alarm Circuit
  • Low Voltage Alert Circuit for 9V Battery
  • Digital Code Lock Circuit using IC 4017
  • Darkness Activated LED Circuit
  • Fan Start 10 Second Delay Timer Circuit

Recent Comments

  1. TDHofstetter on DIY Variable Power Supply Circuit using Arduino
  2. feathbuff on Simple Micro Ampere Meter Circuit
  3. Admin-Lavi on Simple School Project Multimeter Circuit
  4. choke on Simple School Project Multimeter Circuit
  5. Admin-Lavi on Analog to Digital Converter Circuit using IC 555

Copyright © 2026 | New Circuit Ideas