Arduino 4 Way Traffic Light

How to build an Arduino based 4 way traffic light for model railroads.

A fast and easy way to give your layout a bit more life with operating traffic lights keeping eyes occupied.

Materials Required To Make Traffic Lights

To set up on breadboard

Arduino Uno Or Mega

LEDs – For HO and OO scales, 3 mm .  For  TT and n scales, consider SMD Leds

Resistors – At least 200 ohm. 1/4 watt is fine.

To Build Scale Model Traffic Light Equipment

Most people buy ready made or kits.  For the scratch builder I will be posting a tutorial on making your own.

 

The Arduino Sketch For Traffic Lights On Four Corners

Copying from a web page results in Unicode characters being used.  Arduino IDE requires ASCI.     Copy this, paste it in Notepad and save as a text file. That results in ASCI. That text can be added to the IDE and then save that as an ino file.

[code]
//traffic lights 4 corners
// by Gary Granai
//www.steamtrainfo.com/arduino-projects
//updated 11 April 2021
//free to use as long as these credits stat in place.

void setup()
{
//main road lights
pinMode(13, OUTPUT); //main road red
pinMode(12, OUTPUT); //main road yellow
pinMode(11, OUTPUT); //main road green

pinMode(4, OUTPUT); //main road red
pinMode(3, OUTPUT); //main road yellow
pinMode(2, OUTPUT); //main road green

//crossing road lights
pinMode(10, OUTPUT); //cross road red
pinMode(9, OUTPUT); //cross road yellow
pinMode(8, OUTPUT); //cross road green

pinMode(7, OUTPUT); //cross road red
pinMode(6, OUTPUT); //cross road yellow
pinMode(5, OUTPUT); //cross road green

}

void loop() {
digitalWrite(13, HIGH); //main road red on
digitalWrite(8, HIGH); //cross road green on
digitalWrite(10, LOW); //cross road red off

digitalWrite(4, HIGH); //main road red on
digitalWrite(5, HIGH); //cross road green on
digitalWrite(7, LOW); //cross road red off

delay(6000);

digitalWrite(13, HIGH); //main road red on
digitalWrite(8, LOW); //cross road green off
digitalWrite(9, HIGH); //cross road yellow on

digitalWrite(4, HIGH); //main road red on
digitalWrite(5, LOW); //cross road green off
digitalWrite(6, HIGH); //cross road yellow on
delay(3000);

digitalWrite(13, HIGH); //main road red on
digitalWrite(10, HIGH); //cross road red on
digitalWrite(9, LOW); //cross yellow off

digitalWrite(4, HIGH); //main road red on
digitalWrite(7, HIGH); //cross road red on
digitalWrite(6, LOW); //cross yellow off

delay(2000);

// change travel lanes

digitalWrite(13, LOW); //main road red off
digitalWrite(10, HIGH); //cross road red on
digitalWrite(11, HIGH); //main road green on

digitalWrite(4, LOW); //main road red off
digitalWrite(7, HIGH); //cross road red on
digitalWrite(2, HIGH); //main road green on

delay(6000);

digitalWrite(10, HIGH); //cross road red on
digitalWrite(11, LOW); //main road green off
digitalWrite(12, HIGH); //main road yellow on

digitalWrite(7, HIGH); //cross road red on
digitalWrite(2, LOW); //main road green off
digitalWrite(3, HIGH); //main road yellow on

delay(3000);

digitalWrite(13, HIGH); //main road red on
digitalWrite(10, HIGH); //cross road red on
digitalWrite(12, LOW); //main yellow off

digitalWrite(4, HIGH); //main road red on
digitalWrite(7, HIGH); //cross road red on
digitalWrite(3, LOW); //main yellow off

delay(2000);
}

[/code]

Wiring Instructions For Arduino Traffic Lights On Four Corners

Wiring is very simple.

The cathods of LEDs for traffic lights  for main road traffic are connected to pins 2, 3, 4, 11, 12, 13

The cathods of LEDs for traffic lights for main crossing traffic are connected to pins  5, 6, 7, 8, 9, 10.

The anodes are all connected to ground, (it can be a common ground on your circuit board0 via a resistor.  Each LED connects to its own resistor.

Video Tutorial For Four Traffic Lights

Scale Model Tutorials Traffic Light Video
Click to watch video tutorial

Click on the image to the left or on this link to watch the Traffic Lights in Action.

 

 

 

 

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

Tell others about this information by using one of these services. Thank you for the support.
Scroll to top