Working Principle of Traffic Lights

Let’s first review how traffic lights work in our daily lives:
-
The green light is on for a period of time (e.g., 30 seconds)
-
The green light turns off, and the yellow light is on for a few seconds (usually 3-5 seconds)
-
The yellow light turns off, and the red light is on for a period of time (e.g., 20 seconds)
-
Repeat the above steps

Looks simple, right? But to implement this process with a PLC, we need to think carefully.
Hardware Connection
Before programming, we must first connect the hardware. Let’s assume we are using a small PLC, such as the Siemens S7-200.
PLC output points ------ Traffic Light
Q0.0 ---------- Red Light
Q0.1 ---------- Yellow Light
Q0.2 ---------- Green Light
Note: In actual engineering, PLC outputs usually do not drive high-power devices directly. We typically use PLC output points to control an intermediate relay, which then controls the actual traffic light. This protects the PLC and extends its lifespan.
PLC Ladder Diagram Program
Alright, the hardware is connected, let’s see how to program:
| | |
|---[ T32 ]---+---( Q0.2 ) // Green Light
| |
| +-[ T33 ]---( Q0.1 ) // Yellow Light
| |
| +-[ T34 ]---( Q0.0 ) // Red Light
|
|---[/T32]---[/T33]---[ T33 ]---(TON T34, 20) // Red Light Timer
|
|---[/T32]---[/T33]---[/T34]---(TON T32, 30) // Green Light Timer
|
|---[ T32 ]---[/T33]---[/T34]---(TON T33, 3) // Yellow Light Timer
This ladder diagram looks a bit complicated? Don’t worry, I’ll explain it:
-
We used three timers (T32, T33, T34) to control the duration of the green light, yellow light, and red light respectively.
-
The output for each light (Q0.0~Q0.2) is directly controlled by the corresponding timer.
-
The next three lines are the starting conditions for the timers, ensuring they operate in sequence.
Tip: In actual programming, you can give these timers and output points memorable names, such as GREEN_TIMER, YELLOW_LIGHT, etc., making the program more readable.
Program Execution Process
-
After powering on, T32 (green light timer) starts first and lasts for 30 seconds.
-
After T32 ends, T33 (yellow light timer) starts and lasts for 3 seconds.
-
After T33 ends, T34 (red light timer) starts and lasts for 20 seconds.
-
After T34 ends, it returns to step 1, repeating this cycle.
Practical Application Cases
The idea behind this traffic light program has many applications in industrial automation. For example:
-
Production Line Control: Controlling processing times at different workstations.
-
Traffic Management: Traffic light signaling systems in parking lots.
-
Equipment Maintenance: Controlling the start, stop, and cleaning operations of equipment in sequence.
Common Problems and Solutions
-
Problem: The switching is not smooth, both lights are on at the same time. Solution: Check the interlock conditions of the timers to ensure that only one timer is running at a time.
-
Problem: The program always stays in one state and does not change. Solution: A timer may be stuck. Try adding a general reset condition, such as adding a normally open contact as a start signal in the first rung.
-
Problem: The actual light duration does not match the set time. Solution: Check the PLC’s scan cycle settings to ensure it is much smaller than the shortest timer duration (here it is 3 seconds).
Precautions
-
Safety First! In actual traffic light control, various abnormal situations must be considered, such as adding a yellow flashing mode as a fault warning.
-
The accuracy of the timers is affected by the PLC scan cycle. For applications requiring millisecond precision, consider using high-speed counters or interrupt programs.
-
In actual engineering, manual and automatic control switching functions are usually added.
Practical Suggestions
To truly master this program, just watching is not enough. I suggest you:
-
Implement this program using simulation software and observe the execution process.
-
If possible, set up a real hardware environment, using LED lights to simulate the traffic lights.
-
Try to improve the program, such as adding a pedestrian crossing button or dynamically adjusting the duration of each light based on traffic flow.
Once you master this traffic light program, I believe you will have a deeper understanding of the application of PLC timers and sequential control. Next, you can try more complex traffic management systems, such as coordinated timing at multiple intersections. Keep it up, you are one step closer to becoming a PLC expert!