• 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 29 June 2026 by Admin-Lavi Leave a Comment

Railway accidents happen because obstacles come on railway track, because many trains cannot stop fast; therefore, this project uses Arduino Uno, ultrasonic sensor, relay and motor or servo to give warning or stop mechanism.

The system checks distance and if object comes close, relay activates and motor moves barrier or alarm system, also this helps to avoid accidents in simple low-cost way.

Additionally, this Railway Track Accident Prevention Circuit using Arduino is easy to build.

Arduino Code:

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:

ComponentsQuantity
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 and echo pin reads reflection.

Then relay module gets 5V and signal from Arduino digital pin and also this relay can drive a DC motor or alarm.

Hence, when the sensor detects an object nearby, the relay activates and starts the motor or alarm, then, the servo rotates to show the gate closing.

Finally, 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:

  • First, gather all the parts as shown in circuit diagram.
  • Next, Ultrasonic sensor VCC pin go to 5V, GND pin go to GND, Trig pin go to Arduino pin 9 and echo pin go to Arduino pin 10.
  • Then relay module VCC pin go to 5V, GND pin go to GND, Signal IN pin go to Arduino pin 7 and COM pin goes to +5V of Arduino
  • Now relay output terminals go to motor
  • Further, servo motor Red wire go to 5V, brown wire go to GND, orange or yellow wire go to Arduino pin 6.
  • Lastly, connect one wire of the DC motor to the relays NO (Normally Open) terminal and connect the other wire to the Arduino GND.

Conclusion:

To conclude, this project for Railway Track Accident Prevention Circuit using Arduino gives simple method to avoid railway accidents.

Here, system detects object on track using ultrasonic sensor and then Arduino controls relay and servo to give warning or close barrier.

This project costs very little and works reliably, also we can install it on small rail crossings or demo models because it increases safety and reduces human error.

Filed Under: Arduino Projects, Automation Circuits, Hobby Circuits, Security and Protection, 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

  • 555 Timer Projects (129)
  • Alarm Circuits (80)
  • Amplifier Circuits (92)
  • Arduino Projects (103)
  • Audio Circuits (189)
  • Automation Circuits (139)
  • Automobile Circuits (39)
  • Battery Charger Circuits (85)
  • DIY Projects (381)
  • Free Energy (12)
  • Heater and Temperature Controllers (32)
  • High Voltage (23)
  • Hobby Circuits (220)
  • Indicator Circuits (63)
  • Inverter Circuits (17)
  • IoT projects (11)
  • LDR Circuits (46)
  • LED and Lamps (199)
  • Meters and Testers (43)
  • Mini Projects (349)
  • Motor Controllers (25)
  • Oscillator Circuits (64)
  • Power Supply Circuits (234)
  • Radio Frequency (8)
  • Remote Control Circuits (12)
  • Renewable energy (19)
  • Security and Protection (120)
  • Sensors and Detectors (233)
  • Solar Circuits (31)
  • Timer Circuits (62)
  • Transistor Circuits (175)
  • Transmitter Circuit (19)
  • Tutorials (29)
  • Voltage Regulator (40)
  • Water Level Controller (10)

Recent Posts

  • Low Current Controlled Battery Charger Circuit using LM723 IC
  • 741 Op-Amp Treble Booster Circuit
  • Simple Diode and Transistor Based Audio Limiter Circuit
  • Simple 500mW Speaker Driver Circuit
  • Easy DIY LM386 Audio Amplifier Circuit

Recent Comments

  1. Admin-Lavi on High Voltage Fence Charger Circuit
  2. egidio grzinic on High Voltage Fence Charger Circuit
  3. Logic OR Gate Circuit using Transistors - Circuit Ideas for You on Automatic Street Light Circuit using LDR
  4. Tony Gallegos on NTC Thermistor Based Temperature to Voltage Converter Circuit
  5. colin on Simple Single Transistor Audio Amplifier Circuit

Copyright © 2026 | New Circuit Ideas