Scan a keypad matrix from PLC discrete inputs

8 min read · Published November 10, 2026

Energize one of four row outputs at a time, read the five column inputs each scan, and accept a key only after three identical sweeps. That reads 20 keys from 9 I/O points, with the row switched at the end of one scan and read on the next, and a 40 ms debounce at a 5 ms cycle.

A keypad with no common and no power supply is the easiest kind to read from a PLC. Drive one row at a time from four discrete outputs, then read the five columns as discrete inputs. The one intersection that reads ON is the key that is down. A 4 x 5 pad of dome switches therefore uses 9 I/O points for 20 keys, and it draws nothing except the input current your PLC supply already provides. This article gives the wiring with the bleed resistors that hold idle columns OFF, the four-step scan, the debounce that stops contact bounce from making false keys, and the bench check that proves all 20 positions before any key reaches machine logic.

20 keys from 9 points

An r by c matrix reads r x c keys on r + c points. One switch per input, the same pad would need 20 input points; the matrix saves 11. The cost is time: the controller visits one row per scan, so a key is seen on one sweep in four. A deliberate press holds the contact down for 100 ms or longer, so the sweep costs nothing that matters.

Keypad Keys I/O points Points saved
4 x 4 16 8 8
4 x 5 20 9 11
4 x 6 24 10 14
8 x 8 64 16 48

Past 8 x 8 the sweep and the terminal count both get heavy; that is where a keypad that reports key codes over a serial link starts to win.

What you need

  • Four spare discrete output points, relay or transistor, fed from one 24 V DC supply.
  • Five spare 24 V DC input points and their input common.
  • A 4 x 5 keypad of plain momentary dome switches, one switch per position, no common bus.
  • Five 10 kΩ bleed resistors, quarter-watt or larger.
  • A meter and a 20-position checkout sheet.

The keypad takes no supply of its own and has no common terminal. The row output is the only source on the matrix; a key is a switch that hands the row voltage to one column. The electrical reference is made on the PLC side, in the input circuit.

Wire the rows and columns

Label the wires R1 to R4 and C1 to C5 on the drawing; those are drawing names, not PLC addresses. Each of the four rows lands on its own output point, each of the five columns on its own input point, and every key joins exactly one row to exactly one column.

Use the outputs as the +24 V source and the inputs as loads returning through the input common. With a row driven and its key down, current runs output point, closed switch, column input, input common. A 24 V DC input point typically draws on the order of 10 mA when ON; the module's input specification prints the exact figure, and the row output carries it plus the bleed.

The 10 kΩ bleed resistor is what makes an idle column read OFF. A column joined only to switch contacts floats when no row is driven, and a floating input reads unpredictably. The bleed holds each column at 0 V and carries 2.4 mA when that column's key is down: 24 V / 10,000 Ω = 2.4 mA, which is 58 mW of heat, so a quarter-watt part runs cool.

If your inputs expect the opposite polarity, mirror the topology: rows driven to 0 V, columns pulled up to +24 V through 10 kΩ, input common wired to the module diagram. The scan program is identical.

Keep the four row points off limits to the rest of the logic. A shared point that another rung energizes puts two rows live at once, and the decode fills with phantom keys.

The scan sequence

  1. On the first scan, initialize all four row outputs OFF.
  2. Drive exactly one row ON; leave the other three OFF.
  3. Read the five column inputs and store the 5-bit pattern tagged with the row number.
  4. At the end of the scan, advance: current row OFF, next row ON.
  5. Read the new row on the next scan, so it has had a full cycle to settle before you sample it.
  6. After row 4, wrap to row 1. A drum or step-sequencer instruction runs the same sequence; the instruction changes none of the wiring or timing.

Switch at the end of the scan and read on the next, and a column reading is never credited to the previous row. One sweep is 4 scans.

Decide what the outputs do when the program stops. A retentive hold-last-state configuration keeps outputs at their last state across a stop, so a program halted mid-sweep parks a row ON. The first-scan initialization in step 1 clears that on restart, and the difference between retentive bits and live outputs is explained on why retentive bits hold an output's last state.

A deliberate press holds a key down for 100 ms or more, so one press spans sweep after sweep no matter how fast the controller cycles. How many scans a momentary button bit stays on works the same arithmetic from the input side.

Accept a key on the third identical sweep

Dome and leaf contacts bounce for a few milliseconds when they close, usually settling inside 10 ms. Read the raw pattern and the flicker decodes as several presses.

Debounce per row: count consecutive sweeps whose 5-bit pattern is identical with exactly one column ON. Accept the key on the third identical sample and latch the decode. Then require one sweep with all five columns OFF before another key on that row is accepted, so a press yields exactly one event.

Reject everything else. A sweep with two columns ON is either two real keys or a ghost path, and a bare switch matrix makes both look the same, so discard the sample. The ghost is real current, not noise: with R1C1, R1C2 and R2C2 held, current walks from the driven R2 line through the R2C2 and R1C2 keys onto the R1 line, then through R1C1 onto C1, and the scan of R2 reports the phantom fourth corner. A one-key-at-a-time station gets that protection from the rejection rule alone; when the job truly needs simultaneous keys, fit a keypad with a diode in series with every switch, which blocks the walk-back path.

Decode an accepted key into an entry buffer rather than a bare coil. Saving each entry to the next table word is the pattern for numeric entry.

Worked example: a 20-key pad on a 5 ms scan

The inputs: 4 rows and 5 columns, the pad itself, 20 dome switches with no common and no keypad supply; a 5 ms scan cycle, a declared mid-range figure for a small fixed-I/O controller running light logic, which cycles in about 1 to 10 ms, so substitute the cycle you measure on your own machine (the load sweep method is on finding a runtime cycle time limit with a load sweep); 3 identical samples, the debounce count set in the program; and a 10 ms bounce ceiling, the usual upper end for dome contacts.

The rule in words: the sweep period is the row count times the cycle time, and the debounce time is the number of intervals between the first and last accepted sample times the sweep period.

The arithmetic:

  • Keys and points: 4 x 5 = 20 keys on 4 + 5 = 9 points.
  • Sweep: 4 x 5 ms = 20 ms, so row 1 is sampled at 0, 20 and 40 ms.
  • Debounce: (3 - 1) x 20 ms = 40 ms from the first clean sample to the accepted key.
  • Margin over bounce: 40 ms / 10 ms = 4.
  • Column bleed: 24 V / 10,000 Ω = 2.4 mA; a key down asks the output for about 12.4 mA, the input plus the bleed.

The result: a press is accepted 40 ms after the first sweep that shows it, and bounce up to 40 ms is absorbed on the way.

The decision: at a 5 ms cycle, three samples give a 40 ms debounce and sit comfortably inside a 100 ms press. The threshold is the bounce you observe: above 40 ms of bounce, move to five samples, which lands at 80 ms at this cycle, and at a 10 ms cycle the same three samples already give 80 ms.

Bench check before you trust it

Wire and prove the keypad with its decoded keys disconnected from machine actions; that is the safety rule for this job, because a mislabeled key that reaches a start rung is a live hazard. Reconnect after all 20 positions pass.

  1. With the controller stopped and all row outputs OFF, meter each column terminal: it reads 0 V. Any other reading is a short to +24 V or a missing bleed.
  2. Run the scan and watch the row outputs: exactly one ON at any moment, stepping R1 through R4 and wrapping.
  3. Press one key and watch the inputs: only its column toggles, ON for the hold and OFF on release.
  4. To test one row electrically before the program exists, force that single output with the scan logic out of the controller; the rules for forcing inside the cycle are on how forcing works inside the PLC cycle.
  5. Fill the 4 x 5 checkout sheet: all 20 positions, the input pattern each produced, the key each decoded. Press slowly and tap quickly on every position.
  6. Hold two keys and confirm the decode rejects the sample. Then close the enclosure, dress the cables and repeat one row of the sheet.

Pass looks like: 20 unique decodes, five columns OFF with no key down, no position decoding twice, and row outputs stepping cleanly. A swapped row and column wire shows up here as a wrong position decoding, which a clean-running scan never reveals.

The decision

Recommendation: Build the pad as four sourced rows and five bled columns, switch the row at the end of each scan, read it on the next, and accept a key on the third identical sweep with exactly one column ON. At a 5 ms cycle that is a 20 ms sweep and a 40 ms debounce, for 20 keys on 9 points. Keep the station to one key at a time and discard every two-column sample. Past 64 keys, past a need for simultaneous keys, or past a long cable run, specify a diode-isolated keypad or one that reports key codes over a serial link and decode the codes in the PLC.

Questions

What changes for a 4 x 4 keypad?

Drop the fifth column input and keep everything else: 16 keys from 8 points, one sweep every 4 scans, and the same three-sample rule. The row count sets the sweep, so a 5 ms cycle still debounces at 40 ms; only the decode table shrinks from 20 positions to 16.

Does it change with relay outputs instead of transistors?

A relay output point takes about 10 ms for the contact to move, so drive the new row at the end of one scan and read its columns two scans later. The sweep at a 5 ms cycle stretches to roughly 40 ms and the three-sample debounce to 80 ms, which still lands inside a deliberate 100 ms press.

Why does a column input stay ON with no key pressed?

With the controller stopped and every row output OFF, a column should sit at 0 V through its bleed. One held ON has a live path with nothing selecting it: a wire shorted to +24 V, a welded switch contact or a missing bleed resistor. Meter the column terminal, then the terminal strip, then the switch itself.

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