Smart Railway Crossing System With Arduino

by | Mar 18, 2023 | Arduino, Basic Coding, Coding

Home » Coding » Smart Railway Crossing System With Arduino

Introduction

Are you looking for a fun and rewarding project that combines your love for electronics with your interest in transportation? Look no further than building a DIY Smart Railway Crossing System with Arduino! This project allows you to design and assemble a fully functional railway crossing system that can detect the presence of a train and automatically lower the crossing arm to prevent accidents.

Using an Arduino microcontroller, some sensors, and a few other electronic components, you can create a smart system that is not only a great Arduino project starter but also has practical applications. So, grab your tools, and let’s get started on building your very own Smart Railway Crossing System!

To build this Arduino project, we will use a PIR motion sensor to detect the presence of the train, and accordingly, we will close and open the gates with a red led light.

 

Supplies

Before you start building your DIY Smart Railway Crossing System with Arduino, there are a few prerequisites you need to keep in mind. Here are the key components you will need:

Components

Circuit Diagram

Steps To Build A Smart Railway Crossing System With Arduino

Step 1: We first gather all the components on the Digital Board of the TinkerCad website.

PIR Sensor:

Step 2: Connect the Ground terminal of the PIR sensor to the GND pin of the Arduino.

Step 3: Connect the Power terminal of the PIR sensor to the 5V pin of the Arduino.

Step 4: Connect the Signal terminal of the PIR sensor to the 13-number pin of the Arduino.

Micro Servo:

Step 5: Connect the Power terminal of the micro servo to the 5V pin of the Arduino.

Step 6: Connect the Signal terminal of the micro servo to the 2 & 3 number pin of the Arduino, resp.

Step 7: Connect the Ground terminal of the micro servo to the GND pin of the Arduino.

LEDs:

Step 8: Connect the Cathode terminal of the LED to the GND pin of the Arduino.

Step 9: Connect the Anode terminal of the LED to the 6 & 7 number pin of the Arduino.

Source Code

#include <Servo.h>
Servo s1, s2;
int presence = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, INPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
s1.attach(3);
s1.write(90);
s2.attach(2);
s2.write(90);
}
void loop()
{
presence = digitalRead(13);


Serial.print(presence);


if( presence == HIGH)
{
s1.write(90);
s2.write(90);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
if(presence == LOW)
{
s1.write(0);
s2.write(0);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
}
}

Explanation of the Code

1. The first thing we did was to include the Servo library.

2. After that, we declared the object of the servo as “s1” and “s2” and initialized another integer variable named “presence” to 0.

3. In the setup function, we are configuring the pinMode of the Arduino for input purposes. Using serial.begin, we are establishing a serial connection with 9600 bits per second.

4. After that, we have attached pin numbers 2 & 3 of the Arduino to the servo, and initially, writing it to 0 degrees means the gates will be initially in an open position.

5. Now, in the loop function, we are reading input from pin number 13 of the Arduino, which will tell us if there is any train passing through the track or not. We are storing this value in the presence variable.

6. Finally, we use the if statement to change the direction of the servo wrt the presence variable. We have used the write function to change the orientation of the servo. If any train passes in the range of the sensor, the LED will glow, and the gates will close.

Output

Below we have demonstrated the output of this smart railway crossing system project.

Smart Railway Crossing System With Arduino - Output

On starting the simulation, if any train passes through the sensor, the gates( servo) will be closed, and the red led will glow.

 

 

More Arduino Projects>>>

You May Also Like To Create…

0 Comments

Submit a Comment

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