Interactive simulatorIntermediate

Line Maze Solver Simulator with LSRB Routing

Run a line maze solver in your browser: a taped maze, junction detection, and the LSRB substitution rules collapsing a dead-end route into the shortest one.

Category
Arduino
Time
2–3 hours
Platform
Browser · Arduino
Line Maze Solver Simulator with LSRB Routing technical schematicJUNCTIONS → L S R B → ROUTEBB

01 / Start here

Introduction

A line maze robot is a line follower that can also decide. This lab drives one along black tape, classifying each junction and writing a single character per move. When it reaches the finish you watch the LSRB substitution rules fire one at a time, folding every dead-end detour out of the record, until a string with no B in it remains—the shortest route, which the robot then drives again.

Live lab / Junction detection & LSRB route memory

Line maze simulator

A line follower drives a taped maze, recording every turn as L, S, R or B. Watch it back out of dead ends, then watch the substitution rules collapse that string into the shortest route — and drive it again.

Browser native
A line maze lab. A robot starts at the bottom-left of a taped maze and follows the left-hand rule to the finish at the top-right, recording one turn symbol per junction and backing out of every dead end. The LSRB substitution rules then collapse that record into the shortest route, which the robot drives again as a speed run. Use the controls below to run it or step one move at a time.

The dark lines are the tape. The orange trail is everywhere the robot drove while exploring, dead ends included; the teal line is the simplified route it speed-runs. The bar above the robot is its eight-channel reflectance array — a whole side lights up when a branch opens there.

  • Tape
  • Explored (dead ends included)
  • Simplified route
  • Finish

Route memory

The robot writes one symbol per move. Every B is a dead end it had to reverse out of.

Press Start — the string builds as the robot drives.

Simulation

Ready. Press Start to explore the line maze, or Step one move at a time.

Phase
Ready
Junction
Explored turns
— moves
Simplified turns
— moves
Saved
Maze

Keyboard: focus the maze, then use Space to run/pause, N to step, R to reset, M for a new maze, and F for full screen.

Controls

Mode picks between the full three-act run—explore, simplify, then speed-run—and jumping straight to the finished route. Run speed sets how fast the robot drives. Start, Pause and Step run it continuously or one move at a time, Reset replays the same maze, and New maze generates a fresh one. Focus the canvas and use Space, N, R, M and F for the same controls from the keyboard.

The route memory strip below the maze is the part worth watching. It fills in one symbol per move while the robot drives, then rewrites itself during the simplify phase as each substitution fires.

Theory

A line maze robot is built in two layers, and keeping them apart is what makes it tractable.

The lower layer is an ordinary line follower. An eight-channel reflectance array reads the tape, the readings collapse into a single weighted error, and a PID loop turns that error into two different wheel speeds. This layer knows nothing about mazes.

The upper layer only wakes up when the tape branches. It classifies the junction—left, right, T, cross, dead end, or finish—picks a branch by the left-hand rule, and appends one character to a string. The bar drawn across the robot’s nose in this simulator is that array, and you can watch a whole side light up as a branch opens.

The catch is that the instant reading is ambiguous. A T junction, a crossroads and the finish block all report every channel black. The robot has to commit past the junction and read again before it knows what it just crossed.

Algorithm

Exploration uses the left-hand rule: at every cell take the leftmost available option, and only turn back when a dead end leaves nothing else. On a maze with no loops that always reaches the finish, and it is stateless enough to verify by hand.

Every move appends a symbol. L, S and R are turns; B only ever appears where the robot reversed out of a dead end. So each B in the finished string marks a mistake, together with the turn before it and the turn after it.

That three-character window is always replaceable by a single turn, because the three moves are just angles that add up. Counting left as −90°, straight as 0°, right as +90° and back as 180°, L B L sums to 0°, which is S—drive straight through instead of entering the spur at all. The six substitution rules are that arithmetic, tabulated.

One pass is not enough: collapsing a detour can push two turns together that now form a new reducible window, so the rules are applied repeatedly until nothing changes. When the loop ends there is no B left in the string, which is the proof it is finished—any remaining dead end would still show one.

Source code

// Repeat until a full pass changes nothing: collapsing one detour
// can push two turns together that are themselves reducible.
void simplify(String& route) {
  bool changed = true;
  while (changed) {
    changed = false;
    for (int i = 1; i + 1 < route.length(); i++) {
      if (route[i] != 'B') continue;          // windows centre on a turn-back
      route = route.substring(0, i - 1)
            + fold(route[i - 1], route[i + 1])
            + route.substring(i + 2);
      changed = true;
      break;
    }
  }
}

fold is the substitution table, and it is short because it is only angle arithmetic: add the two turns either side of the 180° reversal, wrap into ±180°, and map the result back to a symbol.

Circuit diagram

The robot this lab models is the one in the line maze solver build path: an Arduino Nano reading an eight-channel reflectance array on its analog pins, driving two geared motors through a TB6612FNG.

The wiring rule that matters most is the power split. The motor battery reaches the driver’s VM pin and nothing else; the Arduino’s 5 V supplies logic only; and every ground—board, driver, sensor array, battery negative—must be tied together, or the control signals have no reference and the failure is silent.

Hardware checklist

Components

  • Arduino Nano or Uno
  • Eight-channel IR reflectance sensor array
  • TB6612FNG dual motor driver
  • Two geared DC motors on a 2WD chassis
  • Black electrical tape on a light board

Explore the graph

Where this simulator is used

The projects, learning paths, and tutorials that build on this lab.

Continue building

Download resources

Use these on-page references while working through the project. Downloadable project bundles will be added only after their source and version are published.

Common questions

Frequently asked questions

What is a line maze robot?

A line follower with a decision layer on top. The lower layer keeps the robot centred on black tape using a reflectance array and a PID loop, exactly as an ordinary line follower does. The upper layer watches for the moments the tape branches, classifies what kind of junction it is, chooses a direction, and records the turn. That record is what lets it run the maze a second time without a single wrong turn.

How is a line maze different from a Micromouse maze?

The world and the sensing are completely different. A line maze is black tape on a light board, read by a downward-facing reflectance array; a Micromouse maze has physical walls read by distance sensors. What survives the swap is the strategy—explore to gather knowledge, then run the best route. The line maze is far cheaper to build, which is why school and college competitions usually use one. Compare the two in the Maze Solver Simulator.

What does LSRB stand for?

Left, Straight, Right and Back—the four things a robot can do at a junction. The robot appends one character per move during the exploration run, and every B marks a dead end it had to reverse out of. Six substitution rules then replace each three-character window centred on a B with the single turn that would have had the same effect, which deletes the detour entirely.

Why can't the robot decide at the instant it sees a junction?

Because the sensor pattern is ambiguous. A T junction, a crossroads and the finish marker all light the whole array at once, and a left branch reads the same whether or not the line also carries on straight. The robot has to record which branches appeared, drive forward about one robot length, and read again to learn whether there was a way straight ahead. Deciding on the first reading is the most common cause of confident wrong turns.

Does LSRB work on every maze?

Only on a perfect maze—one with no loops, where exactly one route connects any two points. Taped competition mazes almost always are, and this simulator generates one. 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.

How much memory does this take on an Arduino?

Almost none, which is the whole appeal. The entire map is one array of characters—a few dozen bytes for a competition maze—because the robot never stores the maze itself, only the turns it made. A flood-fill robot by contrast keeps a distance value for every cell of a grid. That is the trade: LSRB is tiny but needs a loop-free maze, flood fill is heavier but copes with anything.

Further reading

References

Authoritative sources for going deeper than this simulator's bounded educational model.