How The Heck Do Traffic Lights Work?

How Victorian railway semaphores evolved into modern traffic systems.

Shri Khalpada

Shri Khalpada

Part of How The Heck?, a series of interactive explanations of everyday technology designed primarily for curious, non-technical readers.
If you like these, you can follow the author, buy him a coffee, or suggest what comes next.

Recently I was out on a walk, thinking about what the next entry in this series should be. I had a few ideas bouncing around in my head, but nothing particularly stuck.

Keeping in mind the spirit of this series, I looked around my neighborhood and something hit me: I had no idea how traffic lights work.

It felt like a great "what's actually going on here?" type of question, so I started researching and was surprised by how much I didn't know. This piece goes down the rabbit hole of traffic lights, from their Victorian origins to the inductive loops in our roads, and the networked systems that control them today.

Lights, Camera, Action

TL;DR
Traffic lights inherited their colors from railway signals: red meant stop, green eventually became go, and yellow became the warning in between. Red also travels farther through fog and smoke because longer wavelengths scatter less.

The railway semaphore

The story of how we landed on red, yellow, and green is a combination of human psychology, failed designs, and a bit of physics.

To start, let's take a step back and look at the history of traffic lights. By the time cities started wrestling with the chaos of horse-drawn traffic in the mid-1800s and had a need for signaling traffic commands to drivers, they were able to borrow from a visual system used by railroads for decades: the semaphore.

Originally designed for long stretches of open countryside, the semaphore used large mechanical arms that could be raised and lowered to signal whether the track ahead was clear. Operators would communicate via telegraph about the state of the track ahead and adjust the arm position accordingly. Train drivers would read the arm position as they approached: horizontal meant stop, an angled position indicated caution, and vertical meant go.

Horizontal (0°)
Stop
Angled Up (45°)
Caution
Vertical Up (90°)
Go

This system worked well during daylight, but it was impossible to see the semaphore arm at night or in bad weather. To solve this, the semaphore was equipped with a constantly burning lantern behind the arm's pivot point. A metal bracket, called a spectacle, held colored or clear glass discs and was attached to the base of the arm, so each arm position swung a different lens in front of the flame. Each state corresponded to a different color, with white light indicating "go".

Stop

There was a big problem: if something went wrong with the spectacle or the lens, the light would always appear white even when the arm was horizontal. This was a disaster waiting to happen, and eventually it did. In 1876 at Abbots Ripton, a village in England, snow and ice kept the signals from fully moving to danger, causing them to show white. The driver of the Scotch Express later reported he had seen "nothing but white lights all the way from Peterboro" before crashing into a coal train, killing 13 people.

Eventually, we phased out white altogether and settled on the colors we're familiar with today: red for danger, yellow for caution, and green for go.

EraStopCautionGo
1840sRedWhite
1850s–60sRedGreenWhite
1870s+RedYellowGreen

The first traffic light

In December 1868, the world's first traffic light was installed outside the Houses of Parliament in London. John Peake Knight, a railway engineer, was given the task of designing it. His solution was essentially to take the same semaphore system from the railroads and mount it on a street corner.

A few weeks after it was installed, a gas line connected to the traffic light exploded, destroying the device and badly burning the police constable operating it. The project was abandoned, and traffic lights disappeared from London's streets entirely. Although this design saw gradual adoption elsewhere, the traffic light didn't return to London until 1926, nearly 60 years later, with the help of electricity.

Red turns out to be a good choice for "stop"

When British railway managers met in 1841 to standardize their signaling colors, the choice of red was almost inevitable. Red had meant danger for centuries in the western world, from naval warning flags to the color of blood itself, and empirically, people had long observed that red light carried further than other colors in poor conditions.

It wasn't until decades later that physics provided a more formal explanation: red possesses the longest wavelength in the visible spectrum, which is why it scatters least through fog and smoke.

Red · 700nmAmber · 590nmGreen · 520nm
cleardense
Longer wavelengths scatter less and reach further through fog.
Why do longer wavelengths scatter less?

There are a couple of different but related effects at play.

Rayleigh scattering happens when particles are much smaller than the wavelength of light, like air molecules. It's why the sky is blue: shorter wavelengths scatter more, so blue light bounces all over the atmosphere while red light passes through.

Mie scattering happens when particles are closer in size to the wavelength, like fog droplets, dust, or smoke. That's the better description for traffic lights in fog. It's less wavelength-dependent than Rayleigh scattering, but longer wavelengths still tend to fare better.

In both cases, the underlying reason is similar: smaller particles interact more strongly with shorter wavelengths, which are closer to their own size. Longer wavelengths are simply too large to be significantly deflected, so they pass around small particles rather than bouncing off them.

Lights, Camera, Action

TL;DR
Many traffic lights run on simple timers, but others use a variety of techniques to detect vehicles and pedestrians. Each approach has its own strengths and limitations. For example, inductive loops work well regardless of the weather but require cutting into the road to install. Lidar is the most precise but is the most expensive and can be degraded by bad weather.

The sensors

There isn't much data on the exact breakdown, but I was surprised to learn that a 2024 study by the University of Michigan mentions that "most intersections are controlled by fixed-time traffic signals that are not regularly optimized".

For the intersections that do have sensors, there are a few technical approaches to detecting vehicles. Different technologies have emerged over the decades, each with different tradeoffs in cost, accuracy, robustness to weather, and fidelity of detection.

The sensor data is fed as input into a controller, a computer housed in a metal cabinet near the intersection. The controller is programmed with timing plans for different times of day, for example: a morning rush hour plan, a midday plan, a late night plan. When a sensor detects a vehicle, the controller decides what to do with that information.

Lights, Camera, Action

TL;DR
Traffic lights use strategies ranging from simple fixed timers to complex adaptive algorithms that optimize for a couple things: minimizing the time cars spend waiting at red lights, and minimizing the amount of time green lights are wasted on empty roads. When we factor in the complexity of real traffic patterns, the optimization problem becomes combinatorially complex. Systems like SCATS and SCOOT help us get a reasonably good solution.

The Green Wave

Even without sensors, networks of traffic lights can be coordinated thoughtfully. One example is the green wave, where lights are timed so that if you drive at a certain speed, you'll hit green lights all along a corridor.

In an ideal system, a couple things would be minimized as much as possible: the time cars spend waiting at red lights, and the amount of time green lights are wasted on empty roads. The green wave is an elegant approach to the first problem.

In practice, picking the ideal offset between consecutive lights is a complex optimization problem. It depends on the distance between lights, the speed limit, how many other vehicles can enter the road between lights, and more. For more detail than we go into here, the Wikipedia page walks through the math.

Adaptive systems

For traffic lights that do have sensors, the most basic approach is to augment a fixed timing plan with a few simple rules. For example, if a sensor detects traffic waiting on a red light and no cars are detected on the green, the controller can cut the green short and switch to red sooner.

How does the simulation work?

This is a sped-up, simplified version of what a real adaptive controller does. Each cycle here is about 14 seconds: 5 seconds of green per direction, a 1 second yellow at the end of each, and a 1 second “all red” clearance where both signals are red to let the intersection empty out before the other direction gets the green. Real cycles are usually 60 to 120 seconds long.

While a cycle runs, the controller watches both approaches and remembers the most cars it saw waiting on each side. At the end of the cycle, it compares the two and shifts some green time toward whichever direction was busier (up to 2 seconds, in either direction). There is also a small pull back toward an even 5/5 split each cycle, so any borrowed time has to be re-earned. In other words, the algorithm wants to keep the even split, and will only deviate from that if the traffic continues to be imbalanced.

On top of that, if the active green is sitting empty and the other side has cars stacking up, the controller cuts the wasted green short instead of waiting for the next cycle to react.

We can scale that up to a grid. Every intersection runs the same adaptive loop independently, borrowing and donating green time based on the traffic it sees.

In a real system using sensors, a kind of "distributed coordination" emerges. Each traffic light can take the current state of its neighbors into account as part of its decision making. A controller is taking into account the time of day, what it senses at its own intersection, and what's going on down the road at the next light over.

Real-world implementations of this approach include SCOOT (developed in the UK) and SCATS (developed in Australia), which are deployed in cities around the world. SCOOT works by making small incremental adjustments to offsets, cycle times, and splits across the network. SCATS is a bit more distributed and chooses between a few pre-defined timing plans at the individual controller level, rather than making small adjustments to a single plan across the network.

When you factor in the complexity of real traffic patterns: multidirectional traffic, pedestrians, cyclists, emergency vehicles, and more, the optimization problem becomes combinatorially complex. Systems like SCATS and SCOOT help us get a reasonably good solution given the constraints of real-world traffic, even if it doesn't always feel that way during rush hour!

Hidden complexity

The amount of invisible complexity and coordination in the world never ceases to amaze. Every time I stop at a traffic light, I'm looking at a red light because we learned over a century ago that's a psychologically and physically optimal signal for "stop". A wire underneath me is detecting my car and feeding that information to a local controller. That local controller may shave off a few seconds of green time for the empty cross street, and relay information about what it just did to the next light down. All of this happening in a fraction of a second, every time I stop at an intersection.

The best part about infrastructure like this is that, since it usually does a good job, we don't have to think about it. But when we do, it can be fascinating.

Thank you!

If you like this type of content, you can follow me on BlueSky. If you wanted to support me further, buying me a coffee would be much appreciated. It helps us keep the lights on and the servers running!

We're just getting started.

Subscribe for more thoughtful, data-driven explorations.