Simulator

A robot car simulator: an obstacle-avoiding Arduino car

Mokxi is a free online Arduino robot car simulator that runs in your browser, with nothing to install and no account needed. The first robot in most kits: a two-wheel chassis, an L298N motor driver, an HC-SR04 ultrasonic sensor on the front, an Arduino Uno and a 7.4 V battery pack. Put something closer than 25 cm in front of it and the car stops, backs up, turns and drives on.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Arduino Uno: an obstacle-avoiding carlive0.000 s 0.00x
Click to open it in the editor
Click the circuit to open it in the editor. The car drives ahead across the floor drawn in the chassis; drag the HC-SR04’s distance under 25 cm to put an obstacle in front of it.

What you can do here

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

  • Drive two motors forward, backward and in a spin turn through an L298N
  • Set the speed with analogWrite on the driver’s enable pins
  • Measure the distance ahead with an HC-SR04
  • Put an obstacle in front of the car by dragging a slider
  • Read each decision the sketch makes on the serial monitor
  • Change the stopping distance or the turn in the sketch and run it again

What the running circuit shows

Drive, look, back up, turn.

Press Run and the monitor prints “obstacle-avoiding car: ready”, the driver’s outputs go live and the car rolls ahead. The sketch pings the HC-SR04 over and over. With the nearest thing 30 cm away, nothing happens. Drag the distance to 24 cm and the monitor prints “obstacle at 240 mm: back up and turn”: both motors reverse, then one runs forward and one back so the car turns right on the spot, and then it drives on.

The wiring is the kit’s. The jumpers on the L298N’s two enable pins are off, so those pins take PWM from the Uno and analogWrite sets the speed. The module’s regulator jumper is on, so it makes its own 5 V from the 7.4 V pack, and the HC-SR04 runs from that. Get these two jumpers wrong on a real car and it either runs flat out or does not run.

How the car is modeled

Real motors and a real driver, on an open floor.

The motors are driven by the L298N as on hardware, including the two to three volts the driver loses, which is why a car on a 7.4 V pack is slower than the numbers on the motors suggest. The chassis turns the two wheel speeds into movement across the floor drawn inside it, so you can see forward, reverse and a spin turn.

The floor has no walls. The sensor sees whatever its slider says, which is your obstacle, and nothing else; the car does not bump into anything. So this tests the sketch’s decisions and the wiring, which is where a first robot car usually fails, and not how well it gets around your living room.

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.

Can I simulate an Arduino robot car online?

Yes. This page runs a complete obstacle-avoiding car: an Uno, an L298N, two motors, an HC-SR04 and a battery pack, with the sketch a kit car runs. You place the obstacle by dragging the sensor’s distance.

Why does my robot car go in circles?

One motor is wired backwards, so “forward” spins the wheels in opposite directions. Swap that motor’s two wires at the driver, or swap its two direction pins in the sketch.

Can an L298N run from a 7.4 V battery?

Yes, and with the regulator jumper on it also supplies 5 V for the sensor. Expect the motors to see two to three volts less than the pack, which the driver loses.

More simulators

Each one opens on a circuit that is already running.

Put a wall in front of it

Open the circuit, drag the distance under 25 cm and watch the car back away. Nothing to install, and no account needed.