Target behavior
Toggle the lamp on/off each time the button is pressed
What you will learn
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!
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.
| Device | Comment |
|---|---|
| Inputs | |
X0 | Button |
| Outputs | |
Y0 | Lamp |
| Internal relays | |
MR0 | Button press pulse |
The row numbers in the figures match the row numbers in the simulator's ladder window.
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.
The two conditions on rows 004 and 005 are placed in parallel and output to Y0.
| Condition | Meaning | |
|---|---|---|
| Row 004 | MR0 ON and Y0 OFF | A pulse arrives while the lamp is off → turn it on |
| Row 005 | MR0 OFF and Y0 ON | While 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
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.LDB) closes when its device is OFF, the opposite of an N.O. contact.