06 · TK-101 · Projects
Two-way traffic light controller in Structured Text
A CODESYS Structured Text program that runs red, yellow and green for two directions from a one-second TON timer and a down counter, written three ways, with a WebVisu screen showing both sides.

The problem
A junction with two signals needs a sequence that is guaranteed: both directions are never green together, and a direction never goes from green to red without yellow. The exercise is to write that sequence as clear logic whose timings are easy to trace and change.
Solution and data flow
A TON timer produces a pulse every second and decrements a down counter C1. The counter value decides which lamps are on for the first direction R1/Y1/G1 and the second R2/Y2/G2. The logic was written three ways for comparison: IF/ELSIF chains with a 36-second cycle, a variant with a 30-second cycle, and a CASE state table with the values 30, 20, 15, 5 and 0.
Implementation and challenges
The project is a CODESYS V3.5 project for a CODESYS Control Win V3 soft PLC on a PC, with a 20 ms cyclic task. A WebVisu screen with "SIDE 1" and "SIDE 2" lamps is bound to the program outputs. The challenge is keeping all timings in one place so green and red can never overlap, and the CASE state table keeps them in one table unlike the IF chains. This is an exercise on a simulated PLC, not a field installation, and the code was recovered from the project's editing history.
Skills developed
Structured Text, timers and counters, state machines with CASE, and binding variables to a WebVisu screen and testing them on a simulated PLC.