Line(Edge) Following Using One Sensor
The simplest type of line following uses one sensor. It is really edge-following, as it measures whether it is on the black tape or on the white background, and turns accordingly.
The sensor we use includes an infra-red(IR) source and a light sensor, and measures the amount of light reflected off the surface. The sensor has an analog output inversely proportional to brightness. The output is connected to one of the analog inputs, and is measured using the analogRead instruction. Possible values range between 0 and 1023, but are typically between 50 and 700. For calibration purposes, you can use the Analog Read Serial example sketch to measure the dark and light values.
The sensor we use includes an infra-red(IR) source and a light sensor, and measures the amount of light reflected off the surface. The sensor has an analog output inversely proportional to brightness. The output is connected to one of the analog inputs, and is measured using the analogRead instruction. Possible values range between 0 and 1023, but are typically between 50 and 700. For calibration purposes, you can use the Analog Read Serial example sketch to measure the dark and light values.
As it is measuring reflected light, the distance between the sensor and the surface is critical, and should be between 1/8" and 1/4". You will need to figure out how to precisely mount the sensor, and to determine the optimum mounting distance.
Once the sensor has been mounted, and the dark and light levels have been determined, you are ready to program.
You may want to modify your turn left and turn right functions to all being versions of your forward function, with turning being achieved by sending different amounts of power to each wheel- start by turning by powering a single wheel, then adding small amounts of power to the opposite wheel.
Faster line following can be achieved using multiple sensors and/or Proportional-Integral-Derivative (PID) algorithms
Once the sensor has been mounted, and the dark and light levels have been determined, you are ready to program.
You may want to modify your turn left and turn right functions to all being versions of your forward function, with turning being achieved by sending different amounts of power to each wheel- start by turning by powering a single wheel, then adding small amounts of power to the opposite wheel.
Faster line following can be achieved using multiple sensors and/or Proportional-Integral-Derivative (PID) algorithms
One sensor line following( edge detection)
Below: Options for edge-following:
(1) Full Left/Full Right "bit banging" (2) Full left/straight/full right (3) Proportional control
(1) Full Left/Full Right "bit banging" (2) Full left/straight/full right (3) Proportional control