48
SR = digitalRead(SensorRight);//Right Line Walking Infrared sensor against white
undersurface,then LED[L2] light illuminates and while against black
undersurface,LED[L2] goes off
SL = digitalRead(SensorLeft);//Left Line Walking Infrared sensor against white
undersurface,then LED[L3] light illuminates and while against black
undersurface,LED[L3] goes off
Distance_test();// Measuring front distance
if((Distance < 20))//The value is the distance that meets the obstacle, and can be set
according to the actual situation
brake();//stop
else
{
if (SL == LOW&&SR==LOW)// Black lines were not detected at the same time
run(); // go ahead
else if (SL == LOW & SR == HIGH)// Left sensor against white undersurface and
right against black undersurface , the car left off track and need to adjust to the right.
right();
else if (SR == LOW & SL == HIGH) // Rihgt sensor against white undersurface and
left against black undersurface , the car right off track and need to adjust to the left.
left();
else // Black lines were detected at the same time , the car stop.
brake();
}
}
}
Experimental steps:
1. We need to open the code of this experiment:
Tracking_ultrasonic.ino
,
click
“
√
”
under the menu bar to compile the code, and wait for the word "
Done
compiling
" in the lower right corner, as shown in the figure below.
2. In the menu bar of Arduino IDE, we need to select
【
Tools
】
---
【
Port
】
---
selecting the port that the serial number displayed by the device manager just now,
as
shown in the figure below.