Arduino Traffic Light

About: hIOTron is an IoT Based company that offers IoT Platforms, IoT Solutions, IoT Training.

The system must be used to control the traffic lights for the smooth and safe movement of traffic.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components and Supplies

Arduino Uno

Resistor 10k ohm

Resistor 220 ohm


Connecting wires


Green LED

Yellow LED


Step 2: Steps to Follow

Traffic Lights are indicating devices that are used to control the flow of traffic. Generally, they are located at junctions, ‘X’ roads, pedestrian crossings, etc. and alternate the priority of who has to wait and who has to go.

The traffic lights will give instructions to the users (drivers and pedestrians) by showing lights of standard color. The three colors generally used in traffic lights are Red, Yellow and Green.

Connect the anode of each LED to digital pins eight, nine and ten (via a 220-ohm resistor). Connect the cathodes to the Arduino’s ground. Design a Code for Arduino Traffic Light Start by assigning variables so that you can address the lights by name rather than a number.

Next, add the setup function, where you’ll configure the red, yellow and green LEDs to output. As you have created variables to represent the pin numbers, you can mention to the pins by name instead.

The pinMode function configures the Arduino to use a given pin as an output. Now for the actual logic of the traffic light. Below is the code that you need. Upload the code to your Arduino and run (make sure to select the correct board and port from the Tools > Board and Tools > Port menus). The final outcome should have a working traffic light that changes every 15 seconds. The Internet of Things Course Training will help you to implement your own ideas and to build an IoT Application over several challenges.

Step 3: Run a Program

int red = 10;

int yellow = 9;

int green = 8;

void setup() {

pinMode(red, OUTPUT);

pinMode(yellow, OUTPUT);

pinMode(green, OUTPUT);


void loop(){




void changeLights(){

// green off, yellow on for 3 seconds

digitalWrite(green, LOW);

digitalWrite(yellow, HIGH);


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

digitalWrite(yellow, LOW);

digitalWrite(red, HIGH);


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

digitalWrite(yellow, HIGH);


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

digitalWrite(yellow, LOW);

digitalWrite(red, LOW);

digitalWrite(green, HIGH);

delay(3000); }

Step 4: The Final Arduino Traffic Light

Be the First to Share


    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest