Due to public request on my youtube channel here is the code for my smooth line follower.
If you try the code with your robot the result might not be as good as in the video.
This can be caused by:
– Different position of the light sensor in relation to the wheels
– Different distance from wheel to wheel
The basic idea behind the code: My formula to calculate the speed is a/100*80-25=”speed value” with “a” as light value. One wheel is set to this speed value. The other is set to 30 – “speed value”. Huh? Let´s see what happens when the robot is driving on the line.
Case A – light sensor reads 100 (on white area)
100/100*80-25=55 Now one wheel gets the 55 as speed value. The other gets 30 – 55 = -25 As result the robot turns!
Case B – light sensor reads 0 (on dark area)
0/100*80-25=-25 Now the wheel that previously was turning forward turns backwards since it´s speed is set to: -25 The other wheel turn forward because it is set to 30 – (-25) = 55 As result the robot turns in the other direction!
Case C – light sensor reads 50 (somewhere on the edge of the line between white and black)
50/100*80-25=15 One wheel gets the value 15 and the other gets the value 30 – 15 = 15. As result the robot drives straight ahead!
If the robot is on the edge (or a little off) of the line both wheels will be set to positive speed values.
Driving through narrow corners is possible because one wheel (the inner one) is set to a negative speed if the light sensor detects that the robot is either in the white or black area. This enables the robot to nearly turn on the spot.