Traffic light with PLC timers

The traffic light is a classic PLC exercise because it is a sequence driven only by time. You will program red → green → yellow → red in Ladder, first with three chained TON timers and then with one timer and comparisons. Both are common in exams and both run in the simulator of Virtuino Circuits.

Open the ready-made circuit in the simulator

The sequence

PhaseLampTime
1Red10 s
2Green8 s
3Yellow3 s

A selector switch S1 on %I0.0 switches the traffic light on. When it is off, all lamps are off.

Wiring

  1. Open the app, place a PLC and choose S7-1200 CPU 1214C. Supply it from L1/N.
  2. Feed the inputs from 24 V DC: L+ → latching switch S1 → input .0; 1M → M.
  3. From Signalling place three indicator lamps and set their colours: H1 red on %Q0.0, H2 yellow on %Q0.1, H3 green on %Q0.2. Feed the output common 1L from L1 and wire the lamps to N.

Method 1: three chained timers

 Rung 1     %I0.0     T3                T1: TON PT = 10 s
 |-----------| |------|/|----------------[IN        Q]------|
 Rung 2      T1                         T2: TON PT = 8 s
 |-----------| |-------------------------[IN        Q]------|
 Rung 3      T2                         T3: TON PT = 3 s
 |-----------| |-------------------------[IN        Q]------|

 Rung 4     %I0.0     T1                              %Q0.0 RED
 |-----------| |------|/|---------------------------------( )-|
 Rung 5      T1       T2                              %Q0.2 GREEN
 |-----------| |------|/|---------------------------------( )-|
 Rung 6      T2                                       %Q0.1 YELLOW
 |-----------| |------------------------------------------( )-|
  • T1 starts when the switch is on and counts the red time. When it is done, T2 starts and counts the green time, then T3 counts the yellow time.
  • When T3 is done, its NC contact in rung 1 opens. T1 resets, and so do T2 and T3 because their inputs come from the previous timer. In the next scan T1 starts again: the cycle repeats forever.
  • The lamps are decoded from the timer outputs: red while T1 is not done, green between T1 and T2, yellow after T2.

Give each TON its name (T1, T2, T3) and its PT in the properties panel. A contact with the timer's name follows the timer output.

The ready-made example uses this method.

Method 2: one timer and comparisons

A single TON with PT = 21 s (10 + 8 + 3), reset by its own output, gives an elapsed time ET that runs from 0 to 21 s and starts again. Comparison contacts select the lamp:

 Rung 1   %I0.0     T1                    T1: TON PT = 21 s
 |---------| |------|/|--------------------[IN       Q]------|
 Rung 2   %I0.0   [ T1 < 10 ]                         %Q0.0 RED
 |---------| |-------[      ]----------------------------( )-|
 Rung 3   [ T1 >= 10 ]  [ T1 < 18 ]                   %Q0.2 GREEN
 |----------[        ]-----[      ]----------------------( )-|
 Rung 4   [ T1 >= 18 ]                                 %Q0.1 YELLOW
 |----------[        ]-----------------------------------( )-|

In the simulator a comparison contact closes when its condition is true; for a timer the value compared is its elapsed time in seconds. This method is shorter and makes it easy to change the times, and it shows how comparisons work with timer values.

Simulate

  1. Press F5, open the Ladder window and switch S1 on.
  2. Red lights; in the TON box you see ET counting. Use ×10 on the floating bar to run the cycle faster.
  3. Check that exactly one lamp is on at every moment. If two lamps light together, look at the NC contacts in the lamp rungs.
  4. Switch S1 off: all timers reset and all lamps go off.

Exercises

  • Add red + yellow together for 2 s before green, as in some European countries.
  • Add a pedestrian button that shortens the green phase.
  • Make the yellow lamp flash when S1 is off (night mode), using a timer that resets itself every second.

Open this circuit in the simulator