Arduino Traffic Light controller

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

Public Chat
Similar projects worth following
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 be outputs. 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 working traffic light that changes every 15 seconds.

IoT Training will help you to implement your own ideas and to build a Customized IoT solutions over several challenges.

Live Demo of Arduino traffic Light.gif

The final outcome should have a working traffic light that changes every 15 seconds.

Graphics Interchange Format - 144.83 kB - 08/20/2019 at 09:47


  • 1 × Arduino Uno
  • 1 × 10k ohm resistor
  • 6 × 220ohm resistor
  • 1 × breadboard Electronic Components / Misc. Electronic Components
  • 1 × Connecting wires

View all 8 components

  • 1
    Run a Code
    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);

View all instructions

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates