Simulator

A line follower simulator: a five-sensor cart on an Arduino

Mokxi is a free online line follower robot simulator that runs in your browser, with nothing to install and no account needed. A five-channel line tracker, two gear motors on a TB6612FNG driver and a two-cell battery pack, on an Arduino Uno. Drag the tape under the sensors and watch the sketch steer: the line goes right, the left wheel speeds up.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Arduino Uno: a line-following cartlive0.000 s 0.00x
Click to open it in the editor
The cart stays put, so the floor moves instead. Click the circuit to open it in the editor, then drag the tape sideways under the tracker and read the two wheel speeds on the serial monitor.

What you can do here

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

  • Drag the line under five reflectance sensors
  • Watch the sketch turn five readings into a position in millimeters
  • See proportional and derivative steering change the two wheel speeds
  • Take the line away and watch the cart search the way it last saw it
  • Lay down the finish bar and stop the cart
  • Tune the gains in the sketch and run it again

What the running circuit shows

Where the line is, and what the wheels do about it.

With the tape under the middle sensor the sketch prints “line 0 mm left 120 right 120”: both wheels at the cruising speed of 120 out of 255. Drag the tape 15 mm to the right and it settles at “line 15 mm left 165 right 75”. The left wheel speeds up by 45 and the right slows by 45, which is the gain of 3 times the 15 mm error, and the cart would turn toward the line. Drag it 15 mm left and the numbers swap.

While the tape is moving, the wheels answer harder than that. A second term looks at how fast the error is changing and adds to the correction, so a line that is running away gets a sharper turn than one that is sitting still off center. That is the D of a PD controller, and it is what stops a fast cart weaving.

Drag the tape clear of all five sensors and the line reads “searching, last -30 mm left -110 right 110”: the cart spins on the spot toward the side it last saw the line. Click the swatch to put a black bar under all five sensors, the finish line, and it stops.

How the cart is modeled

Real sensors, a real driver, and a floor that moves.

The tracker’s five outputs go to analog pins A0 to A4, each reading dark or light for the patch of floor under it, and the motors are driven through the TB6612FNG with PWM from the battery pack. The sketch is a complete line follower, the same code that would run on the cart.

What is missing is the loop through the world. The chassis does not drive across a track, so turning the wheels does not bring the line back under the sensors; you move the tape and watch the response. That makes it a good place to check the sensor math, the signs of the steering and the lost-line behavior. The final gains have to be tuned on a real track, because they depend on the cart’s weight, its motors and its speed.

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 line follower robot work?

Reflectance sensors under the front tell dark tape from light floor. The sketch works out how far the line is from the center and slows one wheel and speeds the other to turn back toward it. In this circuit a line 15 mm to the right gives wheel speeds of 165 and 75.

How many sensors does a line follower need?

Two will follow a gentle line by bouncing between its edges. Five, as here, give a position in millimeters, which allows smooth proportional steering and lets the cart recognize a crossing bar.

Does the cart drive around a track in the simulator?

No. The cart stays still and you drag the line under its sensors, then watch how the sketch drives each wheel. It tests the logic, not the lap time.

More simulators

Each one opens on a circuit that is already running.

Move the line

Open the circuit, drag the tape and watch the wheels answer. Nothing to install, and no account needed.