DIY Arduino LED Traffic Light Controller
By Ryan Jones
This Arduino-based traffic light controller will teach you some things about timing sequences on Arduino and works as an actual stoplight! The lighting sequence performed by the Arduino mimics a four-way intersection. This traffic light controller can also help children learn traffic signal patterns so they can learn to cross intersections.
- Arduino UNO (Most Arduinos should work)
- Red LEDs ×2
- Yellow (Amber) LEDs ×2
- Green LEDs ×2
- 330Ω Resistors ×6
Arduino Traffic Light Schematic Diagram
Originally, this was a simple LED project for people new to Arduino. We didn’t think it would be all that helpful in the United States, but somebody in a small village in Vietnam actually recreated the project with bigger LEDs to make a real traffic light! It goes to show that you never know who will find uses for electronics projects that you may not have thought to be very useful, which is why sharing is an important part of making! If you have an electronics project that you haven’t shared yet, feel free to share it on DIY Hacking!
You never know who your projects can help, so share away!
This project is also a good introduction to LED projects with the Arduino, like the ones below!
Arduino LED Projects
How Does it Work?
It’s really a simple concept and the table below helps to explain it. The code uses For loops and delay statements in order to implement the on-time for each of the LEDs.
The two streets in our example are Busy Bunny Lane and Lazy Tortoise Avenue. They each have different traffic volumes, so one has a longer green light (and a shorter red light).
Busy Bunny Lane is pretty . . . busy. The green light for Busy Bunny Lane stays on for 12 seconds. Lazy Tortoise Avenue has much less traffic, so our hypothetical city has declared that it needs a green light that stays on for only one-third of the time that Busy Bunny’s green light stays on. So Lazy Tortoise Avenue gets a 4-second green light. Fair is fair.
As Busy Bunny Lane switches from green to yellow to red, Lazy Tortoise Avenue briefly maintains its red light in case there are stragglers who try to make a last-minute dash through the intersection. Don’t forget about this red-light-overlap interval if you ever design the traffic light system for your town’s newest intersection. When the coast is clear, Lazy Tortoise Avenue gets the green light it has been patiently waiting for.
This chart will help you understand the traffic light timing. Taken from Joseph Corleto’s Arduino traffic light tutorial.
When Lazy Tortoise Avenue reaches its red light stage, there is another period of red-light-overlap, and then the loop restarts! This is a pretty basic and antiquated traffic light. Modern traffic lights today are “smart”—they can detect vehicles, adjust their timing, and even make interruptions for crosswalks. There is always room for improvement!
We’d love to see readers take this project and modify it to make it their own. Maybe turn this boring intersection into a “smart” one by adding a crosswalk interruption button! You can even change the light patterns based on the time of day! Take this knowledge and run with it, and remember to share your creations!