Project showcase
Railroad Crossing Lights

Railroad Crossing Lights © Apache-2.0

Three LED and a switch equals railroad crossing lights.

  • 3,065 views
  • 4 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

Hello! My name is David. This is my first project. In this project, I made a railroad crossing lights with three LEDs: 2 red and 1 white and 1 switch. This project demonstrates how to define an Arduino pin.

Code

Railroad cross lightsC/C++
/*
 Railroad crossing lights
by DAVID
 */
// constants won't change. Used here to set a pin number :
const int ledPinP1 =  9;     // the number of the LED pin
const int ledPinP2 =  6;     // the number of the LED pin
const int ledPinF =  3;     // the number of the LED pin
const int switchPin = 2;    // the number of the switch pin
int switchState = 0;       // variable for reading the switch status   

void setup() {
  
  pinMode(ledPinP1, OUTPUT);  // initialize the LED pin as an output:
  pinMode(ledPinP2, OUTPUT);
  pinMode(ledPinF, OUTPUT);
  pinMode(switchPin, INPUT);  // initialize the pushbutton pin as an input:
}

void loop() 
{
    switchState = digitalRead(switchPin);   // read the state of the 
                                            //pushbuttonvalue:
    if (switchState == HIGH)   //if the switch on:
    {
        digitalWrite(ledPinF, LOW);     //white LED off
        digitalWrite(ledPinP1, HIGH);   //red1 LED on
        digitalWrite(ledPinP2, LOW);    //red2 LED off
        delay(400);                     //wait 400ms
        digitalWrite(ledPinP1, LOW);    //red1 LED off
        digitalWrite(ledPinP2, HIGH);   //red2 LED on
        delay(400);
    }
    if(switchState == LOW)              //if the switch off
    {
        digitalWrite(ledPinP1, LOW);    //red1 LED off
        digitalWrite(ledPinP2, LOW);    //red2 LED off
        digitalWrite(ledPinF, HIGH);    //white LED on
        delay(500);                     //wait 500ms
        digitalWrite(ledPinF, LOW);     //white LED off
        delay(500);
    }
}

Schematics

Breadboard
This is breadbord
Vasuti villogo bb hxdbpisf4q
Schematic
This is schem
Vasuti villogo schem 9rtyamxckq

Comments

Similar projects you might like

PIR Automated Intelligent Zebra Crossing

Project showcase by Adersh B

  • 2,262 views
  • 1 comment
  • 5 respects

Advance Automatic Railway Crossing System

Project showcase by Pawan singh and Akansh Saxena

  • 2,241 views
  • 1 comment
  • 13 respects

Police Chaser Lights

Project showcase by Jolynn Awesome

  • 5,196 views
  • 0 comments
  • 20 respects

Model Railroad Grade Crossing Controller

Project in progress by KevinMcArthur

  • 1,776 views
  • 0 comments
  • 13 respects

Crossroad Traffic Lights (FSM)

Project showcase by Daniel Turner and Carlos Silva

  • 1,297 views
  • 1 comment
  • 6 respects
Add projectSign up / Login