🐷Catto← Back to home

🚦 Traffic Light with Logic Gates

A traffic light for a two-street intersection built with 4000-series chips: an NE555 provides the clock, a binary counter counts the seconds and a few gates decide which light is on at each moment. The complete project, from the schematic to the breadboard.

Digital Techniques · Six ICs · The simulation runs on the same circuit that is drawn.

The intersection

Street A runs from left to right and street B from top to bottom. The cars obey what the traffic lights show: they stop at red and at yellow, unless they are already so close to the line that they cannot stop in time. Drag to rotate the view and use the wheel to zoom in.

Timing diagram of a full cycle

The sixteen counter states, one per clock pulse. The blue band marks where the circuit is right now.

State table

The counter runs through states 0 to 15 and starts over. The first half of the cycle belongs to street A and the second to street B; in each half, the last two states are yellow. The highlighted row is the one the simulation is showing.

Complete schematic

The wires carrying logic signals change color with the simulation: green is a high level and dark gray is a low level. The small numbers next to each pin are the IC’s pin numbers. On a phone, the drawing scrolls sideways.

Clock State 0 · 0000

How to read it

  • U1, the NE555, oscillates as an astable: R1, R2 and C1 set a period of one second.
  • U2, the CD4520, advances one state on each rising edge of the clock. Pushbutton S1 returns it to zero; R3 holds the reset low while it is not pressed.
  • U3A and U4A build the auxiliary signals: \( \overline{Q_4} \) and F, and from F comes \( \overline{F} \) through U3B. All four run down the vertical bars.
  • Six AND gates, one per light, take from the bars what each equation calls for.
  • U6, the ULN2003A, turns on the LEDs: each output pulls the cathode of the corresponding LED to ground.

What is not drawn

  • The power supply of U3, U4 and U5: pin 14 to +9 V and pin 7 to ground on all three.
  • A 100 nF capacitor between +9 V and ground next to each IC, and a 100 µF electrolytic at the power input.
  • Unused inputs: those of U3C to U3F and of U5D go to ground. In CMOS a floating input takes any value and makes the IC draw current.
Why the reds go through a gate. Red A is Q4 and Red B is \( \overline{Q_4} \): they could go straight to the ULN2003A. But each ULN2003A input draws about 3 mA, and a CMOS output delivering that current has its voltage drop. Q4 and \( \overline{Q_4} \) also feed other gates, which need a clean high level. U5B and U5C, with their two inputs tied together, act as a buffer.

How many ICs are needed

6ICs in total
1NE555 · clock
1CD4520 · counter
1CD4069 · 2 of 6 inverters
2CD4081 · 7 of 8 ANDs
1ULN2003A · 6 of 7 channels

Each drawing is the IC seen from above, with the notch at the top: pin 1 is at the top left and the numbering runs counterclockwise. The color of each pin follows the simulation: green for high, gray for low, orange for +9 V, blue for ground.

Connection list

When building on the breadboard it helps to check them off one at a time. “U4·12” means pin 12 of U4.

Bill of materials

The clock: NE555 as an astable

\( t_{\text{high}} = 0.693\,(R_1 + R_2)\,C_1 \) \( t_{\text{low}} = 0.693\,R_2\,C_1 \)
\( T = t_{\text{high}} + t_{\text{low}} = 0.693\,(R_1 + 2R_2)\,C_1 \) With R1 = 10 kΩ, R2 = 68 kΩ and C1 = 10 µF, T ≈ 1.01 s. The counter advances on rising edges, so it does not matter that the high time is longer than the low time.

All the traffic light times are multiples of T: green 6 T, yellow 2 T and red 8 T. If R2 is replaced by a 100 kΩ trimmer in series with a fixed 22 kΩ resistor, the full cycle can be adjusted without changing the proportion between the lights.

Building in stages

  1. Power supply. A 9 V battery or power supply with the 100 µF electrolytic. Measure before putting in any IC.
  2. Clock. Build the NE555 and test pin 3 with an LED and a 1 kΩ resistor to ground: it should blink once per second.
  3. Counter. Add the CD4520 and watch Q1 to Q4 with test LEDs: they should count in binary. Q4 changes every 8 seconds.
  4. Decoder. Add the CD4069 and the two CD4081s. With a multimeter, F should go high in states 6, 7, 14 and 15.
  5. Lights. Add the ULN2003A, the six 470 Ω resistors and the LEDs. With the reset pushbutton you always start from the green of street A.

Testing each stage before moving on to the next saves a lot of time: if something fails, the error is in the last thing that was added.

Care with the 4000 family

  • CMOS ICs are damaged by static electricity: touch something connected to ground before handling them and keep them in their tube or in conductive foam.
  • No input may be left floating. Those not in use go to ground or to +9 V.
  • Never apply a signal to an input while the IC is unpowered.
  • The operating voltage of the 4000 series runs from 3 to 15 V; the NE555, from 4.5 to 16 V. At 9 V both are comfortable.

Going further

Three improvements to tackle with the same circuit as a base:

  • All red. At real intersections there is an instant with both streets at red between one phase and the other, so that whoever went through on yellow can finish crossing.
  • Flashing yellow. A switch that, at night, turns off the greens and reds and makes the yellows blink with the clock.
  • Pedestrian pushbutton. Have the light stay green for street A until someone requests it from street B.