~/nodetwelve.com$
34 notes · 6 topics
updated 2026-11-27

TIA Portal traffic lights sequencer using a shift register

· 3 min read

A simple example of using the SHL (Shift Left) instruction in Siemens TIA Portal to build a traffic lights sequencer.

The idea is to use a single bit stored in a byte as a pointer to track the current step of the sequence. After each step is completed, the bit is shifted one position to the left, activating the next step through the corresponding memory bit.

The project uses a Siemens S7-1200 PLC, a WinCC HMI panel and PLCSIM for simulation.

Device configuration

I use two devices configured in TIA Portal and connected over Ethernet:

They are both simulated within the software.

Siemens S7-1200 and HMI Ethernet Configuration in TIA Portal

WinCC HMI design

The HMI is kept simple. It contains three circles representing the traffic lights, along with Start and Stop buttons to control the sequence.

Simatic HMI Traffic Lights Sequence Screen

PLC tags

The PLC uses Q outputs to control the three lights and memory bits to keep track of the sequence.

MB0 is used as the shift register. It stores the current bit pattern and is shifted left using the SHL instruction after each completed step. Sounds simple enough? Let's program it.

Siemens PLC Tags Traffic Lights

PLC programming

The logic is split into separate networks, each handling a particular part of the sequence.

Network 1: start/stop RS flip-flop

Memory bits M5.0 (Start) and M5.1 (Stop) control an SR flip-flop.

The output, M5.2 (Run), enables the entire sequence. Pressing Start sets the bit, while Stop resets it.

Network 1 Traffic Sequencer

Network 2: initialise the shift register

When the sequence is enabled and the initial conditions are met, the shift register is loaded with a value of 1.

This sets the initial bit position in MB0 and prepares the sequencer for the first step.

Network 2 Traffic sequencer

Network 3: shift the bit left

Memory bit M10.0 (PulseStep) generates the pulse used to trigger the next step.

The SHL instruction moves the current bit one position to the left. This changes the active memory bit in MB0 and allows the next part of the sequence to run.

Network 3 Traffic Sequencer

Network 4: traffic lights sequence

Each step is triggered by its corresponding memory bit, from M0.0 to M0.4.

The shift register determines which step is currently active. Once a step is completed, a pulse shifts the bit to the next position.

For example:

This way, the sequencer moves through the steps without needing a separate memory bit for each transition.

Network 4 Traffic Sequencer

Network 5: Step 1 - red light

The first step activates the Red light output by setting it to 1.

Network 5 Traffic Sequencer

Network 6: Step 2 - amber light

After 5 seconds, the Amber light output is set to 1.

Network 6 Traffic Sequencer

Network 7: Step 3 - green light

After another 5 seconds, the Green light is activated.

At the same time, the Red and Amber outputs are reset to 0.

Network 7 Traffic Sequencer

Network 8: Step 4 - amber light

After 5 seconds, the Green light is switched off and the Amber light is activated again.

Network 8 Traffic Sequencer

Network 9: Step 5 - complete the sequence

The final step resets the Amber light output to 0.

This completes the sequence. The logic returns to Network 2, where the shift register is initialised with a value of 1 again, ready for another cycle.

Network 9 Traffic Sequencer

Network 10: stop and reset

When Stop is pressed on the HMI, the Run bit (M5.2) is reset.

All traffic light outputs are switched off, and the timers are reset using their RT instructions. This stops the sequence and returns the system to its initial state.

Network 10 Traffic Sequencer

Simulation

The complete project can be tested using PLCSIM together with the WinCC HMI. The Start and Stop buttons allow you to control the sequence, while the three lights show the current state of the program.

That's it. A simple way of using the SHL instruction to build a step-by-step sequencer in TIA Portal, without having to create a separate set of control bits for every transition.

This will be a good reference point when programming more complex structures.