Skip to content
PLCampus
All examples

04Level 2

Crossroad traffic lights

Two coordinated traffic lights driven by a single cycle timer and compare contacts on its elapsed time.

The simulator is designed for computers (screens 1024 px or wider).

Virtual plant

Q0.0 · redQ0.1 · amberQ0.2 · greenStreet AQ0.3 · redQ0.4 · amberQ0.5 · greenStreet B

Street A: off. Street B: off

Shown at rest. In the simulator the plant moves according to your program's outputs.

Inputs and outputs

AddressNameDescription
I0.0ONOperation switch
Q0.0RED_ARed light, street A
Q0.1AMBER_AAmber light, street A
Q0.2GREEN_AGreen light, street A
Q0.3RED_BRed light, street B
Q0.4AMBER_BAmber light, street B
Q0.5GREEN_BGreen light, street B
T0CYCLE20 s cycle timer
M0.0CYCLE_ENDPulse at the end of each cycle

Program

Ladder diagram (LD)

  1. Rung 1 — Self-restarting 20 s cycle timer.

    ONI0.0CYCLE_ENDM0.0TONCYCLEPT T#20sCYCLE_ENDM0.0
  2. Rung 2 — Street A: green from 0 to 8 s.

    ONI0.0<T0.ETT#8sGREEN_AQ0.2
  3. Rung 3 — Street A: amber from 8 to 10 s.

    ONI0.0>=T0.ETT#8s<T0.ETT#10sAMBER_AQ0.1
  4. Rung 4 — Street A: red from 10 to 20 s.

    ONI0.0>=T0.ETT#10sRED_AQ0.0
  5. Rung 5 — Street B: red from 0 to 10 s.

    ONI0.0<T0.ETT#10sRED_BQ0.3
  6. Rung 6 — Street B: green from 10 to 18 s.

    ONI0.0>=T0.ETT#10s<T0.ETT#18sGREEN_BQ0.5
  7. Rung 7 — Street B: amber from 18 to 20 s.

    ONI0.0>=T0.ETT#18sAMBER_BQ0.4

Step by step

  1. 1Press ▶ Run (F5) and turn on the ON switch (I0.0).
  2. 2Rung 1 is a 20 s timer that restarts itself: when it finishes, CYCLE_END turns on, its NC contact resets the timer and everything starts over.
  3. 3The other rungs compare the elapsed time (CYCLE.ET) with fixed limits: green A from 0 to 8 s, amber A from 8 to 10 s, red A from 10 to 20 s; street B does the opposite.
  4. 4Watch T0.ET in the monitor and check that two green lights are never on together. Try changing the times in the compare contacts.