Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Zachary Haslam
Published © GPL3+

Arduino Traffic Light Simulator

Simulate a traffic light using an Arduino and LEDs! This project is super cool to watch and easy to make!

BeginnerFull instructions provided1 hour249,085
Arduino Traffic Light Simulator

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Any kind of 'Uno" will do. I have a Geekcreit Uno that works fine.
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
Male/Male required
×1
LED (generic)
LED (generic)
You will need red, green, and blue lights
×3
Arduino USB 2.0 data Cable
×1
Resistor 100 ohm
Resistor 100 ohm
Brown, Black, Brown
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Traffic Light Schematics

Code

Arduino Traffic Light Code

Arduino
// 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);
}

Credits

Zachary Haslam
1 project • 84 followers
My name is Zach, and I'm 15. I've been developing for aImost 4 years now. specialize in Python and Linux.

Comments