Arduino Traffic Light Controller

Made a simple traffic light controller with an Arduino Uno and a few resistors for a model railroad. I would eventually like to try this out with a Walthers traffic signal or other similar model. Check out the full article for the complete code and video demo.

The setup for this is fairly simple as the Ardiuno is the brains behind this traffic light controller. Digital pins 8 thru 13 go to the positive lead, with a 220 Ohm resister, on the each LED and the negative lead is hooked up to the ground. In my example I used a breadboard and some jumper wires to mock this up.

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() { 

void ChangeLights() { 
digitalWrite(green1, LOW); 
digitalWrite(yellow1, HIGH); 
digitalWrite(yellow1, LOW); 
digitalWrite(red1, HIGH); 
digitalWrite(yellow2, LOW); 
digitalWrite(red2, LOW); 
digitalWrite(green2, HIGH); 
digitalWrite(green2, LOW); 
digitalWrite(yellow2, HIGH); 
digitalWrite(yellow2, LOW); 
digitalWrite(red2, HIGH); 
digitalWrite(yellow1, LOW); 
digitalWrite(red1, LOW); 
digitalWrite(green1, HIGH); 

If you have any ideas on improving this code please let a comment here or on the video directly.

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