Project showcase
Advance Automatic Railway Crossing System

Advance Automatic Railway Crossing System

This is an advanced version of a railway crossing system.

  • 3,736 views
  • 1 comment
  • 16 respects

Components and supplies

Apps and online services

About this project

We decided to make this project because we wanted to improve the older version of it. The older version that we have seen contained only two paths - track and road; our model has a system for tracks, pedestrian path and roads.

Code

Advance Automatic Railway crossing systemArduino
Code for the project
#include<Servo.h>
#include<EEPROM.h>

#define segA A0  // connecting segment A to PIN2
#define segB 3  // connecting segment B to PIN3
#define segC 4  // connecting segment C to PIN4
#define segD 5  // connecting segment D to PIN5
#define segE 6  // connecting segment E to PIN6
#define segF 7  // connecting segment F to PIN7
#define segG 8  // connecting segment G to PIN8
#define red 9   // red pin
#define green 10 // green pin
#define speaker 12

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

Servo myservo;

const int button = 2; 

int di,du,count,a,t,y,z,u, value1, value2;
int l=0;
int b=0;


void setup(){
 Serial.begin(9600);
 pinMode(A1, INPUT);
 myservo.attach(11);
 for(a=3;a<=10;a++)
 {
  pinMode(a, OUTPUT);
 }

  pinMode(button, INPUT); 
  pinMode(A0, OUTPUT);
  pinMode(speaker,OUTPUT);
  
 attachInterrupt(digitalPinToInterrupt(button), bstate, HIGH);
  
}

void loop(){
 pOffroadOn();

 Serial.println(di);
 value1 = EEPROM.read(1);
 Serial.print("value is : " );
 Serial.println(value1);
 Serial.println(di);
 
 if(value1 == 1){
  roadOffpOn();
  delay(9000);
 }

 else if(value1 == 0){
  pOffroadOn();
  
 }
 
 EEPROM.update(1,0);

value2 = EEPROM.read(2);

Serial.print("value2 is:  ");
Serial.println(value2);

if(value2 == 1 && b == 0){
  pOffroadOn();
  Serial.println("button pressed in first cycle"); 
}

else if(value2 == 1 && b == 1){
  roadOffpOn();
  Serial.println("button pressed in second cycle");
}

else{
  pOffroadOn();
  Serial.println("button not pressed");
}

EEPROM.update(2,0);

 }
  
    
    
void trainAppear(){                // train appears
   ultra();
   if(di<=30){
   Train();
   }  
   }

  
  

    
       

    void timerOff(){                  // Timer off
    for(t=3;t<=8;t++){
    digitalWrite(t, LOW);
    }
    digitalWrite(A0, LOW);
    
    }



    void pOffroadOn(){                 // pedestrian off when road On
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    
    myservo.write(90);
    noTone(speaker);
    
    trainAppear();
    Timer();
}

  

  
    
    void roadOffpOn(){                    // road off when pedestrian on
  
    
    digitalWrite(red, LOW);
    //digitalWrite(green, HIGH);
    myservo.write(0);
    //speakerP();
    timerOff();
    noTone(speaker);
    //tone(speaker,1000);
    //trainAppear();
    greenG();
    
    
  }


   void bstate() {
   
    EEPROM.write(1,1);
    EEPROM.write(2,1);
    Serial.println("value return:    ");
  }


    void Timer(){                // Timer O
     switch (count)      
                {
               
                case 0 ://when count value is zero show”0” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, HIGH);
                digitalWrite(segE, LOW);
                digitalWrite(segF, HIGH);
                digitalWrite(segG, HIGH);
                break;
 
                case 1:// when count value is 1 show”1” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, HIGH);
                digitalWrite(segE, HIGH);
                digitalWrite(segF, HIGH);
                digitalWrite(segG, HIGH);
                break;
 
                case 2:// when count value is 2 show”2” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, LOW);
                digitalWrite(segE, LOW);
                digitalWrite(segF, LOW);
                digitalWrite(segG, LOW);
                break;
 
                case 3:// when count value is 3 show”3” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, LOW);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, HIGH);
                digitalWrite(segE, HIGH);
                digitalWrite(segF, HIGH);
                digitalWrite(segG, HIGH);
                break;
 
                case 4:// when count value is 4 show”4” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, LOW);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, HIGH);
                digitalWrite(segE, LOW);
                digitalWrite(segF, HIGH);
                digitalWrite(segG, HIGH);
                break;
 
                case 5:// when count value is 5 show”5” on disp
                digitalWrite(segA, LOW);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, LOW);
                digitalWrite(segE, LOW);
                digitalWrite(segF, HIGH);
                digitalWrite(segG, HIGH);
                break;
 
                case 6:// when count value is 6 show”6” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, HIGH);
                digitalWrite(segE, LOW);
                digitalWrite(segF, LOW);
                digitalWrite(segG, HIGH);
                break;
 
                case 7:// when count value is 7 show”7” on disp
                digitalWrite(segA, HIGH);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, LOW);
                digitalWrite(segD, HIGH);
                digitalWrite(segE, HIGH);
                digitalWrite(segF, LOW);
                digitalWrite(segG, HIGH);
                break;
 
                case 8:// when count value is 8 show”8” on disp
                digitalWrite(segA, LOW);
                digitalWrite(segB, HIGH);
                digitalWrite(segC, HIGH);
                digitalWrite(segD, LOW);
                digitalWrite(segE, LOW);
                digitalWrite(segF, LOW);
                digitalWrite(segG, LOW);
                break;

                
                }
                if (count<10)
                {
                                count++;
                                delay(1000);///increment count integer for every second
                                
                                
                }
           else if (count==10)
                {
                                count=0;// if count integer value is equal to 10, reset it to zero.
                               
                                b = 1;                                
                }
                }


               
   void greenG(){
  for(y=0;y<=5;y++){
  digitalWrite(green, HIGH);
  delay(900);
  digitalWrite(green, LOW);
  delay(100);
  trainAppear();
  
 }

  for(u=0;u<=30;u++){
  digitalWrite(green, HIGH);
  delay(90);
  digitalWrite(green, LOW);
  delay(10);
  trainAppear();
 }
   }
Advance Automatic Railway crossing systemArduino
Code to check photo-resistor value whenever used
int value;

void setup() {
  Serial.begin(9600);

  pinMode(A1, INPUT);
  // put your setup code here, to run once:

}

void loop() {
  value = analogRead(A1);
  Serial.println(value);
  // put your main code here, to run repeatedly:

}

Schematics

Advance Automatic Railway crossing system
Schematic
frit_VvnoH7JsLk.fzz
Circuit diagram
Screenshot (20) dezvezr3pk

Comments

Similar projects you might like

RFID Based Automatic Door System

Project showcase by Robodia Technology

  • 35,759 views
  • 20 comments
  • 97 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,826 views
  • 17 comments
  • 75 respects

Automatic Watering System

Project tutorial by PRosenb

  • 14,923 views
  • 15 comments
  • 36 respects

Automatic Watering System

Project tutorial by Manson Hau

  • 9,064 views
  • 11 comments
  • 38 respects

Automatic Brightness Sensor

Project showcase by Achraf Oukheir

  • 2,527 views
  • 1 comment
  • 8 respects
Add projectSign up / Login