Walkthrough: Problem 3: Button & Lamp ③

Difficulty

Target behavior

Toggle the lamp on/off each time the button is pressed

What you will learn

  • Rising edge (LDP): a contact that is ON only at the moment of pressing
  • N.C. contacts (LDB)
  • How to use internal relays (MR)

Problem

This is again a simple model with just a button and a lamp.

The goal is to make the lamp toggle off → on → off → on… each time the button is pressed.


In addition to N.O. contacts and coils, this ladder needs N.C. contacts and rising edge (load pulse) contacts.


This problem is difficult.

If you find it hard, download the answer and study it to understand what the ladder means!

Target behavior (video)

Approach

The key to "toggle each time it is pressed" is to react only at the moment the button is pressed. First, turn the moment of pressing into a signal that is ON for just one scan (a pulse), then use that signal to invert the lamp state.

Based on this approach, try writing the ladder yourself first.
In the simulator, you can create the wiring and ladder and actually run the 3D equipment model.

Try it in the simulator
Show the sample ladder and explanation(click to open)

Devices used

DeviceComment
Inputs
X0Button
Outputs
Y0Lamp
Internal relays
MR0Button press pulse

Ladder explanation

The row numbers in the figures match the row numbers in the simulator's ladder window.

1Create a pulse at the moment the button is pressedRows 001–002

LDP X0 is a contact that closes only in the scan where X0 changes from OFF to ON. Even if the button is held, it opens from the second scan onward.

This pulse is output to internal relay MR0. An internal relay is a "memo" device that is not wired to anything and can only be used inside the ladder.

2Invert the lamp when a pulse arrivesRows 003–005

The two conditions on rows 004 and 005 are placed in parallel and output to Y0.

ConditionMeaning
Row 004MR0 ON and Y0 OFFA pulse arrives while the lamp is off → turn it on
Row 005MR0 OFF and Y0 ONWhile there is no pulse, if it is on → keep it on (self-holding)

If a pulse arrives while the lamp is on, row 004 fails because Y0 is ON, and row 005 fails because MR0 is ON, so Y0 turns OFF. In other words, Y0 inverts each time a pulse arrives.

The sample wiring and ladder data can be downloaded fromGitHuband loaded with "Load wiring" and "Load ladder" in the simulator.

Key points

  • If you use LD X0 instead of LDP, the lamp inverts every scan while the button is held, so it flickers and ends up in a random state. Use a pulse when you want to react only at a moment.
  • An N.C. (normally closed) contact (LDB) closes when its device is OFF, the opposite of an N.O. contact.