Engineering · PLC · Project 8 of 15 · Signals and alarms · Level 2
Traffic light
Green, yellow and red in a repeating cycle using three chained timers.

You will learn
Timers can be chained: the done bit of one starts the next. The last timer resets the first one, so the cycle repeats forever. This is the base of every timed cyclic light or sequence.
How it works
- The light starts in green while the signal switch is on.
- After 4 s it goes yellow, then red, then back to green.
- Flip the switch off and all lamps go dark.
In real life
Simple junctions, level crossings, machine status towers.
Inputs, outputs and addresses
The same signals on seven PLC brands. Inputs and outputs are numbered in order; check your own hardware and software, because addresses depend on the model and module position.
| Name | What it is | Type | Siemens S7-1200 | Allen-Bradley CompactLogix | Mitsubishi iQ-F FX5U | Delta DVP / AS | Omron CP2E | Schneider M241 | Inovance H5U |
|---|---|---|---|---|---|---|---|---|---|
| ENABLE | Signal ON switch | Input | %I0.0 | Local:1:I.Data.0 | X0 | X0 | 0.00 | %IX0.0 | X0 |
| RED | Red lamp | Output | %Q0.0 | Local:2:O.Data.0 | Y0 | Y0 | 100.00 | %QX0.0 | Y0 |
| YEL | Yellow lamp | Output | %Q0.1 | Local:2:O.Data.1 | Y1 | Y1 | 100.01 | %QX0.1 | Y1 |
| GRN | Green lamp | Output | %Q0.2 | Local:2:O.Data.2 | Y2 | Y2 | 100.02 | %QX0.2 | Y2 |
Ladder diagram (shown for Siemens, live state)
Green wires carry power in the moment captured below. Switch the brand and the language in the simulator.
Structured text, Siemens SCL
(* Siemens S7-1200, CPU 1214C DC/DC/DC - TIA Portal - SCL *)
(* Rung 1: Green time (4 s), restarts after red *)
"T1"(IN := "ENABLE" AND NOT "T3".Q, PT := T#4s);
(* Rung 2: Yellow time (1.5 s) *)
"T2"(IN := "T1".Q, PT := T#1500ms);
(* Rung 3: Red time (4 s) *)
"T3"(IN := "T2".Q, PT := T#4s);
(* Rung 4: Green lamp *)
"GRN" := "ENABLE" AND NOT "T1".Q;
(* Rung 5: Yellow lamp *)
"YEL" := "T1".Q AND NOT "T2".Q;
(* Rung 6: Red lamp *)
"RED" := "T2".Q AND NOT "T3".Q;Structured text, Allen-Bradley
(* Allen-Bradley CompactLogix 5069 (L306ER) - Studio 5000 Logix Designer - Structured Text *)
(* Rung 1: Green time (4 s), restarts after red *)
Timer1.PRE := 4000; (* ms *)
Timer1.TimerEnable := ENABLE AND NOT Timer3.DN;
TONR(Timer1);
(* Rung 2: Yellow time (1.5 s) *)
Timer2.PRE := 1500; (* ms *)
Timer2.TimerEnable := Timer1.DN;
TONR(Timer2);
(* Rung 3: Red time (4 s) *)
Timer3.PRE := 4000; (* ms *)
Timer3.TimerEnable := Timer2.DN;
TONR(Timer3);
(* Rung 4: Green lamp *)
GRN := ENABLE AND NOT Timer1.DN;
(* Rung 5: Yellow lamp *)
YEL := Timer1.DN AND NOT Timer2.DN;
(* Rung 6: Red lamp *)
RED := Timer2.DN AND NOT Timer3.DN;Try this
- Change the green time to 8 s.
- Add a pedestrian button in your own version.
Parts to buy
The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.
This is a learning tool. It teaches the logic, not the exact keystrokes of each vendor’s software. Check the manual of your own PLC.