Main Menu

Secondary Menu

Traffic Lights Prototype

The main objective of the project is to show people how traffic lights work and how arduino projects can be present in our daily lives.

based in project: https://www.makeuseof.com/tag/arduino-traffic-light-controller

Step 1: Take the Materials Needed

1 breadboard

1 arduino

Male-to-male wires

Red, green and yellow LED's

1 resistor

1 button

Step 2: Copy the Code Below in the Arduino Platform

int red = 10;

int yellow = 9;

int green = 8;

int button = 12; // switch is on pin 12

void setup(){

pinMode(red, OUTPUT);

pinMode(yellow, OUTPUT);

pinMode(green, OUTPUT);

}

void loop() {

if (digitalRead(button) == HIGH){

delay(15); // software debounce

if (digitalRead(button) == HIGH) {

// if the switch is HIGH, ie. pushed down - change the lights! changeLights(); delay(15000); // wait for 15 seconds

}

}

}

void changeLights(){

// green off, yellow on for 3 seconds

digitalWrite(green, LOW);

digitalWrite(yellow, HIGH);

delay(3000);

// turn off yellow, then turn red on for 5 seconds

digitalWrite(yellow, LOW);

digitalWrite(red, HIGH);

delay(5000);

// red and yellow on for 2 seconds (red is already on though)

digitalWrite(yellow, HIGH);

delay(2000);

// turn off red and yellow, then turn on green

digitalWrite(yellow, LOW);

digitalWrite(red, LOW);

digitalWrite(green, HIGH);

delay(3000);

}

Step 3: Start Putting the Male-to-male Wires

Make sure the correct male-to-male wires are connected in the breadboard, since the breadboard works in a way that all the holes in the same row are connected. Also, all the male-to-male wires need to be in the right entrance at the arduino to the code work.

Step 4: Now, the Resistors and the Button

Place the resistors and buttons connected to the male-to-male wires in the same row to make the code work. The button will work as a traffic button for pedestrians to change the light whenever they like. Connect the button to digital pin 12.

Step 5: The LED's Will Be Connected Now

The LED's have two different legs, one positive and one negative. The longer leg is the postive and the short leg is the negative. Connect the long leg of each LED to digital pins eight, nine, and ten via a 220? resistor. Connect the short leg to Arduino ground.