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

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 *

*