Arduino Traffic Light

Introduction: 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.

Step 1: Components and Supplies

Arduino Uno

Resistor 10k ohm

Resistor 220 ohm

Breadboard

Connecting wires

Red LED

Green LED

Yellow LED

Switch

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(){

changeLights();

delay(15000);

}

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 4: The Final Arduino Traffic Light

3 People Made This Project!

Recommendations

  • Big and Small Contest

    Big and Small Contest
  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge
  • For the Home Contest

    For the Home Contest

2 Comments

0
fangying2003
fangying2003

3 years ago

I am a student in junior high, our computer midterm homework is to find a thing on this website. I choose your topic and our teacher said we need to write a lesson on this website too. So I first comment here to tell you that my lesson will be very similar like yours.

0
hIOTron IoT
hIOTron IoT

Reply 3 years ago

You are talking about this website or the topic on Arduino Traffic Light?