Build pathAdvancedA few weekends

Build a Micromouse: A Flood-Fill Maze-Solving Robot

A robot that explores a walled maze on its own, builds a map of it, and then drives the shortest route from start to centre without a wrong turn.

Build a Micromouse: A Flood-Fill Maze-Solving Robot technical schematicWALL SENSING → FLOOD FILL

What you are building

A robot that is dropped into a maze it has never seen, finds the centre, and then drives back through the shortest route it can prove exists.

That second half is what makes a micromouse different from every other robot on this site. A line follower reacts. An obstacle avoider reacts. A micromouse remembers — it builds a map while driving, and then plans across cells it has not visited. It is the smallest complete robotics problem: sensing, motion, mapping and planning, all of which must work at once.

The two-run strategy

Competition mice get several runs and are scored on the fastest. That produces a strategy worth copying even when nobody is timing you:

Run one — explore. Drive carefully, record which cells have which walls, and reach the centre. Speed is irrelevant; the map is the product.

Run two — exploit. Flood fill the finished map, compute the shortest route, and drive it without stopping to sense anything you already know.

The split matters because the two runs want opposite things. Exploring wants slow, cautious motion and constant sensing. Speed-running wants commitment. Trying to do both at once produces a robot that is bad at each.

Why the algorithm is not the hard part

Flood fill is genuinely simple: give the goal cell distance 0, give every neighbour 1 more than the lowest neighbour it can reach, and then always step to a lower number. It is a few dozen lines and it is provably shortest on a grid.

The hard part is that it assumes the robot knows which cell it is in.

Miscount one cell, or turn 88° instead of 90° a few times, and the planner is now solving the maze for a robot that is somewhere else. The symptom is maddening: the algorithm is perfect, the wiring is fine, and the robot confidently drives into a wall.

So the build order below spends most of its effort on motion, and adds the planner last. You can prove the planner separately in the maze solver simulator, where position is exact by construction — which is precisely why simulating it first is worth the time.

Build order

1 — Get three clean distance readings. Front, left, right, using VL53L0X time-of-flight sensors. They share one I²C bus and boot at the same address, so bring them up one at a time by holding the others in reset and reassigning addresses at startup. Confirm each reads a wall at a known distance before mounting anything.

2 — Make it drive straight and turn square. This is the real project. Follow wall following and precise turns: a PID loop on the side sensors to stay centred, gyro-integrated turns instead of encoder counts, and re-squaring against a front wall whenever one is available. Do not move on until the robot can do ten turns and still face the right way.

3 — Count cells reliably. Encoders predict where a boundary should be; the falling edge of a side wall confirms where it actually is. When they disagree, believe the wall — it is a physical landmark, not an accumulated estimate.

4 — Record walls into a map. Two bits per cell for four walls, and a 16 × 16 maze fits in a few hundred bytes. Record what you see as you see it.

5 — Add flood fill. Now the planner has honest data. Recompute the distances whenever a newly discovered wall invalidates the current plan — that replanning is the whole reason flood fill is used rather than a one-shot search.

Hardware notes that matter

Small beats fast. The robot must turn within a cell. A tight chassis with the wheels near the centre of rotation pivots cleanly; a long one clips walls on every turn, and no amount of tuning fixes geometry.

Backlash is heading error. Every pivot turn reverses the motors, and a loose gearbox loses the first few degrees. N20 metal-gearbox motors exist for this reason.

Mount the side sensors slightly forward and angled. Pointing them straight out means they see a wall only when perfectly beside it, so the robot learns about the wall late. A small forward angle gives the control loop a preview.

Give the sensors a stable supply. A VL53L0X returns plausible-looking wrong numbers on a sagging rail rather than obviously failing — the worst kind of fault, because the map fills with walls that are not there.

When it goes wrong

Symptom Usually
Drives into a wall confidently Cell count is off — position, not planning
Ends up diagonal after several turns Gyro bias not subtracted, or turns not re-squared
Lurches into side openings Wall-presence check missing from the following loop
Maps walls that do not exist Sensor supply sagging, or crosstalk between modules
Solves it slowly, crashes fast Speed run too quick for the motion layer — slow it, then raise

Almost every entry in that table is a motion or sensing fault rather than an algorithm one. That distribution is the single most useful thing to know before starting, because it tells you where to spend your weekends.

If you want the mapping and planning ideas without the hardware, the maze solver simulator runs the same two-phase strategy in the browser, and the path planning and mapping roadmap carries it forward into A* and SLAM. For a much cheaper first maze robot, the line maze solver uses tape instead of walls and needs no distance sensors at all.

Project roadmap

The build path

Follow the tech tree from parts to a robot that follows a taped line. Each node unlocks when its prerequisites are done, and your progress saves on this device.

0 / 16 done

100%
Learning path

Path planning and mapping

Learning path

Open path
Build

Make it map the maze

Build

Goal

Make it run the route

Goal

Components

Tutorials in this path

Practise before you wire

Tune it in the live simulator

The build path routes through a browser lab. Find gains that follow the track cleanly here, then transfer them to the real robot.

Frequently asked questions

What is a micromouse?

A small autonomous robot that solves a walled maze, and the oldest continuously running robotics competition in the world. The standard maze is 16 by 16 cells of 18 cm each with the goal at the centre, and the robot gets no map — it has to explore, build one, and then drive the fastest route it can find. It is a complete robotics problem in a box: sensing, precise motion, mapping and planning all have to work together, and any one of them failing is visible immediately.

Why use time-of-flight sensors instead of ultrasonic?

Three reasons, all of which a maze makes worse. An ultrasonic beam spreads roughly 15 degrees, so in a narrow corridor it hits the walls either side of what you were aiming at. Multiple ultrasonic sensors interfere with each other, hearing each other's pings. And each reading takes milliseconds of flight time, which limits how fast your control loop can run. A VL53L0X has a narrow beam, is unaffected by its neighbours, and reads in about 20 ms.

Do I need a gyro if I have encoders?

For a maze, yes. Encoders measure wheel rotation, not robot rotation, and those differ every time a wheel slips — which is exactly what happens during a pivot turn. A 2 degree error per turn is unnoticeable once and fatal after ten. The gyro measures the robot's actual rotation directly, so turns stay square no matter what the wheels did.

How is this different from the line maze solver?

They are different robots that happen to share a word. A line maze is black tape on a board read by a downward reflectance array, and LSRB route memory collapses the dead ends out of a string of turns. A micromouse has physical walls, reads them with distance sensors, and must build an actual map of the maze in order to plan across cells it has never driven. The line maze is far cheaper to build; the micromouse is the one that teaches mapping.

Why does my robot solve the maze but crash on the speed run?

Because speed changes the physics, not the algorithm. Faster driving means more wheel slip, longer stopping distances, and less time for the wall-following loop to correct before the next cell. The usual fix is not more tuning but a slower speed run to start with, then raising it once the motion layer is proven. It is also why competition mice re-square against walls whenever they can — it is the only thing that removes accumulated error rather than limiting it.

Can I build a micromouse on an Arduino Uno?

For a first mouse, yes. The Uno can run three VL53L0X sensors and an IMU on I²C and hold a 16 by 16 wall map in a few hundred bytes. What it cannot do is compete — serious mice use faster 32-bit controllers so the motion loop can run in the kilohertz and the planner can recompute constantly. Build the slow one first; almost everything you learn transfers.