Teeny weeny traffic lights

Hi there!

I’m Carolina and this is my first electronics project for the Inner Geek.

On a weekend at home I had an idea, I wanted to make a model traffic light for cars and pedestrians like the ones you see on the street. I wanted to do this project to learn a little bit more about electronics and to have fun.

So, How does it work?

There are two sets of lights in this project: One for cars and one for pedestrians. There is also a button to let pedestrians cross the street.

Electronic diagrams, flowchart and prototype.

The story behind my Project.

My technology teacher asked us to make a traffic light project at school in groups, but I wanted to try to do it by myself at home because there I have more tools, materials, and time. I had learned about the Arduino before, but there were other things that I didn’t know like how to solder and isolate wires so they don’t short.

Luckily, during the project, there were no disasters, like shorts or burns, but there was a mistake. At first, when I tried to run the circuit, everything seemed to be going well: the LEDs were turning on and off correctly, except for the red LED in the pedestrian traffic light. It didn’t take me long to figure out the mistake. It turns out I had inverted the LED: the Cathode was connected to positive and the Anode was connected to ground. Such an easy mistake to make. I de-soldered the LED and re-soldered it the right way round. After that, the traffic light worked perfectly.

Traffic lights making of video

What you need to make this project:

  • Arduino Pro micro board
  • 2 green LEDs
  • 2 red LEDs
  • 1 yellow LED
  • 1 button
  • a 9v battery
  • a battery holder
  • 4 220Ω resistor

The Code

// (c) Carolina Carvalho 2021

#define GREEN_CARS 2
#define RED_CARS 4
#define YELLOW_CARS 3
#define GREEN_PEDESTRIAN 5
#define RED_PEDESTRIAN 6
#define BUTTON 7
#define BUTTON_LED 8

void setup()  {
  pinMode(GREEN_CARS, OUTPUT);
  pinMode(RED_CARS, OUTPUT);
  pinMode(YELLOW_CARS, OUTPUT);
  pinMode(GREEN_PEDESTRIAN, OUTPUT);
  pinMode(RED_PEDESTRIAN, OUTPUT);
  pinMode(BUTTON, INPUT);
  pinMode(BUTTON_LED, OUTPUT);

}

// Turn off all LEDs
void turn_off() {
  digitalWrite(RED_CARS, LOW);
  digitalWrite(YELLOW_CARS, LOW);
  digitalWrite(GREEN_CARS, LOW);
  digitalWrite(GREEN_PEDESTRIAN, LOW);
  digitalWrite(RED_PEDESTRIAN, LOW); 
  digitalWrite(BUTTON_LED, LOW);
}

void loop(){
  turn_off();
  digitalWrite(GREEN_CARS, HIGH);
  digitalWrite(RED_PEDESTRIAN, HIGH);

  // Waits for button press
  while (digitalRead(BUTTON) == HIGH) {
    // Do nothing
  }

  // Start pedestrian count down
  digitalWrite(BUTTON_LED, HIGH);
  delay(500);
   digitalWrite(BUTTON_LED, LOW);
  delay(500);
   digitalWrite(BUTTON_LED, HIGH);
  delay(500);
   digitalWrite(BUTTON_LED, LOW);
  delay(500);
   digitalWrite(BUTTON_LED, HIGH);
  delay(500);
   digitalWrite(BUTTON_LED, LOW);
  delay(500);
   digitalWrite(BUTTON_LED, HIGH);
  delay(500);
   digitalWrite(BUTTON_LED, LOW);
  delay(500);
   digitalWrite(BUTTON_LED, HIGH);
  delay(500);
   digitalWrite(BUTTON_LED, LOW);
  delay(500);
  
  turn_off();
  digitalWrite(YELLOW_CARS, HIGH);
  digitalWrite(RED_PEDESTRIAN, HIGH);
  delay(3000);
  
  turn_off();
  digitalWrite(RED_CARS, HIGH);
  digitalWrite(GREEN_PEDESTRIAN, HIGH);
  delay(5000);
  
  turn_off();
  digitalWrite(RED_CARS, HIGH);
  digitalWrite(GREEN_PEDESTRIAN, HIGH);
  delay(500);
  digitalWrite(GREEN_PEDESTRIAN, LOW);
  delay(500);
  digitalWrite(GREEN_PEDESTRIAN, HIGH);
  delay(500);
  digitalWrite(GREEN_PEDESTRIAN, LOW);
  delay(500);
  digitalWrite(GREEN_PEDESTRIAN, HIGH);
  delay(500);
  digitalWrite(GREEN_PEDESTRIAN, LOW);
  delay(500);
}

In Conclusion

This traffic light was cool to make, quick, and in my opinion it was quite easy. I recommend making this project because it is not only fun, but it’s cool to show your friends and family this nice, little project.