PLC Sim Lab
Beginner exercise · set / reset, edges, interlock

Drawbridge control with one button on each side

A drawbridge over a river and only two push buttons, one on each bank. The press on your side closes the bridge, the press on the far side opens it again, and it must work in both directions. The trick is to make the PLC remember who is crossing.

Worked solution with video · Updated 2026-10-02

Loads the panel and the ladder program from the video. Press RUN PLC and try it.

The task

A drawbridge crosses a river. It normally stays open (raised) so boats can pass. There is one push button on each bank, PB A and PB B, and nothing else for the people crossing:

The bridge has a drive with two directions (CLOSE and OPEN) and a limit switch at each end of its travel. In the PLC Sim Lab Playground this is the Drawbridge part in the parts list.

Inputs and outputs

SiemensTOYOPUCSignal
I0.0X000PB A, side A
I0.1X001PB B, side B
I0.2X002LSC: bridge fully closed
I0.3X003LSO: bridge fully open
Q0.0Y000drive: CLOSE
Q0.1Y001drive: OPEN
M0.0M000a person from A is crossing
M0.1M001a person from B is crossing

Thinking it through

Both buttons can open and close the bridge, so the button alone does not tell the PLC what to do. What decides it is who is on the bridge. Two memory bits store that: M0.0 means someone from side A is crossing, M0.1 someone from side B.

  1. Ask to cross. While the bridge is fully open, PB A sets M0.0 and PB B sets M0.1. Each also checks that the other bit is off, so two people cannot both "own" the bridge.
  2. Only the far side opens it. While the bridge is fully closed, PB B resets M0.0 (the person from A has arrived on side B), and PB A resets M0.1. A second press on the near side finds no matching rung, so it is ignored.
  3. Drive to the limits. If either bit is on, close until the closed limit switch; if neither is on, open until the open limit switch. Each direction is blocked while the other one runs, so the motor can never get both.

Use edges (one-shots) on the buttons. Without them, a single long press on side B could reset M0.0 and, as soon as the bridge is open again, immediately set M0.1 and close it again.

The ladder program (Siemens style)

RungContactsOutputWhat it does
1P I0.0, I0.3, NOT M0.1S M0.0A asks to cross
2P I0.1, I0.3, NOT M0.0S M0.1B asks to cross
3P I0.1, I0.2, M0.0R M0.0A has crossed, B opens
4P I0.0, I0.2, M0.1R M0.1B has crossed, A opens
5(M0.0 OR M0.1), NOT I0.2, NOT Q0.1Q0.0close until LSC
6NOT M0.0, NOT M0.1, NOT I0.3, NOT Q0.0Q0.1open until LSO
The Siemens video: watch on YouTube

The same on a TOYOPUC

On a JTEKT TOYOPUC the one-shot is a rise differential placed after the contact, and each differential needs its own P edge relay (P000 to P003) to remember the previous state. Inputs are X, outputs Y, internal relays M, all numbered in hexadecimal.

RungInstructionsOutput
1STR X000, rise diff. P000, AND X003, ANDN M001SET M000
2STR X001, rise diff. P001, AND X003, ANDN M000SET M001
3STR X001, rise diff. P002, AND X002, AND M000RST M000
4STR X000, rise diff. P003, AND X002, AND M001RST M001
5(M000 OR M001), ANDN X002, ANDN Y001OUT Y000
6STRN M000, ANDN M001, ANDN X003, ANDN Y000OUT Y001
The TOYOPUC video: watch on YouTube

Loads the panel and the ladder program from the video. Press RUN PLC and try it.

Test it

  1. RUN: the bridge is open and LSO is on.
  2. Press PB A: M0.0 is set and the bridge comes down until LSC.
  3. Press PB A again: nothing happens.
  4. Press PB B: M0.0 is reset and the bridge opens.
  5. Now start from side B: PB B closes, PB A opens.

Common mistakes

Variations to try

Try it yourself

Build it from scratch in the free PLC Sim Lab Playground, or open the finished solution and change it:

Loads the panel and the ladder program from the video. Press RUN PLC and try it.

Frequently asked questions

Why not just toggle the bridge on every press?

A toggle cannot tell the near button from the far one, so a second press on the starting side would open the bridge while the person is still on it. Remembering who is crossing makes only the far button open it.

Why are the CLOSE and OPEN outputs interlocked?

Each output has a normally closed contact of the other one. Even during a programming mistake the drive cannot be told to run both ways at once, which on a real reversing starter would be a short circuit.

More: all PLC exercises · free PLC course with certificate · PLC timers and counters · ladder logic basics