Simulator

A keypad simulator: a 4x4 keypad door lock on an Arduino

Mokxi is a free online 4x4 keypad simulator that runs in your browser, with nothing to install and no account needed. A 4x4 membrane keypad on eight pins of an Arduino Uno, with a relay, a lamp and an RGB LED. Click 1234 and # on the keys and the relay pulls in for three seconds; any other code is turned away.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Arduino Uno: a keypad door locklive0.000 s 0.00x
Click to open it in the editor
Click the circuit to open it in the editor, then click 1, 2, 3, 4 and # on the keypad. The serial monitor shows each key as it arrives.

What you can do here

In the circuit above, or in the editor it opens.

  • Click any of the 16 keys on the canvas
  • Watch the sketch scan the rows and read the columns
  • Enter a code and switch a relay with it
  • See each key arrive on the serial monitor
  • Change the secret code in the sketch
  • Put the scope on a row pin and see the scan pulses

What the running circuit shows

Sixteen keys on eight wires.

A keypad has no chip in it. It is 16 switches at the crossings of four row wires and four column wires, here on pins 9 to 6 and 5 to 2. The sketch pulls one row low at a time and reads the four columns through their pull-ups; a column that reads low means the key at that crossing is down. Sixteen keys, eight pins.

Click 1, 2, 3, 4 and the monitor prints “typed 1”, then “typed 12”, up to “typed 1234”. Press # and it prints “code accepted: door open”, the LED goes green and the relay pulls in, lighting the lamp that stands in for a door strike. Three seconds later it prints “locked again”. Type 999# and you get “wrong code” and a red flash.

How the keypad is modeled

Real switches in a real matrix.

Each key is a switch between its row wire and its column wire, so the scan in your sketch works for the same reason it works on hardware, and fails for the same reasons too: swap two wires and the wrong keys appear. Ghosting is modeled as well: with three keys held at three corners of a rectangle, the key at the fourth corner reads as pressed, as it does on a bare matrix.

What it leaves out is contact bounce: a key here closes once, cleanly. A real membrane key can chatter for a few milliseconds, which is why keypad libraries wait a moment before they believe a key. Keep that debounce in your sketch even though this keypad does not need it.

How it works

Three steps from a blank tab to a running circuit.

  1. Open the editor

    It runs in your browser tab. Nothing to install, and you need no account to start.

    Your first project
  2. Wire it and write the code

    Drag parts onto a breadboard, run each wire from pin to pin, and write the sketch beside it.

    Wiring
  3. Press Run

    Your sketch compiles in the tab and runs on a model of the chip, with the Serial Monitor beside it.

    Run and serial
Reviews

What makers say about Mokxi.

“The AI checker helps check and correct my circuits, and it has way more components than Tinkercad. As a student I really appreciate the tool.”

ChloeEngineering student

“I’d been looking for a real online electronic simulator that was intuitive and complete when I found Mokxi. I was able to quickly import a Fritzing file and my Arduino sketch and start testing. Mokxi has all of the makings for the best online Arduino simulator I have been able to find!”

JayModel builderFeatured in his DioramaOS post

“I’m using Mokxi to develop and simulate an STM32-based four-wheel-drive robot car before building the actual hardware. It allows me to experiment with DC motor control, PWM, RPM measurement using photointerrupters, and different acceleration, braking, and reversing strategies, helping me understand and refine the system before implementing it in real life.”

NusretRobot car builder, Hamburg

Share your story

FAQ

Questions, answered.

Is it free?

Yes. The circuit on this page, every part in it and the editor it opens in are on the free plan, with no card.

Do I need an account?

No. The circuit runs the moment the page does, and the editor opens without one. A free account is only for saving a project to the cloud and sharing it by link.

How does a 4x4 keypad work with only 8 pins?

The 16 keys sit at the crossings of 4 rows and 4 columns. The sketch drives one row low at a time and reads the 4 columns; a low column names the key. The scan repeats so quickly that a press looks instant.

Which pins does a keypad use on an Arduino Uno?

Any eight digital pins. This circuit puts the rows on pins 9, 8, 7 and 6 and the columns on 5, 4, 3 and 2, the order most tutorials use. Avoid pins 0 and 1, which the serial monitor needs.

Why does my keypad show the wrong keys?

The rows and columns are wired in a different order from the one the sketch expects. If 1 prints as A, or the rows come out mirrored, reverse the order of the pins in the row or column list rather than rewiring.

More simulators

Each one opens on a circuit that is already running.

Type the code

Open the circuit, click 1234 and # and hear the relay pull in. Nothing to install, and no account needed.