HMI forward off reverse selector with a PLC state machine

7 min read · Published November 9, 2026

A Forward-Off-Reverse selector for a dual-solenoid valve is a small state machine, and it belongs in the PLC. Two momentary HMI buttons write two request bits for one scan; the PLC owns three state bits for Forward, Off and Reverse, with the SET rungs placed above the RST rungs. Pressing the opposite direction drops through Off, a second press energizes the other coil, and the cross-interlocked outputs can never both be ON in one scan.

A Forward-Off-Reverse selector for a dual-solenoid valve is a small state machine, and it belongs in the PLC, not in an HMI object. Give the panel two momentary pushbuttons that write two request bits, let the PLC own three state bits for Forward, Off and Reverse, and derive the two solenoid outputs with a cross-interlock. Pressing the opposite direction then drops the selector through Off, and a second press of the same button is required before the other coil energizes. This setup walks through the ladder rungs and the panel objects, follows one transition scan by scan, and ends with the four-transition test to pass before operators get the screen.

Why the selector cannot live in the panel

A radio button group cannot produce this sequence, and the reason is the object's documented behavior: the members of a radio group are mutually exclusive, so selecting Reverse clears Forward and the display jumps straight from Forward to Reverse. The intermediate Off state and the second press never appear.

Two workarounds fail for their own reasons. Toggle buttons bound to the coil bits latch state inside the panel, and nothing in that arrangement keeps both bits at 1, which energizes both coils of the valve at once. And any panel object that writes the three state bits makes the panel a second writer of state: displayed state and real valve state then depend on which device won the last write, and the two drift apart whenever a reply is late.

Split the jobs. The panel sends requests; the PLC owns state. A momentary pushbutton writes 1 to its tag while it is touched and 0 on release, and that is the whole job: the press is a request, and PLC rungs produce the command bits.

What you need

  • An HMI panel with momentary pushbutton and indicator-lamp objects, connected to the PLC over its normal link.
  • A ladder editor and a PLC with a one-scan pulse instruction; the rungs below use PLS, the pulse instruction in this ladder syntax.
  • 2 request bits, example addresses M110 for Forward and M111 for Reverse.
  • 2 pulse bits, M120 and M121, each ON for exactly 1 scan.
  • 3 state bits, M100 Forward, M101 Off, M102 Reverse.
  • 2 outputs, Y0 to the Forward coil and Y1 to the Reverse coil.
  • The valve datasheet, for what Off does mechanically.

Every address here is an example; use any free internal relays and outputs and keep the names consistent through the project. The requests arrive as data writes from the panel, not as field inputs; HMI button writes vs the PLC input scan: what changes covers what that difference changes in the scan.

Give the panel two buttons and three lamps

  1. Enter the five PLC addresses in the panel tag database: M110 and M111 as writable bits, M100, M101 and M102 as read-only indications.
  2. Place two momentary pushbutton objects, Forward on M110 and Reverse on M111. Leave the action momentary; a toggle or alternate action stores state in the panel and recreates the failure described above.
  3. Place three indicator objects beside the buttons on M100, M101 and M102. Light the Off lamp from M101 so the middle state is visible to the operator.
  4. Remove any radio button or multi-state object that writes M100, M101 or M102. Nothing on the panel writes the state bits, so the display always equals the PLC state.

Enter the state machine in the PLC

  1. Pulse each request once per scan: LD M110 feeding PLS M120, and LD M111 feeding PLS M121. The panel holds the request bit at 1 while the button is touched and writes 0 on release; the pulse rung reduces each press to one scan regardless of how long the touch lasts. How long the raw bit itself stays 1 is a panel timing question that How many PLC scans an HMI momentary button bit stays on walks through; the pulse makes the state machine independent of it.
  2. Write the SET rungs, effective from Off only, and keep them above everything that resets: LD M120 ANI M100 ANI M102 SET M100, then LD M121 ANI M100 ANI M102 SET M102.
  3. Write the RST rungs below the SET rungs: LD M120 AND M102 RST M102 for a Forward press while in Reverse, and LD M121 AND M100 RST M100 for a Reverse press while in Forward.
  4. Derive Off and the outputs at the bottom of the program: LDI M100 ANI M102 OUT M101, LD M100 ANI M102 OUT Y0, and LD M102 ANI M100 OUT Y1. Each output rung excludes the opposite state, so Y0 and Y1 cannot both be 1 even if a state bit is ever corrupted. Where both coils energized at once would be hazardous, keep a valve-manifold or hardware interlock as the second layer.

The SET rungs must sit above the RST rungs. The worked example and the trap list below show what that order changes.

Worked example: pressing Reverse from Forward

Assume the program completes a scan in 5 ms; small ladder programs typically run about 1 to 10 ms per scan, and 5 ms is a mid-range assumption. All state bits start at 0, so the machine starts in Off. The selector is running Forward: M100 1, M101 0, M102 0, Y0 1, Y1 0.

Press 1. The operator touches Reverse and the panel writes M111 to 1. In that scan M121 pulses for exactly 1 scan, 5 ms here. The SET rung for M102 checks ANI M100, sees M100 still 1, and does nothing. The RST rung LD M121 AND M100 clears M100. The output rungs then drop Y0 to 0 and raise M101 to 1. End of scan 1: Off, both coils 0.

The operator releases and presses Reverse again after 200 ms. At 5 ms per scan, 200 ms is 40 scans, so the second press lands in scan 42.

Press 2. M121 pulses again. Now M100 is 0 and M102 is 0, so SET M102 fires. Y1 rises to 1 and M101 falls to 0.

Scan Event M100 M101 M102 Y0 Y1
0 Running Forward 1 0 0 1 0
1 Reverse press 1 0 1 0 0 0
2 to 41 Idle in Off 0 1 0 0 0
42 Reverse press 2 0 0 1 0 1

The result is the required sequence: the opposite-direction press lands on Off, the second press energizes the other coil, and the Off dwell is simply the gap between presses. Both outputs at 1 together would need M100 and M102 both 1 at the end of one scan; every rung that sets one state checks the other first, so the pair cannot get there.

Two traps that skip the Off step

  • SET rungs below RST rungs. Put the resets first and Reverse from Forward completes in one press: the RST clears M100, and the from-Off SET rung later in the same scan sees M100 0 and M102 0 and sets M102 immediately. Off is skipped, which is exactly what the two-press sequence exists to prevent.
  • A request stuck at 1. The panel writes 0 on release; if the link drops mid-press, the 0 never arrives. The pulse rung limits a stuck request to one state change, and if the program has a communication-fault routine, clear M110 and M111 in it.
  • A press of the direction already running changes nothing in this ladder: its SET rung sees its own state bit at 1 and blocks, and its RST rung finds the opposite bit already 0. If operators want that press to return to Off as well, the snapshot variant in the FAQ does it safely.

How to check it worked

Isolate or vent the air to the cylinder first, so a wrong output cannot move the load. Open the ladder monitor and put the valve coil LEDs in view, then run the transitions:

  1. From Off, press Forward. Expect M100 1, Y0 1, Y1 0.
  2. Press Reverse. Expect M101 1 and both outputs 0. Press Reverse again. Expect M102 1 and Y1 1.
  3. Press Forward to return to Off, then press Forward again for Forward.
  4. Hold each button down for 5 s. The state changes once per press, because the pulse fires on the rising edge only.
  5. Press both buttons together from each state. The selector lands on Off every time, and Y0 and Y1 are never 1 together.
  6. Restore the air and confirm the cylinder motion matches the energized coil before releasing the screen to operators.

Confirm the writes themselves the way Operator panel PLC link setup: test writes before motion sets out: prove each button reaches the right bit before anything that moves is connected.

When to use this design

Recommendation: build any Forward-Off-Reverse selector on a dual-solenoid valve this way: two momentary request buttons on the panel, a SET-above-RST state machine in the PLC, the cross-interlocked outputs, and the four-transition test passed with the air isolated before operators use the screen. If the application never needs the Off step between directions, a single state bit per direction is simpler; keep this two-press design for the sequence described here. More builds that pair a screen with PLC logic are collected in the shop-floor screens section.

Questions

What does Off do to the valve itself?

Off in this design means both solenoid coils are de-energized. What the spool does next is a property of the valve. On a two-position valve with two solenoids, the spool commonly stays in its last position, so the cylinder holds where it was. On a three-position valve, the center condition decides whether the cylinder holds, drifts or drives. Read the valve datasheet before trusting the Off state with a hanging load or a gravity axis.

Can a second press of the running direction also return to Off?

Yes, with a snapshot. Copy the Forward and Reverse state bits into two scratch bits at the top of the program and build the SET and toggle-off rungs from the copies. Testing the live bits after a SET rung in the same scan sees the new state and clears it again before the scan ends, so the selector would never hold a direction. With the copies, a press of the running direction pulses the toggle-off rung once and lands in Off.

What happens to the selector after a power cut?

General internal relays in a compact PLC usually come back at 0 after a power cut, and only the ranges designated as retentive in the PLC parameter settings hold their state. With non-retentive state bits the machine wakes in Off with both coils de-energized and the operator selects a direction again, which is normally what a dual-solenoid valve wants after a power loss. Check where your parameter settings draw the retentive boundary before relying on the wake-up state.

Planning information, not legal or engineering advice. Rules differ by place: check codes and permits with your local authority and your licensed trades.

Keep reading

Build your signAsk for a quote