Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Line follower turns clockwise at the end of the line


Hey guys, Cycloned here. I’m a newbie who’s just started Arduino programming so I barely know anything. Doing a HELL of research I’ve managed to put together a PID line follower that works, except for 1 issue - gaps in the line it’s following throws it off. When it reaches the end of the line it follows, it rotates clockwise in place (one motor turns off, one remains on). I want it to keep going forward, how can I accomplish that?

Here’s the code: pastebin.com/hnmUHcxQ

I’m using an Arduino Uno, 6 QTR sensors, TB6612FNG motor driver and some pololu micro motors. As I’ve mentioned, I’m a complete newbie, so I know that I need to add a n if statement where if the sensors all return 0 then the robot should continue forward and not turn. The problem is I dont know where and how to add this statement. Please help!


Hello, Cycloned.

You would probably need to read each sensor to detect the gaps in your line. The readLine function reads in the values of each sensor into the array you specify (e.g. sensors). You could then compare each of those values to some threshold to determine if the sensor detects a white or black surface. To check a specific sensor, you can look at the index of the array that corresponds to that sensor.

If you try adding those features to your code and continue to have issues, you can post your updated code here, and I would be happy to take a look.

- Amanda