Build Your Own Arduino-Powered Model Railroad Traffic Light System

Model railroading is a great hobby that allows you to create miniature worlds that are both fun and educational. But if you’re looking to add a touch of realism to your layout, why not try building your own Arduino traffic light controller?

With an Arduino Uno, a few 220 Ohm resistors, and some scale traffic lights you can easily create a traffic light controller that will make city look alive. The setup is simple: the Arduino controls the LEDs on the traffic lights, and the resistors help to tone down the LEDs.

In my example, I used a breadboard and some jumper wires to mock up the traffic light controller. But you could easily mount the Arduino and the LEDs on a piece of perfboard, a 3D printed enclosure, or even a piece of plastic.


Once you have the hardware set up, you’ll need to write some code. The code is pretty simple, and I’ve included it in the full article. But basically, the code just tells the Arduino how to turn on and off the LEDs in sequence for the traffic lights.

Code for Arduino
// Traffic Light Controller 
// Merrimack Valley Railroad - 2017 
// Light one 
int red1 = 10; 
int yellow1 = 9; 
int green1 = 8; 

// Light two 
int red2 = 13; 
int yellow2 =12; 
int green2 = 11; 

void setup() { 
// Light One 
pinMode(red1, OUTPUT); 
pinMode(yellow1, OUTPUT); 
pinMode(green1, OUTPUT); 

// Light Two 
pinMode(red2, OUTPUT); 
pinMode(yellow2, OUTPUT); 
pinMode(green2, OUTPUT); 
} 

void loop() { 
ChangeLights(); 
} 

void ChangeLights() { 
digitalWrite(green1, LOW); 
digitalWrite(yellow1, HIGH); 
delay(3000); 
digitalWrite(yellow1, LOW); 
digitalWrite(red1, HIGH); 
digitalWrite(yellow2, LOW); 
digitalWrite(red2, LOW); 
delay(500); 
digitalWrite(green2, HIGH); 
delay(7000); 
digitalWrite(green2, LOW); 
digitalWrite(yellow2, HIGH); 
delay(3000); 
digitalWrite(yellow2, LOW); 
digitalWrite(red2, HIGH); 
digitalWrite(yellow1, LOW); 
digitalWrite(red1, LOW); 
delay(500); 
digitalWrite(green1, HIGH); 
delay(7000); 
}

Once the code is written, you can upload it to the Arduino and start using your traffic light controller. The controller will work with any three LED light traffic lights.

So what are you waiting for? Build your own Arduino traffic light controller today and add a touch of realism to your model railroad!

One Comment, RSS

Your email address will not be published. Required fields are marked *

*