Thursday, 14 August 2025

Automatic Railway Gate System – IoT Based project

       Automatic Railway Gate System – IoT                                Based  Safety Project

                                       by:Sugantharajan | iot project | project no:1

                                                                                                                                                                                                          

                                                                PROJECT IMAGE



                                                                                                                                                                                                             

🚀Introduction

Railway crossings are one of the most accident-prone areas, especially in unmanned locations. Manual gate control can lead to human errors and delays. In this project, I have designed an Automatic Railway Gate System using Arduino and IR sensors to enhance safety and efficiency.


                                                                                                                                                                                                             

🧰        Components Used

  • Arduino Uno

  • IR Sensors × 2

  • Servo Motor ×2

  • Jumper Wires

  • Power Supply

                                                                                                                                                                                                             

📟Arduino Code


#include <Servo.h>

// Pin definitions
#define IR1_PIN   2    // IR sensor 1
#define IR2_PIN   3    // IR sensor 2
#define SERVO1_PIN 9   // Servo motor 1
#define SERVO2_PIN 10  // Servo motor 2
#define BUZZ_PIN   8   // Buzzer
#define LED_RED    6   // Red LED
#define LED_GRN    7   // Green LED

Servo servo1;
Servo servo2;

bool gateClosed = false;

void setup() {
  pinMode(IR1_PIN, INPUT);
  pinMode(IR2_PIN, INPUT);
  pinMode(BUZZ_PIN, OUTPUT);
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_GRN, OUTPUT);

  servo1.attach(SERVO1_PIN);
  servo2.attach(SERVO2_PIN);

  openGates(); // Start with gates open

  Serial.begin(9600);
}

void loop() {
  int ir1 = digitalRead(IR1_PIN); // LOW means detected
  int ir2 = digitalRead(IR2_PIN);

  // Case 1: Train coming from left to right
  if (ir1 == LOW && !gateClosed) {
    Serial.println("Train detected at Sensor 1 (L→R) - Closing gates");
    closeGates();
    gateClosed = true;
  }
  if (ir2 == LOW && gateClosed) {
    Serial.println("Train passed Sensor 2 (L→R) - Opening gates");
    openGates();
    gateClosed = false;
  }

  // Case 2: Train coming from right to left
  if (ir2 == LOW && !gateClosed) {
    Serial.println("Train detected at Sensor 2 (R→L) - Closing gates");
    closeGates();
    gateClosed = true;
  }
  if (ir1 == LOW && gateClosed) {
    Serial.println("Train passed Sensor 1 (R→L) - Opening gates");
    openGates();
    gateClosed = false;
  }
}

void closeGates() {
  digitalWrite(LED_RED, HIGH);
  digitalWrite(LED_GRN, LOW);

  // Warning buzzer
  for (int i = 0; i < 3; i++) {
    digitalWrite(BUZZ_PIN, HIGH);
    delay(200);
    digitalWrite(BUZZ_PIN, LOW);
    delay(200);
  }

  // Move both servos to closed position
  for (int pos = 0; pos <= 90; pos++) {
    servo1.write(pos);
    servo2.write(pos);
    delay(15);
  }
}

void openGates() {
  digitalWrite(LED_RED, LOW);
  digitalWrite(LED_GRN, HIGH);

  // Move both servos to open position
  for (int pos = 90; pos >= 0; pos--) {
    servo1.write(pos);
    servo2.write(pos);
    delay(15);
  }
}
                                                                                                                                                                                                     

🔌 Connections


1) IR Sensors
  • IR Sensor 1

    • VCC → 5V

    • GND → GND

    • OUT → D2

  • IR Sensor 2

    • VCC → 5V

    • GND → GND

    • OUT → D3                                                                         

2) Servo Motors 

  • Servo 1

    • Signal (Orange/White) → D9

    • V+ (Red) → 5V 

    • GND (Brown/Black) → GND

  • Servo 2

    • Signal → D10

    • V+ → 5V (same supply as Servo 1)

    • GND → GND

                                                                                                                                                                                               

Advantages

  • Prevents accidents at railway crossings

  • Fully automated, no human operation needed

  • Low-cost and easy to maintain


 Applications

  • Rural & semi-urban railway crossings

  • Smart transport systems

  • Educational automation projects


Contact us. sugantharajan17@gmail.com

No comments:

Post a Comment

Pulse Oximeter Using Arduino project

                    Pulse Oximeter Using Arduino project                                              by sugantharajan  |18th  august      ...