A robot in a maze has no map and no eyes โ only whatever its sensors report right now. Navigation is a non-stop loop: sense (how far is the nearest wall ahead, left and right?), think (which way should I go?), act (drive or turn). This page lets you drive that loop yourself, or hand it to two classic control rules.
Why simple rules work: the wall follower is the "keep one hand on the wall" trick you know from real mazes. The right-hand rule always tries to turn right first, then straight, then left, then back. In a maze with no freestanding wall islands, this eventually drags the robot past every corridor โ including the exit. It is dumb but tireless, and it needs no memory of where it has been.
Why planning beats reacting: a wall follower wanders into every dead-end pocket that hangs on its sensing side. A search algorithm (here: BFS โ breadth-first search) computes the provably shortest route in steps before moving a single wheel. Compare the two on the same maze and you have the central trade-off of robot navigation: zero memory + simple rule vs one map + guaranteed best route.
Where you see it in real engineering
Robot vacuums hug walls and skirting boards exactly like the follower modes; warehouse robots and delivery drones run BFS/A*-style searches over a stored map; the Micromouse contest (robots solving 16ร16 mazes) is won by teams that plan with flood-fill โ BFS's big sibling โ and only fall back to wall-following when the map is unknown.
๐งฎ The maths
v = n ร scell v โ robot speed (m/s) n โ speed setting (cells/s, slider) scell โ maze scale, 1 cell = 0.3 m (fixed here for realism)
tmove = 1/n ยท tturn = 0.5/n tmove โ time for one cell-to-cell move (s) tturn โ time for one 90ยฐ turn (s)
dsensor = (k + ยฝ) ร scell dsensor โ reported distance to the next wall (m) k โ number of fully open cells before that wall in the beam direction
ฮท = stepsopt / stepsactual ร 100 % ฮท โ route efficiency (%) stepsopt โ BFS shortest-path length (steps) stepsactual โ steps your run took (a step = one cell move)
BFS explores the maze outward from the start cell, one ring of neighbours at a time; the first time it touches the exit, the path it followed is guaranteed to be the shortest possible in steps. It runs the moment the page loads โ the gold dashed line on the canvas is the result.
Worked example: suppose BFS finds a shortest route of 18 steps and your run takes 30 steps: ฮท = 18 / 30 ร 100 % = 60 %. The real numbers for this maze appear live in the workspace โ the right-hand follower lands near 63 %, can you do better? A speed of 1.5 cells/s is 1.5 ร 0.3 = 0.45 m/s, and one cell then takes 1/1.5 โ 0.67 s.
Assumptions & limitations: the robot is a holonomic disc on a grid โ it moves cell-to-cell and turns exactly 90ยฐ instantly in terms of dynamics (turns only cost time, never momentum or wheel slip). Wall detection is perfect: the simulated sensors have no noise, no range limit and no mis-readings, which real ultrasonic or IR sensors cannot promise. The 0.3 m cell scale is a teaching convention. Bumps are a stylised animation, not a contact-force model. This simulation is an educational approximation of a real differential-drive robot navigating with range sensors.
๐น Simulation workspace
Controls
Keyboard works too: โ = forward, โ = rotate left, โ = rotate right (Manual mode). A blocked forward move bumps: it costs time, adds a collision, and gets you nowhere.
Live measurements
Steps taken0
Distance (m)0.00
Time (s)0.0
Collisions0
Efficiency (%)โ
Ready โ press โถ Run (or drive in Manual mode).
Efficiency = BFS optimal (17 steps on this maze) รท your steps ร 100. It is finalised when you reach the exit ๐.
Scale: one cell = 0.3 m, so the maze is 3.6 m ร 2.7 m โ a desktop robot arena. Sensor beams are drawn from the robot to the next wall in each direction, with the measured distance in metres.
๐ Graphs
Distance travelled (m) against elapsed time (s) for the current run. A steeper line = faster robot; a run with detours climbs in bursts and plateaus during turns and bumps.
๐งช Guided experiments
๐ Engineering challenges
๐ Real-world applications
๐งน Robot vacuumsWall-following is literally how many vacuums trace room perimeters and find their dock when the map is unknown.
๐ฆ Warehouse robotsAmazon-style AMRs run Dijkstra/A* โ BFS's weighted big brothers โ over a stored floor map, then follow it with wheel encoders corrected by sensors.
๐ Micromouse contest16ร16 mazes, 35 years of history: first-timers use wall-following, winners use flood-fill (BFS) after exploring, then sprint the optimal route.
๐ Search & rescueSnake and tracked robots enter collapsed buildings with no map: senseโthinkโact loops with range sensors are the only option.
Try it with hardwareBuild a 2-wheel Arduino UNO R4 (or ESP32) robot with three HC-SR04 ultrasonic sensors pointing ahead, left and right โ that is exactly the sensor layout simulated here. Print a maze like this one on A3 paper with walls from folded cardboard, and port the right-hand rule to C. Pair it with our Ultrasonic Distance Sensor simulation to learn how the ranging works.
โ Check your understanding
๐ What you discovered
Navigation is a loop: sense โ think โ act, repeated continuously โ no single step is clever, the loop is.
The wall follower needs no memory and works in simply-connected mazes, but it wanders into every pocket on its sensing side โ here it needs 27 steps where 17 exist.
BFS plans first and drives the provably shortest route (the gold line) โ but it needs a map, which a real robot must build or be given.
Hand choice matters: the left-hand follower ignores right-side pockets and scores 89.5% here โ the same maze can flatter or punish a rule.
Distance sensors replace eyes: three range numbers per instant are enough to navigate.
โก Engineering takeaway: a simple reactive rule will always get you there in a well-behaved maze, but only a plan can get you there efficiently โ good engineering is knowing when each is enough.