Fareed Mohmed← Project library

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.

▶ Run it in the simulator

Virtual machine for Traffic light: buttons, lamps and the process it controls
Learning model only. This page teaches the program logic. A real machine needs a proper control panel with an isolator, fuses, motor protection and a hard-wired emergency stop. Mains and motor wiring is for qualified electricians. A PLC output never drives a motor directly.

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.

NameWhat it isTypeSiemens
S7-1200
Allen-Bradley
CompactLogix
Mitsubishi
iQ-F FX5U
Delta
DVP / AS
Omron
CP2E
Schneider
M241
Inovance
H5U
ENABLESignal ON switchInput%I0.0Local:1:I.Data.0X0X00.00%IX0.0X0
REDRed lampOutput%Q0.0Local:2:O.Data.0Y0Y0100.00%QX0.0Y0
YELYellow lampOutput%Q0.1Local:2:O.Data.1Y1Y1100.01%QX0.1Y1
GRNGreen lampOutput%Q0.2Local:2:O.Data.2Y2Y2100.02%QX0.2Y2

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.

Rung 1 Green time (4 s), restarts after redENABLE%I0.0Timer 3 done"T3".Q"T1"TONINPT T#4sQETET = 4000 msRung 2 Yellow time (1.5 s)Timer 1 done"T1".Q"T2"TONINPT T#1500msQETET = 1500 msRung 3 Red time (4 s)Timer 2 done"T2".Q"T3"TONINPT T#4sQETET = 740 msRung 4 Green lampENABLE%I0.0Timer 1 done"T1".QGRN%Q0.2Rung 5 Yellow lampTimer 1 done"T1".QTimer 2 done"T2".QYEL%Q0.1Rung 6 Red lampTimer 2 done"T2".QTimer 3 done"T3".QRED%Q0.0

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

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.

#ItemBuy / compare
1PLC with 1 input and 3 outputsAmazon.in · IndiaMART · Robu.in
2Signal lamps or LED stack lightAmazon.in · IndiaMART · Robu.in
← 7. Two cylinders: A+ B+ B- A-All projects9. Flasher (blinking lamp) →

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.