Simulator

A joystick simulator: a thumb stick on an Arduino’s analog pins

Mokxi is a free online joystick module simulator that runs in your browser, with nothing to install and no account needed. A two-axis thumb stick on an Arduino Uno: X on A0, Y on A1, the push switch on pin 12, and eight LEDs as a bar graph. Drag the stick and the bar follows; press it and the bar switches to the other axis.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Arduino Uno: a joystick and an LED barlive0.000 s 0.00x
Hold the button
Click the circuit to open it in the editor, then drag the stick sideways and watch the lamps. Let go and it springs back to the middle: four lamps.

What you can do here

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

  • Drag the stick and read both axes with analogRead
  • See the center read 512 and the ends read 0 and 1023
  • Turn a reading into a number of lamps with map
  • Press the stick and read its switch
  • Use the stick to steer a servo, a motor or a game
  • Print both axes on the serial monitor

What the running circuit shows

Two potentiometers and a switch under one cap.

A thumb stick is two potentiometers at right angles, each dividing 5 V by where the stick is. At rest the X pin sits at 2.50 V, analogRead gives 512 and the sketch prints “X 512 -> 4 lamps”. Push it all the way right: 5.00 V, 1023, eight lamps. All the way left: 0 V and none. Three quarters of the way is 3.75 V, a count of 768 and six lamps.

The whole bar graph is one line of arithmetic, map from 0 to 1023 onto 0 to 8, which is the lesson of the circuit. Press the stick down and the switch on pin 12 closes; the sketch prints “reading the Y axis” and the bar follows the other potentiometer.

How the joystick is modeled

An ideal stick, which a real one is not.

Each axis is a real voltage divider between the stick’s supply and ground, so it works on a 3.3 V board as it does on 5 V, and the switch is a contact to ground that needs a pull-up, as on the module.

This stick springs back to exactly 512 on both axes. A real one comes to rest anywhere from about 490 to 530 and not at the same place twice, so a robot steered by one creeps when you let go. Real code treats a band around the center as zero. The switch here does not bounce; a real one does. Write the dead band and the debounce anyway.

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.

What values does an Arduino joystick give?

Each axis reads 0 to 1023 with analogRead on a 5 V Uno, with the center near 512. In this circuit the center is exactly 512; on a real stick allow a few tens of counts either way.

How do I wire a joystick module to an Arduino?

VCC to 5 V, GND to ground, VRx and VRy to two analog pins, and SW to a digital pin set to INPUT_PULLUP. The switch reads LOW when the stick is pressed.

Why does my joystick drift when I let go?

A real stick does not return to the same center each time. Subtract the center, and treat anything within a small band around zero as zero.

More simulators

Each one opens on a circuit that is already running.

Push the stick

Open the circuit, drag the stick and count the lamps. Nothing to install, and no account needed.