Arduino traffic light example

This was a a simple board that I bought which basically consists of a red, yellow and green LED on a board, rather than buying seperate components and using a breadboard this is a reasonably low cost solution.

 

Code

In the example we use Pin 5 , 6 and 7 for the green, yellow and red LEDs

 

[codesyntax lang=”cpp”]

byte pinLedRed = 7;
byte pinLedYellow = 6;
byte pinLedGreen = 5;

void setup()
{
    // Initialize the pins as output pins
    pinMode(pinLedRed, OUTPUT);
    pinMode(pinLedYellow, OUTPUT);
    pinMode(pinLedGreen, OUTPUT);
}

void loop()
{

    //Red signal
    digitalWrite(pinLedRed, HIGH); // RED on
    delay(5000); // 5 secs

    //Yellow + Red
    digitalWrite(pinLedYellow, HIGH); // YELLOW on
    delay(1000); // 1 sec

    //Green signal
    digitalWrite(pinLedRed, LOW); // RED  off
    digitalWrite(pinLedYellow, LOW); // YELLOW off
    digitalWrite(pinLedGreen, HIGH); // GREEN  on
    delay(5000); // 5 secs

    //Yellow signal
    digitalWrite(pinLedGreen, LOW); // GREEN  off
    digitalWrite(pinLedYellow, HIGH); // YELLOW  on
    delay(1000);
    digitalWrite(pinLedYellow, LOW); // YELLOW  off

}

[/codesyntax]

 

Link

The traffic light board only costs about $1

LED traffic lights light-emitting module / digital signal output Traffic light module / electronic building blocks

Related posts

Arduino and GY-21P readings on a web page

MPL3115A2 sensor readings displayed on a web page

Adafruit Neopixel shield examples