A PLC traffic light program is a step sequencer: one integer holds the current step, one timer measures how long that step has lasted, and every lamp is switched on by comparing the step number. A two-way intersection needs six steps (green, amber and all-red for each road) plus an optional all-red Walk step for pedestrians, and the whole thing fits in about fifteen rungs of ladder logic.
In this traffic light ladder logic tutorial I will build that program from the I/O list up, explain each rung, add a pedestrian button and a conflict check, and show you how to test it in a simulator before you touch hardware.
What we are building
A junction of a north–south (N–S) road and an east–west (E–W) road, each with red, amber and green lamps, plus a pedestrian crossing with Walk and Don’t Walk signals. When someone presses the pedestrian button, the controller inserts an all-red Walk phase after the next N–S all-red.
| Step | N–S | E–W | Pedestrians | Time |
|---|---|---|---|---|
| 1 | Green | Red | Don’t Walk | 20 s |
| 2 | Amber | Red | Don’t Walk | 3 s |
| 3 | Red | Red | Don’t Walk | 2 s |
| 4 | Red | Red | Walk (only if requested) | 8 s |
| 5 | Red | Green | Don’t Walk | 20 s |
| 6 | Red | Amber | Don’t Walk | 3 s |
| 7 | Red | Red | Don’t Walk | 2 s |
Steps 3 and 7 are the all-red clearance intervals. They give a vehicle that entered on amber time to clear the junction before the other road gets green. The times here are teaching values; real junction timings are set by the road authority.

The I/O list
As always, write the I/O list before any ladder. Addresses are Siemens style; the logic is identical on other brands.
| Tag | Address | Type | Description |
|---|---|---|---|
| Start | I0.0 | Input, NO | Start push button |
| Stop | I0.1 | Input, NC | Stop push button (wired normally closed) |
| Ped_PB | I0.2 | Input, NO | Pedestrian request button |
| NS_Red / NS_Amber / NS_Green | Q0.0 / Q0.1 / Q0.2 | Outputs | N–S lamps |
| EW_Red / EW_Amber / EW_Green | Q0.3 / Q0.4 / Q0.5 | Outputs | E–W lamps |
| Walk / Dont_Walk | Q0.6 / Q0.7 | Outputs | Pedestrian signals |
| Run, Fault, PedReq | M0.0, M0.1, M0.2 | Internal BOOL | Running, fault latch, pedestrian request |
| Step | MW10 | INT | Current step, 1 to 7 |
| StepTime | MD12 | TIME | Preset for the current step |
| T_Step | DB instance | TON | Step timer |
Why a step sequencer instead of a chain of timers
The classic beginner version uses one timer per lamp, each started by the one before it. I built exactly that for a single stack light in how to build a PLC timer loop sequence, and it is a good first exercise. For a full junction, a step number is better:
- One timer serves every step, so there is one place to look when timing is wrong.
- All the times sit in one list, easy to change or to move into an HMI.
- Adding a step, such as the Walk phase, means adding a number, not rewiring a chain.
- Debugging is easy: watch Step in online monitoring and you know exactly where the sequence is.
The traffic light ladder logic, rung by rung
Rung 0: run latch
A standard seal-in: Run = (Start OR Run) AND Stop AND NOT Fault. Stop is wired normally closed, so it is programmed with a normally open contact. If the seal-in idea is new, read the start/stop seal-in circuit explained first.
Rungs 1–7: load the time for the current step
One rung per step, each a compare contact and a MOVE:
| Condition | MOVE into StepTime |
|---|---|
| Step = 1 or Step = 5 | T#20s |
| Step = 2 or Step = 6 | T#3s |
| Step = 3 or Step = 7 | T#2s |
| Step = 4 | T#8s |
That is four rungs if you use a parallel branch for each pair. In structured text the same thing is a single CASE statement, which is one reason many programmers write sequencers in ST; see ladder logic vs structured text.
Rungs 8–11: the sequencer itself

- Rung 8, the step timer. TON T_Step is enabled by Run in series with a normally closed contact of its own output, T_Step.Q. When the elapsed time reaches StepTime, Q turns on. On the next scan the NC contact opens, IN goes false, the timer resets and Q drops. So Q is true for exactly one scan per step, and the timer immediately starts timing the next one.
- Rung 9, advance. T_Step.Q drives ADD Step + 1 → Step. Because Q is only true for one scan, the step advances by exactly one.
- Rung 10, skip the Walk step. If Step = 4 and there is no pedestrian request, MOVE 5 into Step. The controller passes through step 4 in a single scan and the cycle is 50 s.
- Rung 11, wrap. If Step > 7, MOVE 1 into Step.
Add one more rung, NOT Run → MOVE 1 → Step, so the sequence always restarts at N–S green after a stop.
Rung order matters. The timer rung must come before the advance rung, and the skip and wrap rungs after it, so that a step change is complete within one scan. The PLC solves rungs top to bottom every scan, as explained in the scan cycle section of my ladder logic tutorial.
Rungs 12–13: the pedestrian request
- Ped_PB → (S) PedReq. A press at any time sets the request, so a pedestrian does not have to hold the button.
- Step = 4 AND T_Step.Q → (R) PedReq. The request clears at the end of the Walk phase, not the start. If it cleared when step 4 began, rung 10 would see no request and skip the phase that had just started. Place this rung between rungs 8 and 9, while Step still equals 4 in that scan.
Rungs 14 onwards: lamp outputs
Each lamp is a compare decoded from Step. Keep the outputs on their own rungs, at the end of the program:
| Output | Logic |
|---|---|
| NS_Green | Run AND Step = 1 |
| NS_Amber | Run AND Step = 2 |
| NS_Red | NOT NS_Green AND NOT NS_Amber |
| EW_Green | Run AND Step = 5 |
| EW_Amber | Run AND Step = 6 |
| EW_Red | NOT EW_Green AND NOT EW_Amber |
| Walk | Run AND Step = 4 |
| Dont_Walk | NOT Walk |
Writing the reds as “not green and not amber” has a useful side effect: when the controller is stopped, every road shows red and pedestrians see Don’t Walk. A lamp program should always fail towards red.
Add a conflict check
Two greens at the same time must never happen. Add one rung after the outputs:
(NS_Green OR NS_Amber) AND (EW_Green OR EW_Amber) → (S) Fault
Fault breaks the Run rung, which turns every road red. Reset Fault only from a separate key switch or HMI button, so somebody has to look at the problem before the junction restarts. With the program above this rung should never fire; it is there to catch a future edit that breaks the step table.
Be clear about the limits. On a real road, the PLC program is not the safety system. Commercial traffic controllers use an independent conflict monitor that watches the lamp circuits themselves and forces the junction into flashing mode if it sees conflicting greens. This project is a training exercise and a good model for any timed machine sequence, not a design for a public road.
Test it in a simulator
Load the program into the Ladder Lab simulator or your vendor’s simulator and work through this list:
- Shorten every step to 2 s so a cycle takes seconds, not a minute.
- Press Start and watch Step count 1, 2, 3, 5, 6, 7, 1. Step 4 should be skipped.
- Press the pedestrian button during step 1. After step 3 you should see Walk with every vehicle lamp red, then step 5.
- Press Stop mid-cycle. Every road must go red at once, and Start must restart at N–S green.
- Check the lamp table above against every step. Write down any mismatch before fixing it.
The PLC timer preset calculator converts times into preset values for platforms that count in 10 ms or 100 ms ticks.
Porting it to other PLCs
- Allen-Bradley (Studio 5000): TON with .PRE in milliseconds (20000 for 20 s) and .DN as the done bit. Use EQU for the compares and ADD/MOV as above.
- Mitsubishi FX: a 100 ms timer such as T0 with K200 for 20 s, a data register (D0) for Step, and comparison contacts such as LD= D0 K1.
- CODESYS or any IEC 61131-3 PLC: exactly as drawn, or as a CASE statement in structured text.
Common extensions: a night mode that flashes amber from a 1 Hz clock bit, vehicle detectors that extend green while traffic keeps arriving, and moving StepTime values into retentive memory so an HMI can adjust them. For more on the timer instruction itself, see PLC timers: TON, TOF and TP.
Frequently asked questions
How do you program a traffic light in a PLC?
Use a step number and one timer. Load each step’s time, let the timer advance the step when it expires, wrap back to step 1 after the last step, and switch each lamp on by comparing the step number.
How many timers does a traffic light PLC program need?
One is enough with a step sequencer. A timer-chain design needs one timer per step, which works for small sequences but is harder to change.
What is the all-red interval?
A short period, typically one to a few seconds, when every approach shows red. It lets a vehicle that entered on amber clear the junction before the crossing road gets green.
Can I write traffic light logic in structured text?
Yes. A CASE statement on the step number is often shorter than ladder. Many programmers write the sequencer in ST and keep the lamp outputs in ladder for easy troubleshooting; see structured text for PLCs.
Why does my traffic light skip steps?
Usually because the step timer’s done bit stays on for more than one scan, so the step advances several times. Use the self-resetting timer in rung 8, or an edge (one-shot) contact on the done bit.
Keep going
Want the next tutorial in your inbox? Join the newsletter, one practical tutorial a week, or download the free eBook Introduction to Ladder Logic Programming and I/O Configuration from the resources library. Timer and compare instructions follow IEC 61131-3; check your PLC’s manual for its exact instruction names.
