Project showcase
Railroad Crossing Lights

Railroad Crossing Lights © Apache-2.0

Three LED and a switch equals railroad crossing lights.

  • 6,188 views
  • 5 comments
  • 9 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

Arduino Pedestrian Crossing Traffic Lights

by NatalMakers

  • 13,857 views
  • 0 comments
  • 23 respects

PIR Automated Intelligent Zebra Crossing

Project showcase by Adersh B

  • 8,000 views
  • 3 comments
  • 17 respects

Model Railroad Grade Crossing Controller

Project in progress by KevinMcArthur

  • 5,538 views
  • 0 comments
  • 21 respects

Police Chaser Lights

Project showcase by Jolynn Awesome

  • 16,886 views
  • 2 comments
  • 31 respects

Traffic Lights Controlled by Arduino

Project showcase by lmsousa

  • 10,585 views
  • 2 comments
  • 21 respects

How to Configure NeoPixels Using Vixen Lights and Arduino

Project tutorial by Victor Aguilar

  • 55,563 views
  • 44 comments
  • 86 respects
Add projectSign up / Login