Traffic Light Control Using Arduino
by Thingerbits in Circuits > Arduino
728 Views, 3 Favorites, 0 Comments
Traffic Light Control Using Arduino
In this tutorial, we will take a look at building an Arduino traffic light circuit. very simple circuit that’s great for beginners
This is a great beginner project if you have only just bought your first Arduino or looking at buying one. Check out the equipment list a bit further down the page for everything you will need in this project.
Even though the traffic lights are extremely basic, it’s a great way to introduce yourself or others to the basics of electronics and coding.
This tutorial will provide you with a basic understanding of connecting circuitry to the Arduino and show some basics of coding.
Supplies
- Arduino UNO ×1
- LED Traffic Lights Signal Module ×1
- male to male jumper wire ×4
Schematics
- Connect the LEDs to the Arduino using the following connections:
- Red LED: Pin 2
- Yellow LED: Pin 3
- Green LED: Pin 4
- If you use 5mm LED Connect a 220-ohm resistor to the longer (anode) leg of each LED and the other end of the resistor to the ground (GND) on the Arduino.
Write the Arduino Code
int red = 2;
int yellow = 3;
int green = 4;
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop(){
digitalWrite(red, HIGH);
delay(15000);
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(green, HIGH);
delay(20000);
digitalWrite(green, LOW);
//
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
}
- Open the Arduino IDE on your computer.
- Copy and paste the code into the IDE.
- Select the correct board and port from the Tools menu.
- Click the "Upload" button to upload the code to your Arduino.
Test the Traffic Light System
After uploading the code, you should see the LEDs simulate a traffic light system with the following sequence: Red -> Red and Yellow -> Green -> Yellow. The cycle will then repeat.
Troubleshooting
If the circuit is not working as expected, double-check your connections, resistor values, and the code. Make sure the LEDs are connected with the correct polarity (longer leg to the resistor).
Expand and Experiment
Feel free to modify the code or add more features to the project. You can include a pedestrian signal, add a button for manual control, or use sensors for a more advanced traffic light system. Good luck with your Traffic Light Control System using Arduino!