PLC Drum Sequencer Tutorial: Traffic Light
The traffic light program that ships with the simulator’s Traffic Light scene is 29 rungs long. Six phase bits, eight timers, latches and unlatches, and an output rung for every lamp. Today we run the same intersection from one instruction: the PLC drum sequencer.
By the end of this post you will know how a PLC drum sequencer steps through a table of output patterns, how to turn a row of lights into a pattern number, and how a step can wait for time, for an event, or for both. We will build it on the free ACC PLC Simulator with the 3D Traffic Light Intersection scene, then make the intersection answer a pedestrian button. This post is also the tutorial for the Traffic Light scene, as promised in the 42-instruction update.

Watch it on YouTube…
PLC Drum Sequencer Tutorial: Traffic Light
Previously, we examined…
- Level Up Your PLC Logic: Clock Pulses Explained · Video
- Everything You Need to Know About One-Shot Instructions · Video
- CTU vs CTD vs CTUD: Which PLC Counter Do You Need? · Video
- Motor Starter Logic: Build a Fail-Safe System in 5 Rungs · Video
- TON, TOF, or RTO? Which PLC Timer Should You Use? · Video
- 17 to 42 Instructions in One Week: The Free PLC Simulator Just Leveled Up · Video
- Run Two 3D Machines at Once — Multi-Scene PLC Simulator · Video
- I Replaced a $5,000 PLC Trainer with Free PLC Training Simulator · Video
- Can AI Program a PLC? I Tested It Live in the ACC PLC Simulator · Video
- ACC PLC Simulator — How to Use Structured Text (ST) Programming · Video
- ACC PLC Simulator: Any Gamepad Now Drives Your PLC! · Video
- PLC Programming Tutorial: Build a Conveyor System (ACC Simulator) · Video
- Control 3D PLC Scenes With Zero Hardware? Here’s How · Video
- ACC PLC Simulator – How to Use the Free Browser-Based PLC Trainer · Video
- How to Use the ACC PLC Simulator — Control Panel Scene Tutorial · Video
One Instruction Instead of a State Machine
Here is a link to the original traffic light program.
What a drum sequencer is
Before PLCs, machines were sequenced by a real drum: a cylinder with pegs on it, turned by a motor. Each peg closed a switch as it went past. A washing machine timer is the one most people have seen. Turn the dial and it clicks from fill, to wash, to drain, to spin.
The DRUM instruction is that cylinder in software. You give it a table. Each row is a step, each column is an output, and a tick in the table means “this output is ON during this step.” The drum turns on the outputs for the current step, waits, then moves to the next row. After the last row it goes back to the first.
Steps and patterns
A traffic light is a perfect drum. There are only six combinations of lamps that are ever allowed, and they always come in the same order.
| Step | Lights ON | Y6 Y5 Y4 Y3 Y2 Y1 | Pattern | Time |
|---|---|---|---|---|
| 1 | NS green, EW red | 1 0 0 0 0 1 | 33 | 5 s |
| 2 | NS yellow, EW red | 1 0 0 0 1 0 | 34 | 2 s |
| 3 | All red | 1 0 0 1 0 0 | 36 | 1 s |
| 4 | EW green, NS red | 0 0 1 1 0 0 | 12 | 5 s |
| 5 | EW yellow, NS red | 0 1 0 1 0 0 | 20 | 2 s |
| 6 | All red | 1 0 0 1 0 0 | 36 | 1 s |
That is the whole traffic program. Notice what is not in it: there is no row with two greens. A drum can only ever output a row you wrote, so the safety interlock “never green both ways” is built into the table.
Building the pattern number
In the simulator’s editor you tick boxes, so you never have to work the number out. But it is worth knowing what is in the file, because the pattern is stored as one whole number.
Each output has a bit value. The first output (Y1) is worth 1, Y2 is 2, Y3 is 4, Y4 is 8, Y5 is 16 and Y6 is 32. Add up the outputs that are ON. Step 1 has NS green (Y1 = 1) and EW red (Y6 = 32), so its pattern is 33. Step 4 has EW green (8) and NS red (4), so it is 12.
Time, event, or both
Every step has two conditions, and the drum moves on when both are true:
- Time. The step has been active for at least its time. A time of 0 means “no time condition.”
- Event. A bit you choose is ON. An empty event means “no event condition.”
Time only is a timed sequence, like our traffic light. Event only waits for something to happen: a limit switch, a level switch, a button. Time and event gives you “at least 5 seconds, and not until somebody asks.” We will use exactly that for the pedestrian button.
Run, pause and reset
- While the rung is true, the drum writes the current step’s pattern to its outputs and its step time counts.
- While the rung is false, the drum pauses. The step and the time already spent in it are held, and the outputs keep their last state.
- While the reset bit is ON, the drum sits at step 1 with zero time, whether the rung is true or false.
The current step lives in a D register, so you can watch it, compare it and even change it. A MOV into the step register jumps the drum to that step.
The done bit
When the last step finishes, the drum goes back to step 1 and turns its done bit ON for exactly one scan. That makes it a ready-made “one cycle complete” pulse. Count it with the rising edge contact and you have a cycle counter.
What other PLCs call it
The idea is everywhere. The details change.
- AutomationDirect Click: the Drum instruction, with a choice of Time Base, Event Base, or Time & Event Base. It handles 1 to 16 steps and up to 16 outputs, set up in a grid of steps and outputs. DirectLOGIC CPUs such as the DL05 and DL06 have DRUM and EDRUM (event drum).
- Rockwell Studio 5000 (Logix): the SQO (sequencer output). It moves one position each time its rung goes from false to true and writes an array element through a mask. It has no built-in step time, so you pair it with a timer.
- Siemens: classic S7-300/400 CPUs have a DRUM system block (SFB 32). On S7-1200 and S7-1500 the usual approach is a step number with a CASE statement in SCL, or a GRAPH sequence.
- IEC 61131-3 Structured Text has no drum instruction. You write a step number, a CASE and a TON, which is exactly what we do further down.
Always check the manual for your controller.
STEP 1 — Define the Task
The Traffic Light Intersection scene is a four-way intersection at dusk. It has a signal head for each road, crosswalks on all four sides, and two pedestrian push buttons on the corners. It is controlled entirely by the PLC: the scene shows the six lamps and sends the two buttons back.
In plain English:
- Cycle the lights through NS green, NS yellow, all red, EW green, EW yellow, all red, and repeat. 16 seconds per cycle.
- Run switch. With the run switch ON the lights cycle. Turn it OFF and they hold where they are.
- Reset. A reset button returns the sequence to the start and clears the cycle count.
- Count cycles. Keep a count of completed cycles.
Later we will add a fifth: 5. Pedestrian call. The N/S road rests on green until a pedestrian asks to cross it.
The times are short on purpose so you can watch several cycles in a minute. A real intersection runs greens of 20 seconds or more.
STEP 2 — Define the I/O
| Address | Description | Type | Modbus |
|---|---|---|---|
| X1 | Ped push button N/S (crosses the E/W road) | Input (scene) | DI 10001 |
| X2 | Ped push button E/W (crosses the N/S road) | Input (scene) | DI 10002 |
| X3 | Run enable switch (maintained) | Input (X tab) | — |
| X4 | Reset push button | Input (X tab) | — |
| Y1 | NS green | Output | Coil 00001 |
| Y2 | NS yellow | Output | Coil 00002 |
| Y3 | NS red | Output | Coil 00003 |
| Y4 | EW green | Output | Coil 00004 |
| Y5 | EW yellow | Output | Coil 00005 |
| Y6 | EW red | Output | Coil 00006 |
| C1 | Drum done (one scan per cycle) | Internal bit | — |
| C2 | EW call (pedestrian version) | Internal bit | — |
| D1 | Drum step (1–6) | Data register (INT) | — |
| D2 | Completed cycles | Data register (INT) | — |
The scene supplies X1 and X2 and shows Y1 to Y6. The run switch and reset are not on the scene, so toggle X3 and X4 on the X tab of the simulator’s I/O panel.
STEP 3 — Develop the Sequence
- Step 1: NS green and EW red for 5 s.
- Step 2: NS yellow and EW red for 2 s.
- Step 3: all red for 1 s (clearance).
- Step 4: EW green and NS red for 5 s.
- Step 5: EW yellow and NS red for 2 s.
- Step 6: all red for 1 s, then back to step 1 and add 1 to the cycle count.
- X3 OFF pauses the sequence. X4 returns it to step 1 and zeros the count.
Two questions before you build it: if you turn the run switch OFF two seconds into a green and back ON a minute later, how much longer does that green last? And if you put the PLC in STOP during step 4 and back in RUN, which step does it start in? (Answers in STEP 5.)
STEP 4 — Develop the PLC Program
Three rungs, every one commented.
| Rung | Logic | Comment |
|---|---|---|
| 0 | X3 → DRUM D1, outputs Y1 ×6, 6 steps, reset X4, done C1 |
Traffic sequence |
| 1 | P C1 → INC D2 |
One count per completed cycle |
| 2 | X4 → MOV 0 → D2 |
Reset clears the cycle count |
To build it yourself, drag XIC onto a new rung and give it the address X3. Then drag Drum Sequencer from the SHIFT / SEQUENCE section of the palette to the end of the rung. In the dialog:
- Step register: D1.
- Outputs: first output bit Y1, number of outputs 6.
- Reset bit: X4. Done bit: C1.
- Click Edit steps…, add six steps, tick the lamps for each step and type its time in milliseconds (5000, 2000, 1000, 5000, 2000, 1000). Leave every event empty.
Rung 1 is a P (rising edge) contact on C1 with an INC of D2 (MATH). Rung 2 is an XIC X4 with a MOV of 0 into D2 (MOVE / DATA).
Or skip the typing: download acc-example-traffic-drum.json and import it with LOAD.
Three things to notice:
- One block replaces a state machine. The 29-rung version needs six phase bits, a timer per phase, an advance rung and a clear rung for each, and an output rung per lamp. The drum keeps all of that in its table.
- The drum owns Y1 to Y6. Do not put an OTE on any of them anywhere else. The OTE would rewrite the lamp on every scan and fight the drum. Read drum outputs with contacts.
- The P on C1 is belt and braces. The done bit is only ON for one scan, so a plain contact would also count once. The rising edge makes the intent obvious to the next person who reads the rung.
While it runs, the drum block shows its step (STEP 4), the step out of the total (4/6) and the time in step against the step time. That is the first place to look when a sequence is “stuck.”
Make It Actuated: The Pedestrian Call
A fixed-time light gives the side road a green even when nobody is there. Real intersections often rest on the main road and only change when they are asked. That is a job for the drum’s event field.
In this version the N/S road is the main road. A pedestrian who wants to cross it presses the E/W button (X2). That latches a call, C2. Step 1 now has a time of 5 s and an event of C2, so NS green lasts at least 5 seconds and then waits for the call. As soon as the drum reaches step 4 (EW green), the call has been served and is cleared.
| Rung | Logic | Comment |
|---|---|---|
| 0 | X2 → OTL C2 |
EW call: latch the pedestrian request |
| 1 | X3 → DRUM D1 (step 1: 5000 ms, event C2) |
Traffic sequence |
| 2 | EQU D1 = 4 → OTU C2 | Call served once EW green starts |
| 3 | P C1 → INC D2 |
Cycle count |
| 4 | X4 → MOV 0 → D2, OTU C2 |
Reset clears the count and any waiting call |
The only change to the drum is one field in one step. Download acc-example-traffic-drum-ped.json to try it.
Why latch the button at all? Because a pedestrian press is a short pulse, and the drum checks the event only when the time condition is also true. If someone presses during the first 5 seconds, a plain X2 event would already be OFF again when the time runs out. The latch remembers the request until it is served.
The Same Sequence in Structured Text
Structured Text has no drum, so the sequence becomes a step number, a CASE for the step time and one TON:
VAR
StepTimer : TON; // times the current step
StepTime : TIME; // preset for the current step
Advance : BOOL; // step time reached on the last call
END_VAR
IF X4 THEN // reset
D[1] := 1;
D[2] := 0;
END_IF;
IF (D[1] < 1) OR (D[1] > 6) THEN // 0 in a new program = step 1
D[1] := 1;
END_IF;
CASE D[1] OF // one case per step
1, 4: StepTime := T#5s; // greens
2, 5: StepTime := T#2s; // yellows
ELSE
StepTime := T#1s; // all red
END_CASE;
StepTimer(IN := X3 AND NOT X4 AND NOT Advance, PT := StepTime);
Advance := StepTimer.Q;
IF Advance THEN
D[1] := D[1] + 1; // next step
IF D[1] > 6 THEN
D[1] := 1;
D[2] := D[2] + 1; // one more cycle
END_IF;
END_IF;
Y1 := D[1] = 1; // NS green
Y2 := D[1] = 2; // NS yellow
Y3 := D[1] >= 3; // NS red
Y4 := D[1] = 4; // EW green
Y5 := D[1] = 5; // EW yellow
Y6 := (D[1] <= 3) OR (D[1] = 6); // EW red
It keeps the step in D1, the same register the ladder drum uses, so the D tab looks the same either way. The NOT Advance on the timer input drops it for one scan after every step, which restarts the TON for the next one.
There is one difference worth knowing. A TON cannot pause. Turn X3 OFF and the step and lamps hold, but the step time starts again from zero when X3 comes back. The ladder drum keeps its time in step. That is one more thing the instruction gives you for free.
Download the commented file: acc-example-traffic-drum.st.
STEP 5 — Test the Program
- Open the ACC PLC Simulator and load acc-example-traffic-drum.json.
- Click CONNECT and launch the Traffic Light Intersection scene.
- Press RUN in the simulator. Nothing lights yet: the drum’s rung is false.
- On the X tab, turn X3 ON.
Keep the D tab (or the I/O tab) in view while you work through these tests:
Test the cycle. NS goes green and EW red. Watch D1 count 1, 2, 3, 4, 5, 6 and back to 1, and D2 add one each time it wraps. Time it: a full cycle is 16 seconds, plus a tenth of a second here and there. A step only ends on a scan, and the simulator scans every 100 ms.
Test pause and reset. Turn X3 OFF in the middle of a green. The lamps freeze and the drum block’s time stops counting. Wait as long as you like, then turn X3 back ON. That answers the first question: the green finishes only the time it had left, about 3 seconds. Now press X4. The drum jumps to step 1 and D2 goes to 0.
Test a stop and restart. Wait for step 4 (EW green), then press STOP in the simulator. All six lamps go dark, because STOP clears the Y outputs. Press RUN. That answers the second question: EW comes back green in step 4, not step 1. The step lives in D1, and D registers keep their values through STOP. The time in step does restart from zero, so that green gets its full 5 seconds. If you want every RUN to start at step 1, add a first scan rung: SB3 → MOV 1 → D1.
Test the pedestrian call. Load acc-example-traffic-drum-ped.json, RUN, and turn X3 ON. NS goes green and stays green. Wait 10 seconds, then press the PED button for X2 on the scene. NS goes yellow straight away, then all red, then EW green. Now press X2 again during the first few seconds of the next NS green. NS still gets its full 5 seconds, then changes without another press, because the call was latched.
Testing with a Real PLC over Modbus
To run the same logic in your own PLC, start the bridge (node acc-modbus-bridge.js), click ⬡ MODBUS → CONNECT in the Traffic Light scene, and point your PLC’s Modbus TCP client at the bridge:
| Setting | Value |
|---|---|
| IP address | Your PC’s LAN IP (127.0.0.1 for Modbus Poll on the same PC) |
| Port | 502 (or 5020 if you started the bridge with --modbus-port 5020) |
| Unit ID | 1 |
| Read inputs | FC02 Discrete Inputs 10001–10002 (X1–X2, the pedestrian buttons) |
| Write outputs | FC05 Coils 00001–00006, or FC15 for all six at once (Y1–Y6) |
The run switch and reset are not part of the scene, so wire them to your PLC’s own inputs or use internal bits. Use your controller’s drum or sequencer instruction (see What other PLCs call it above), or the CASE version if it has none. Writing all six lamps with one FC15 keeps them changing together.
Common Drum Sequencer Mistakes
- Driving a drum output with an OTE somewhere else. The coil and the drum write the same bit every scan and the lamp flickers or does nothing. Read drum outputs with contacts only.
- Writing the pattern as a list. In the file the pattern is one number: Y1 + Y6 = 1 + 32 = 33, not “1, 6”. In the editor, just tick the boxes.
- Using a short pulse as an event. The event is checked only when the time is also up. Latch a button press and clear the latch when the request has been served.
- Expecting the drum to start at step 1 after STOP. The step is in a D register, so it survives STOP. Use the reset bit or a first-scan MOV.
- Expecting outputs to turn OFF when the rung goes false. A paused drum holds its lamps. If you need them dark, use a separate output stage.
- Forgetting that a step ends on a scan. Times are rounded up to the next scan, so a cycle runs a little longer than the sum of its steps.
Conclusion
One instruction, six lights:
- A drum sequencer is a table: steps down the side, outputs across the top, a time and an event for each step.
- The pattern is one number made of the bit values of the outputs that are ON. The editor works it out for you.
- A step moves on when its time is up and its event is ON. Time only, event only, or both.
- A false rung pauses the drum and holds its outputs. The reset bit returns it to step 1. The done bit pulses once per cycle.
- The step is a D register, so it survives STOP, can be compared, and can be changed with a MOV.
- In Structured Text a drum is a step number, a CASE and a TON.
Next step: load the pedestrian example into the ACC PLC Simulator, connect the Traffic Light scene, and wire up the other button. Make X1 latch a second call, C3, give step 4 a 5-second time and the event C3, and clear C3 when the drum reaches step 1. Now each road rests on green until someone on the other side asks to cross. Next Monday: changing a program while the PLC is still running, with an online edit on this same intersection.
Related posts
- 17 to 42 Instructions in One Week: The Free PLC Simulator Just Leveled Up
- TON, TOF, or RTO? Which PLC Timer Should You Use?
- Everything You Need to Know About One-Shot Instructions
- ACC PLC Simulator — How to Use Structured Text (ST) Programming













