What is the best way to solve this maze? (coding)

I’m currently using the QTR-8RC from pololu, 2 50:1 micro gear motors, a motor shield and an Arduino. 8 sensors are used, and we have a maze that looks like this:

In reality, it looks like this:

Each team starts at either the blue spot or the red spot and follow the corresponding color line. I don’t know what is the best way for the robot to turn at the right direction at the cross, as the robot often drifts to the wrong line. What is the best way to make the robot follow the correct line when it starts and when it comes back to the finish line?

For the line following code, I’m using the PID and turning similar to this topic: Programming maze solving robot to do sharp turns - #7 by BrandonM

Thanks for any helps/advices!


That looks like a fun course! I think that just using a line following PID algorithm alone is not going to work well. You might consider trying to detect the intersection and then hard coding the turn radius at the start of the next turn based on how many times the robot has been through the intersection. You might also try looking at individual sensor readings to detect when the line splits, something like a state machine to track which section to follow, and then adjust your target to the correct line.

I haven’t seen a competition like that before. I would love to see video of it or your robot in action!


I’m very happy to see your reply, as I’m currently using an Arduino Uno with an Adafruit Motor Shield v2.3, I’m running short on pins to connect another reflectance sensor. I’ve already used pin A0, A1, A2, A3, A4, A5, 9, 10 for the QTR-8RC so I cannot add another sensor to the board. I’ll try and add more cases but it’ll need a lot of time to stabilize the robot and adjust the Kp Ki and Kd value. I’ll be very glad to send you some videos of the competition in the upcoming time.

Thanks for the advice! I hope to hear more from you!

Edit: I just found out the difference between the v1 and v2 shield, as the v2 shield only uses SDA/SCL (A4/A5), and as I don’t use any servos, all of the digital pins can be used! I’ll try and experiment more by buying another individual sensor.