Arduino Traffic Light Timing Lesson

October 10, 2016 by Ryan Jones

The Traffic Light Controller enables you to gain control of your road rage with a sense of understanding!

The Traffic Light Controller enables you to gain control of your road rage with a sense of understanding!

We all have it to some degree and we all know somebody who has it worse than us—road rage! The Traffic Light Controller teaches you street smarts, giving you the knowledge to keep your road rage at bay. If you understand what's going on with the red light, maybe you'll be able to wait more patiently for the green light!



Traffic light setup using an Arduino, LEDs, and 330Ω resistors!


You see, my wife, Debra, and I love taking our Sunday drives but we're sick of sitting at red lights. I figured I could build something to control the traffic lights so we always have green.

I eventually realized that the original project was merely for LEDs and couldn't actually control a real traffic light, but I built the project anyway and thereby gained an understanding of why traffic lights can't switch from red to green solely for our driving convenience. The Traffic Light Controller helps keep Debra and me levelheaded in road-rage situations—ultimately saving our marriage!


Debra, Lazy T, Busy B, and Me!


It's really a pretty simple concept and makes even more sense with the chart below. The code uses For loops and delay statements to implement the on-time for each LED.

The two streets in our example, Busy Bunny Lane and Lazy Tortoise Ave, have different traffic volumes, and thus one has a longer green light (and a shorter red light).

Busy Bunny Lane is pretty . . . well, busy. It has a green light that stays on for 12 seconds. There is much less traffic on Lazy Tortoise, and the city has declared that it needs a green light that stays on for only one-third of the time of Busy Bunny's. So it gets a 4-second green light. Fair is fair.

As Busy Bunny switches from green to yellow to red, Lazy Tortoise briefly maintains its red light in case any stragglers try to make a last-minute dash through the busy intersection. So don't forget about this red-light-overlap interval if your mayor ever asks you to design the traffic light system for your town's newest intersection. When the coast is clear, Lazy Tortoise gets the green light it has been patiently waiting for.


This chart will help you understand the traffic light timing. Taken from the original project.


When Lazy Tortoise reaches its red light, there is another red-light-overlap period, and then the loop restarts! Of course, this is a pretty basic, antiquated traffic light. Modern traffic lights are "smart"—they detect vehicles, adjust their own timing, and make interruptions for crosswalks. There is always room for improvement!

Remember, MIT-i is filmed on set, in front of a live studio audience. The Traffic Light Controller, or any other MIT-i innovation, should not be used in a vehicle or while operating machinery. Road rage is not an excuse to fight with your loved ones.

We think it's great when viewers take our project, modify it, and make it their own. Turn this boring intersection into a "smart" one by adding a crosswalk interruption button! You can even change light patterns based on the time of day! Take this knowledge and run with it, and remember to share your creations!


Give this project a try for yourself! Get the BOM.


Other MIT-i Innovations:

  • Glenn Stewart October 10, 2016

    Coming from Sydney, this brings back memories for my parents. It’s exactly this type of issue that led to engineers in Sydney in the 60’s trying to resolve the issue. In the 70’s Sydney’s traffic system was completely overhauled with an automatic detection system called SCATS (Sydney Coordinated Adaptive Traffic System). In the past 40 years it’s been rolled out to 154 cities around the world including crazy traffic cities like Shanghai, Hong Kong and Tehran.

    Basically it uses sensors in the road to perform dynamic, real-time chases of traffic signals. No more road rage required. If Busy Bunny Lane is busy, and Lazy Tortoise Ave doesn’t have traffic, the light doesn’t change. You could technically get hours of continuous flow on the main road, until a car enters from the lighter street to trigger a change.

    It’s actually a lot more complex than this and worth looking into.

    Like. Reply
  • DakLak January 31, 2017

    Your two projects got me thinking - about my the village/hamlet in which I live, near Buon Ma Thuot, in DakLak Province in the Central Highlands of VietNam. The province has recently ‘improved’ the main highway to GiaLai that runs through our small blip on the road enabling massive tractor-trailers and tour buses to rip past..

    Always short of money, our school children were exposed to traffic thundering through and nothing except good hearing and fast legs to escape vehicular death, we needed traffic control. Exacerbating the problem was the fact that a painted pedestrian crossing was over the brow of a hill - hidden from traffic in one direction.

    After experimenting with your software, adding a few features such as outputs to flash lights, push-buttons for pedestrians to push-to-cross and an easy technician set interface panel, we now have a traffic light system that any Western country accepts as a given.

    My thanks to you for kicking me out of my somnambulance, forty+ children can now cross in safety!

    Like. Reply
    • Ryan Jones January 31, 2017
      Thank you for sharing! I am humbled that my project has been used for a bigger purpose! Feel free to share pictures and future information! - Ryan
      Like. Reply