Arduino Traffic Light

How to use Arduino to make a model traffic light.
For more on using Arduino on a Model Railroad Cilck On Arduino Model Railroad Projects.

This tutorial is part of our series Arduino Projects. There is a video playlist at Playlist

 

 

Sketch

// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
int DELAY_GREEN = 5000;
int DELAY_YELLOW = 2000;

int DELAY_RED = 5000;

// basic functions

void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}

void loop()
{
green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);
}

void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}

void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}

void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}

Wiring Instructions

There are total of 12 LED’s used in this project. Each signal has 3 LED’s (Red, Yellow and Green) connected to it through the 220 ohm resistors. The resistors are used to limit the current that is going to pass through the LED’s. If you won’t use the resistors then the LED’s may burn due to excessive current.

Wiring Diagram













This project is part of our Arduino Tutorial Series

Information in this page is summarized from this.
Tell others about this information by using one of these services. Thank you for the support.
Scroll to top