Code Explanation Following.ino

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

The infrared line following module enables the RollFlash to detect a black line through the collected data, so that it can adjust the direction and follow the line. Meanwhile, the RollFlash will walk away from the obstacle on a black line it’s following, bypass the obstacle and come back to follow the line.

The program above is to read the black line’s position. By comparing the AD value and the setting reference, it can tell whether the black line is at the centre-left or centre-right position.

When the sensor detects the black line is at the centre-left, the RollFlash will turn left slightly; when it is at the centre-right, the robot should turn right a bit; when the line is in the middle, the RollFlash would move forward. That’s how it works for line following. Besides, it needs to detect whether there’re obstacles and avoid them if yes.

The program above is about detecting whether there’s an obstacle 6cm in front of the RollFlash by the ultrasonic module. If it detects an obstacle, it will walk away from the obstacle, and then walk back to follow the line. Thus, we can realize the line following & obstacle avoiding.