You get a bonus - 1 coin for daily activity. Now you have 1 coin

Online simulation of the crossroads with 4 traffic lights on atmega328p — 2 vehicle and 2 pedestrian heads, perpendicular flows circuit

A signalised crossroads on a single ATmega328P: 4 traffic lights — two vehicle heads (red/yellow/green) for two perpendicular directions and two pedestrian heads (red/green). While one direction goes on green, the perpendicular one stays red; pedestrians walk together with the vehicle flow parallel to them. The cycle includes a red+yellow phase and a common all-red gap for safety.

This page is a utility for simulating crossroads with 4 traffic lights on atmega328p — 2 vehicle and 2 pedestrian heads, perpendicular flows online with specified initial values.

The online circuit simulator allows you to model circuit behavior in real time. You can change circuit parameters, add new elements, and observe their interactions. This is a useful tool for learning and experimenting with electronic circuits.
⚡ Circuit Online 
Left-click — place/select · hover over an end (◯ highlights) and drag — stretch · wheel — zoom · middle-click — pan · double-click — settings

This circuit models a signalised crossroads of two perpendicular roads on a single ATmega328P microcontroller. Instead of a single traffic light, four heads work here: two vehicle lights (one per direction) and two pedestrian lights. One pair serves one direction, the other pair serves the perpendicular direction.

Microcontroller pin assignment:

  • Vehicles, direction 1 (e.g. North–South): red — D2, yellow — D3, green — D4.
  • Vehicles, direction 2 (perpendicular, East–West): red — D5, yellow — D6, green — D7.
  • Pedestrians along direction 1: red — D10, green — D11.
  • Pedestrians along direction 2: red — D12, green — D13.

Each of the ten LEDs is connected to its pin through a current-limiting resistor to ground, setting a safe operating current and protecting the microcontroller pins.

In setup() all ten lines are configured as digital outputs. The intersection logic lives in loop() and is built around the main safety rule: the green signals of the two perpendicular directions are never on at the same time. A pedestrian crossing gets its "walk" green only while the parallel vehicle flow is green, and it turns red in advance — before that flow switches to yellow.

The full cycle (about 10.8 s) runs through these phases:

  1. Direction 1 goes: vehicles 1 green, pedestrians 1 "walk"; vehicles 2 red, pedestrians 2 "don't walk".
  2. Clearing the intersection: pedestrians 1 switch to red, then vehicles 1 turn yellow.
  3. All-red: both vehicle lights red — a short safety gap.
  4. Direction 2 prepares: vehicles 2 show "red+yellow", then green; pedestrians 2 "walk".
  5. Clearing the intersection: pedestrians 2 red, then vehicles 2 turn yellow.
  6. All-red and preparation of direction 1 ("red+yellow"), after which the cycle repeats.

Phase durations are set by the constants GREEN_MS, YELLOW_MS, PREP_MS and ALLRED_MS and are timed with the delay() function. By editing them directly in the microcontroller properties inside the simulation environment, you can tune the green duration, the length of the pedestrian phase and the size of the safety gap, watching the intersection respond in real time.


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply