Picture of Maze Solving Robot

In this instructable I will be showing you how to build a maze solving robot. This is actually my 3rd attempt at making one. The first was a complete failure. The second was alright at finding the end of the maze, but it could not go back and drive the quickest path. This is my current and 3rd one. It is able to find the end of the maze and then, when put back at the start, drive the shortest path to the end of the maze without going down any dead ends. What surprises me is that it really does not mess up. 

This was just a short introduction, everything else from theory, building, and programming will be explained in later steps. 

Parts list:

General Parts:
  • 3 1in Spacers (Home Depot)
  • Bolts and nuts that fit the spacers (Home Depot)
  • Hook up wire (I use 22 gauge)
  • Solder
  • .100" Female and Male headers
  • Velcro

  • Soldering Iron
  • Philips Screw driver
  • Wire Strippers
  • Something to cut the wire with
AjayD made it!4 months ago

Sir,I had tried working Hard to make this BOT and it turned out pretty well.It took more than a month and a half to make it.Finally made it.I just made minute changes in the code.The results were actually amazing.....here is the link of the vid.....Sorry about the middle finger in the video.Those were for my friends they thought that I couldn't make it.....Would soon write Instructable on it....Thank you for this....



BTW Ajay, where did you find those sensor arrays?

patrickmccb (author)  AjayD4 months ago

Nice job!

g.knightz5 months ago

brilliant work you have done.. can this project use only 5 sensor.. help is needed..

g.knightz5 months ago

urgent help... can i use arduino mega, and digital line sensor instead of analog line sensor, also can i use 12v dcmotor for for this project .. i provide link of component that i want to use and need your advice does it can be use..



frafi13 years ago
hi. I dont get the exact parts which you used. firstly, can i use a arduino uno instead of the one which you used?

can i use regular DC motors? (http://www.rhydolabz.com/index.php?main_page=product_info&cPath=121&products_id=815)

and can i use a motor driver (http://www.rhydolabz.com/index.php?main_page=product_info&cPath=108&products_id=858)

if yes, could you please guide me through the process, it would be of great help.
sadam khan frafi15 months ago

dear can you send me its complete codes ?

patrickmccb (author)  frafi13 years ago
That motor driver will work, but you do not want that motor. That motor operates at 12 volts. You would have to get a 12v battery pack and regulate it down to 5v for the other parts. I would find a 5v motor.
sadam khan5 months ago

need its complete codding please .

Afroty5 months ago

I can't get the code. Can somebody reupload it please.

To which pin in arduino should we connect the 2nd pin right next to VCC

AjayD6 months ago

Sir,you didn't mentioned the value of the Cap on the Motor Controller Ckt.Also you have not included that in your PCB.Is is not necessary??

Plz give me code with atmega avr 16/32..if it's teotorial i'll highly appreciate that.

Ken908919 months ago

Hey Patrick, the link for the code has expired. Do you think we can get an updated one?

Victora410 months ago

the code not download, please help me!!

Mate can u explain the this value for me ? because im not using the same sensor

(leftCenterReading>200 ||
why is 200?

Well done. Honestly I have to say that was the best tutorial I could find on a line solving robot but I have one question. Where can I get the code because the code no longer exist anymore. Can you help me out there. Thanks. :)

Nevermind I found the code I believe something must be wrong with my internet. Wish me good luck improving it. :)

ajayo21 year ago

Great Work...
Can i use EEPROM library to store the path?
U didn't used an LCD... So, were u testing the path and storing the character using serial monitor all the time?

petrisor231 year ago

A question:

how is your PWM pin?

petrisor231 year ago

A question:

I have a l298 driver and Arduino Uno V3

can you help me to change the code for my robot?

Crazyspud1 year ago


Did you use the 30:1 motor or a different ratio? mMy robot is extremely fast (almost out of control)


shary7021 year ago


The robot I have built does not move in a straight line i.e. it keeps getting off the black line always.

Can you provide me a solution for this?

robozaurus1 year ago
Hey, nice work. I'm building a maze solver myself but I have one question if I leave the start point and have a L shaped turn to the right, according to the algorithm I can't make left so leaves my 2 options go straight or turn right, my issue is how do I detect if I can go straight or not, since all the sensor are on the same line, they will be both true for right and straight even if in fact i can't go straight because it's a turn. I tought using another sensor ahead, offseted forward from the line sensors array. Waiting for an answer. Thanks :)
patrickmccb (author)  robozaurus1 year ago
You have to drive forward some to see if the line continues on (i.e. you can go straight) only then does the robot make the decision. This motion is kind of disguised because the robot has to drive forward anyway in order to turn in place and end up centered on the line.
Good ideea, will try that. Thank's for the input. :)
jaseel11 year ago
Can u give the PCB layout of ine sensor array?
patrickmccb (author)  jaseel11 year ago
I did not make the line sensor array. You should be able to get more information about it by visiting the Pololu website.
ggonzales1 year ago
Hi. .do you have a "C" program for this? I need it for my school project. We're using ATmega32u4 as our microprocessor. I would be very thankful of you. :)
frafi13 years ago
can i use a arduino uno to do this project..
and could you plz tell more specifically how to make the motor controller?
patrickmccb (author)  frafi13 years ago
Any Arduino should work. The motor controller is outlined on step 8. I provided the schematic in the photos. A schematic is about as clear as I can make it. You can also google for L293D or SN754410, both have the same pinout and are pretty common so there are probably other articles on them.
how to get motor controller from dorkbot..?
plz help me.!
kumaran2013 years ago
Great work!!!! i had a query... Do i have to make changes in your coding When i use Arduino UNO?
can i use cny 70 sensors for this project ?
muno13 years ago
So I wrote some code to test the sensors and I realized that the sensors are not sending any signal back to the microcontroller. So I removed the sensor from the design and I put on 5V from the board and the ground from the board and put the entire senor on a piece of black tape (for it to set all of the outputs to around 5V) then I put an led on each hole and realized that it isnt lighting up at all. Is it an adequate conclusion to come to that the sensor is defective? Thanks again for all the help.
muno13 years ago
I have finished building the design with the same motors and chips you have used except I used an arduino uno. but I am running into issues when I first put in the power both motors go forward about an inch and then stop. I am not sure what to do to solve this issue I have it on a straight black tape maze right now just to see if it is working but I am not sure what could be the issue, is there any way to test if the sensors are working or any way to isolate the problem, and as always thank you for your help.
patrickmccb (author)  muno13 years ago
You can write some code to see if the sensor readings are correct. A common issue I have seen is that people do not put their sensors close enough to the ground. How high off the ground is your line sensor? The optimal distance is 0.125" (3 mm)
muno13 years ago
thank you for this posting first and foremost, I was wondering do I have to have the same gear ratio or will any two motors work (i want to maintain your code to be consistent), also will the same code work on a arduino uno...Thank you very much for your time :)
patrickmccb (author)  muno13 years ago
No matter what motors you use, parts of the code will have to be changed unless you copy my design perfectly. Everything is based off of timing.

The same code will work on an Arduino Uno.
Thanks for the help your designs are well thought out and I appreciate it.
mr.kitux3 years ago
Next step could be to change L for R and R for L so it would come back to the start by itself and then go back to the goal through the shortest path :)
We purchased the motor controller that you suggested (http://www.sparkfun.com/products/9457), and we are now having trouble deciding which holes are corresponding on the two boards (yours that you made personally and the one on Sparkfun). Could you please tell me which hole on your board corresponds to which hole on my board? Such as In-1A = AIN1 or something like that. Thank you.
(an image of my board is attached)
A couple questions.
1. What happens when you plug it in? Should some kind of software or something pop up? Does it need to be a mac or windows or can in be both?
2. does the arduino need power when it is connected for the program to be put on it?
3. Is there alternate software I need to read this code or put it on the arduino?
patrickmccb (author)  pingpongkid53 years ago
1. Nothing happens when you plug it in. Operating system does not matter.
2. The programming cable supplies power for you.
3. You need to install the Arduino IDE (http://arduino.cc/en/Main/Software) to view the code, edit it, and upload it.
Is there an alternative site to get this board? Or would you happen to have an extra? I need this for a school project and the guy at Dorkbot will not respond to my order. Thanks.
patrickmccb (author)  pingpongkid53 years ago
The board is a very simple circuit which you could make yourself. Really most motor drivers will do. Something like this would work fine http://www.sparkfun.com/products/9457

As for Dorkbot, you have to send him the files and he normally responses in a day or two.
Thank you very much. Is the schematic any different?
patrickmccb (author)  pingpongkid53 years ago
It works the same as a basic motor controller. You have to input power for the chip, the motors, and you have inputs and outputs. You also have pwm speed control.
janoo4u3 years ago
Can we use Arduino UNO instread of freeduino.
If yes then can u explain PIN Diagram.
patrickmccb (author)  janoo4u3 years ago
Yes you can. The connections are the same.
How do you add the code to the arduino? Like how is it connected to the computer?
patrickmccb (author)  pingpongkid53 years ago
Did I leave that out? Sorry, it takes an FTDI Programming cable
Here is one: http://www.sparkfun.com/products/9718
frafi13 years ago
i need help, i think i'd prefer buying the motor driver, so how about this?? http://www.pololu.com/catalog/product/713 and can i use regular DC motors with these??

and could you tell me how to connect this motor driver to the arduino (the same way you told in step 8)and about the DC motor..

plz reply soon, i want to do this robot very soon..
thank you
patrickmccb (author)  frafi13 years ago
That motor driver is fine. It is very similar to connect as the one I used. The AIN1, AIN2, BIN1, and BIN2 are the direction inputs. AO1, AO2, BO1, and BO2 are the outputs that go to the motors. There are also PWM pins which I make use of in my latest code, but I have yet to update the tutorial. You can tie these to +5v to use the controller as I did in this tutorial. Then connect power to the controller and your motor supply voltage to VMOT.

Do not use a regular DC motor. Use a 5-6V gear motor.
rmartin273 years ago
How long does it take to build this robot?
patrickmccb (author)  rmartin273 years ago
If you have all the parts then it is up to how quickly you can solder for the most part. Maybe an hour with all the parts in front of you.
BeFit4 years ago
Great work!
jobard4 years ago
What happens if after the first recognizing run, you place it in a different start location?
patrickmccb (author)  jobard4 years ago
It would not work properly. It is meant to solve it from the same starting position. It has to be reset if you want it to solve it from another.
Nice. How do you reset it if you want it to go the long way agaibn AFTER it has calculated the shortest path.? Nice, though.
patrickmccb (author)  blinkyblinky4 years ago
Hit the reset button on the Arduino or turn it off and on again.
kimvellore4 years ago
Nice concept. Thank you for explaining in detail. I enjoyed reading it.
hyruler_4 years ago
that is awesome
maximeke24 years ago
Can you please give me some information about your sensor? Does it use LEDs or infrared, and also the type/datasheet of emitter/transmitter?
patrickmccb (author)  maximeke24 years ago
On the first page of the instructable I provided the links to all of the different parts, including this one. Here is the link where you can find more information about it http://www.pololu.com/catalog/product/960
oops... I was just looking for the sensor and didn't read it. Sorry about that
error324 years ago
I have used some parts from the pololu store before. Very good quality!
Though i personally liked it better to make my own PIC based board instead of the too easy arduino solution.
SHIFT!4 years ago
This is a great 'ible, but you forgot the most crucial thing- The Title! Please name this project soon!
patrickmccb (author)  SHIFT!4 years ago
Thanks for the heads up. I thought I named it...