Activities
Each sensor is a matched pair of infra-red (IR) LED light source and a receiver, they bounce light off of the surface and measure how much gets reflected. white / light surfaces reflect a lot of the light, darker / black surfaces absorb much of it.
The controller board for the sensors has one pot (potentiometer, or variable resistor) for each sensor, this adjusts the trigger threshold that flips the output from light to dark.
The four outputs are connected to the Arduino analog input pins as they are not use by the motor control board, they can be configured as digital inputs with the normal pinMode(n, INPUT) and digitalRead() commands.
Use a piece of paper/card with piece of black insulation tape on it to calibrate the sensors, adjust the pots until the corresponding LEDs on the control board reliably turn on and off as you pass the black stripe beneath the sensors.
By monitoring which lines are high or low we can 'see' if the line we are following is central or to one side and adjust the relative speeds of the motors to correct and centre it again. or if it is lost, slowly rotate the robot until we locate it again.
#define LANE_A 14 #define LANE_B 15 #define LANE_C 16 #define LANE_D 17 void setup() { Serial.begin(9600); pinMode(LANE_A, INPUT); pinMode(LANE_B, INPUT); pinMode(LANE_C, INPUT); pinMode(LANE_D, INPUT); } void loop() { Serial.print("IR Lane: "); if (digitalRead(LANE_A) == HIGH) Serial.print("HIGH "); else Serial.print("LOW "); if (digitalRead(LANE_B) == HIGH) Serial.print("HIGH "); else Serial.print("LOW "); if (digitalRead(LANE_C) == HIGH) Serial.print("HIGH "); else Serial.print("LOW "); if (digitalRead(LANE_D) == HIGH) Serial.print("HIGH "); else Serial.print("LOW "); Serial.println(); }