Build pathIntermediateA weekend

Build a Line Maze Solver Robot With LSRB Route Memory

A robot that explores a taped line maze on its own, remembers every junction it met, and then runs the shortest route from start to finish without one wrong turn.

Build a Line Maze Solver Robot With LSRB Route Memory technical schematicJUNCTIONS → L S R B → ROUTEBB

A line follower follows. A line maze solver decides. That is the whole jump this project makes, and it is a bigger one than it looks: the robot stops being a control loop with wheels and becomes something that explores an environment it has never seen, remembers what it found, and acts on that memory.

The trick is that none of it replaces the line follower—it sits on top of one. Underneath, the same reflectance array and the same PID loop keep the robot centred on the tape, knowing nothing about mazes. Above it, a thin decision layer watches for the moments when the line branches, classifies what kind of junction it hit, picks a direction, and writes down one character. That separation is what makes the project tractable, and it is the same two-layer split real robots use everywhere.

So the build order matters more than usual. You get plain line following genuinely stable first—tuned in the simulator, then on a large oval of real tape—and only then add junctions. Skip that discipline and every mechanical problem, every calibration drift, every wheel that is 2 mm out of alignment will show up disguised as a maze-solving bug.

Follow the tech tree below top to bottom. Each node opens once its prerequisites are done, and your progress is saved on this device, so you can build the robot over a weekend without losing your place.

Bill of materials

Part Qty Approx. cost Notes
Arduino Nano 1 $5 A0–A7 gives eight analog channels; an Uno’s six is not enough
IR reflectance array, 8 channel 1 $8–12 Eight, and analog. Junction detection needs the outer sensors
TB6612FNG 1 $3 Worth it here: the L298N’s ~2 V drop hurts the precise low-speed moves
TT gearmotor 2 $4 Encoder versions strongly recommended for repeatable turns
2WD chassis 1 $6–10
Battery pack 1 $6 2×18650, protected holder
Matte black tape, 19 mm 1 roll $3 And a large light-coloured floor or board to lay the maze on

Total: roughly $35–45. The 8-channel array is the one part not to economise on, and the reason is specific: a robot detects a left branch by noticing that the outermost left sensors have gone dark while the centre is still on the line. An array barely wider than the tape physically cannot see that, so junction detection becomes guesswork no matter how good the code is.

Why the array must be wider than the line

   left branch                    array (8 channels, ~60 mm wide)
   ────────────────┐          [ x x x . . . . . ]   outer left dark -> a branch
                   │
   ════════════════╪═══════   [ . . . x x . . . ]   centre still on the line
                   │

Rule of thumb: the array should be at least three times the tape width. For 19 mm tape that is around 60 mm, which an 8-channel array at 8 mm spacing gives you exactly. Narrower and the robot cannot distinguish “the line curved sharply” from “the line branched”, which is the central decision the whole project rests on.

Build it in milestones

The build order here matters more than in any other project on this site. A maze solver is a line follower with a decision layer, and every mechanical or calibration fault in the follower reappears disguised as a maze-solving bug.

# Milestone The test A pass looks like
1 Line following works Ten laps of a large plain oval Zero losses. Not “mostly” — zero
2 Turn repeatability Command a 90° pivot ten times, measure Within ±3°, and repeatable
3 Junction seen Drive over a T slowly, print the array Outer sensors go dark before the centre does
4 Junction classified Drive each junction type slowly Left / right / T / cross / dead end all named correctly
5 One turn executed Meet a left branch, turn left, resume following It reacquires the line and continues
6 Path recorded Drive a short maze, print the string A sequence like LSRB matching what you watched
7 LSRB simplification Feed the recorded path through the simplifier LBL becomes S, and every rule fires correctly
8 Second run Run the simplified path It reaches the goal with no wrong turns and no exploring
9 Full maze A maze with several dead ends Explores, simplifies, then runs the shortest route

Milestone 1 is not negotiable. “Mostly follows the line” becomes “occasionally invents a junction”, and you will spend an evening debugging path simplification for a fault that is really a wheel 2 mm out of alignment.

Milestone 2 is the one people skip. A maze solver executes hundreds of turns per run, and a turn that is consistently 5° short accumulates until the robot leaves the line entirely. This is exactly where gearbox backlash shows up — error that changes sign with direction is mechanical, not a tuning fault.

The two-layer split, in code

The separation that makes this project tractable is worth seeing explicitly:

             ┌─────────────────────────────────────┐
   decision  │  classify junction -> choose turn   │   runs only at junctions
     layer   │  record a character -> simplify     │   knows nothing about PWM
             └──────────────────┬──────────────────┘
                                │ "turn left" / "keep going"
             ┌──────────────────▼──────────────────┐
   following │  read array -> position -> PID      │   runs every loop, ~200 Hz
     layer   │  -> left and right wheel speeds     │   knows nothing about mazes
             └─────────────────────────────────────┘

The lower layer never learns what a maze is. The upper layer never touches a motor. When something goes wrong, that boundary tells you which half to look in — and if you cannot say which half a bug lives in, the layers are not properly separated.

What good looks like

Measurement Typical
Exploration speed 0.15–0.25 m/s — slow enough to classify junctions reliably
Return-run speed 0.3–0.5 m/s — no decisions to make, so it can push
Junction classification accuracy 100%. Anything less and the recorded path is wrong
Turn repeatability ±3°
Path simplification A 30-character explore path typically reduces to 8–12

Junction accuracy is genuinely all-or-nothing, and that surprises people. One misread junction corrupts the recorded string, the simplifier then produces a valid-looking but wrong path, and the return run confidently drives into a wall. There is no partial credit — which is why exploration runs slowly and the return run is where you gain the time back.

Troubleshooting

Symptom Likely cause Fix
Sees junctions that are not there A tight curve reading as a branch Widen the array; require the outer sensors to stay dark for a minimum distance
Misses junctions Driving too fast, or array too narrow Slow the exploration run; check the array is ≥3× the tape width
Turns are inconsistent Backlash, or no encoders Always approach a turn the same way; measure the play
Recorded path has extra characters Junction detected twice Add a dead time after a junction before looking for the next
Simplification produces a wrong path A rule applied in the wrong order Test LBL→S, LBR→B, SBL→R and friends in isolation first
Return run fails at the first turn Path recorded relative to the wrong heading The string is a sequence of relative turns — check the convention
Works on one maze, not another Junction spacing too tight for the dead time Reduce the dead time, or slow down further
Loses the line after a turn Turn overshoots past the new line Turn until the centre sensors reacquire, rather than by a fixed angle
Drifts worse as the run goes on Battery sagging, changing the effective gains Close a speed loop with encoders

Where to take it next

Add encoders and turn by distance rather than by time. Timed turns are the largest source of unreliability in a first maze solver, because the time needed changes with battery voltage and surface. Encoder-based turns do not.

Move to a walled maze — the micromouse — which replaces the tape with walls and the LSRB rule with flood fill. That is the genuinely bigger step: LSRB is a wall-following heuristic that finds a path, while flood fill computes the shortest one and replans as new walls are discovered.

Optimise the return run. Once the path is known, there are no decisions left to make, so the robot can accelerate on straights and slow only for turns. A motion profile over the known route is where the dramatic time improvements come from — often halving the return run.

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 / 21 done

100%
Build

Wire the robot

45 min

Build

Calibrate on your own track

20 min

Build

Get plain line following stable

60 min

Build

Run the exploration pass

45 min

Build

Replay the simplified route

30 min

Goal

Line maze solver complete

You built it

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

How do you make a maze solving robot with Arduino?

Start with a working line follower: a reflectance array, a PID loop, and a motor driver. Then add a decision layer on top that notices junctions, picks a branch by the left-hand rule, and records each turn as one of four characters—L, S, R or B. When the robot reaches the finish, substitution rules collapse every dead-end detour out of that string, and the second run follows the simplified route. This build path walks the whole chain, and you tune the following layer in a browser simulator first.

What is the LSRB algorithm in a line follower?

LSRB stands for Left, Straight, Right, Back—the four things a robot can do at a junction. The robot records one character per junction during exploration, and every B marks a dead end it had to reverse out of. Six substitution rules replace each three-character window centred on a B with the single turn that would have had the same effect, which removes the detour entirely. Repeat until no B remains and you have the shortest route.

What is the difference between a line maze and a walled maze?

A line maze is black tape on a light board, sensed with a downward-facing reflectance array; a walled maze—the Micromouse format—has physical walls sensed with distance sensors. The sensing is completely different, but the layer above it is the same: explore to build knowledge, then run the best route. A line maze is far cheaper to build, which is why school and college competitions usually use one.

Do I need to buy parts before starting this project?

No. The line-following layer, its PID gains, and the explore-then-optimise behaviour all run in the browser simulators, so you can understand the whole robot before spending anything. Only the last four steps—wiring, calibration, the exploration pass, and the replay—need the physical Arduino, sensor array, driver, motors, chassis, and battery.

Why does my maze robot turn at the wrong junctions?

Almost always because it decides too early. The instantaneous sensor pattern cannot tell a T junction from a crossroads—both read as black right across the array. The robot has to record which branches appeared, drive forward about one robot length, and read again to find out whether the line also continued straight. Deciding on the first reading is the single most common cause of confident wrong turns.

Does LSRB work on any maze?

Only on a perfect maze—one with no loops, where exactly one path connects any two points. Taped line mazes almost always are. If the maze contains a cycle, the left-hand rule can circle forever and there is no dead end for the rules to collapse; at that point you need a real map and a graph search such as flood fill instead.