Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →How does the robot think to stay on the black line?
The sensors give a digital reading (0 for white, 1 for black or vice versa depending on the module) and connect to digital pins.
int leftIR = 4; int rightIR = 5;
// ... داخل الـ loop ...
int L = digitalRead(leftIR);
int R = digitalRead(rightIR);
if(L == 0 && R == 0) { moveForward(); }
else if(L == 1 && R == 0) { turnLeft(); }
else if(L == 0 && R == 1) { turnRight(); }Not calibrating the sensors. IR sensors have a small variable resistor (trim pot) that must be adjusted until the sensor correctly identifies black in the current room lighting.