Maze Solving mBot


I’m teaching a mid-winter break camp this February, and the capstone project will be to create a maze solving program for the mBot. There were several challenges involved in figuring out how best to solve the problem with a stock mBot, but perseverance always pays off (a bit of ingenuity helps too!). :slightly_smiling:

Here’s a video of the hardy little mBot (that could) solving the maze mBot solving a maze.

Granted, it’s not a really optimized maze-solver nor does it solve all mazes equally well, but the code is all written in the mBlock (Scratch) environment. More advanced algorithms will require writing in the Arduino environment, but that’s a task for another course. :slightly_smiling:


Love it. It works great and seems like you are using a left wall follow mode. Great stuff.


I would love to see that code :wink:


That’s awesome! Are you planning to put the Arduino or at least the .sb2 up somewhere?


I’ll be putting all of the code for the class I’m teaching in a Github repo after I teach the class so that I can properly document everything in the ebook I’ll be publishing in late March/early April. The ebook will have the lessons, exercises, etc. as well as set up information and lessons learned.

I’m looking at a $5-$10 price tag for the ebook to help fund the robotics team I’m sponsoring, but the primary intent is to encourage robotic programming and to help others. The kids in the team want to get the Ultimate Robot kit and are looking for ways to earn the moneys to do so, and this seems like a good way to help them out.

With regard to the algorithm, it’s a simple wall follower (left hand wall). I’m using the black lines for navigation (moving forward and turning). The robot stops when the linefollower sensor returns 4 (both sensors off of the line). I was trying to use the ultrasonic sensor for ranging, but it proved to be too jittery/inaccurate for my needs, so I ran a series of tests to determine how long the motors needed to run to cover a certain distance at a certain speed. I use the ultrasonic sensor to detect whether or not a wall is in front of the robot (hence the frequent turns to test for an intersection).


Well done @chuckmcknight! Love the project and I’d be happy to buy your book. Can you please let me know when it’s available? Email me at

Thanks! :smiley:


No worries, I’ll be posting an announcement as soon as it’s available. I’ll be sure to send you a follow-up email too. :slight_smile:


Amazing, it is so cool!. One question, MBOT only have two IR sensor? If you don´t use another IR, I suposse you follow the line and turn left every fixed period of time, because you can´t detect with IR the crossing, right?

I like so much teach robotic using challengers.



Yes, I’ve measured the time it takes to cover the distance between room centers and use that as a stopping point to check for intersections with the ultrasonic sensor.


Thank you, I will try to do it in our class.



Can you give me the code? My email: Thx.


Look into
There’s project A-Maze-ing and lot of other interesting projects.


The code repo is a companion to the book, A Gentle Introduction to Robotics which can be purchased at All of the proceeds from the sale go to help fund school robotics programs so give a thought about buying a copy to help the kids. :slight_smile:


Hi , i’m Julien i live in french , i search a code for solving maze with mbot , for a project with my classes, if u can reply fast please ! , Thanks you for me and my classes. have a good day



Merhaba. Ben de labiren çözen yaptım. İnceleyin mutlaka. Kodlar da var


Firstly I did not know about that matter which will you shared here, I am really surprised to know that,But after follow AVG Antivirus Support Number blog, now I am able to know little bit.


I tried loading the code, and there are blanks in quite a few of the comparison expressions, and one of the assignment statements. What might be wrong?
Also is this using the line sensor included with the mBot, or some different hardware from somewhere else? It was hard to follow the discussion