Let mBot move forward on a white table (or other light color table) and stop it when it gets to the edge of the table surface.
Upload the program to Arduino
When mBot travels within the surface of the white table (or other light color table), the line-patroling sensor can receive the returned infrared signal and the value is 3 (both Sensor1 and Sensor2 return 1); when mBot travels to the edge of the table surface, the line-patroling sensor cannot receive the reflected infrared light and the value is 0 (both Sensor1 and Sensor 2 return 0). When the value of the line-patroling sensor is 0, it is deemed to have reached the edge of the table surface and will be stopped.
Also if you use this program, mBot will stop moving forward when it detects black.
|Task 1||Modify the script to let mBot move back when it detects a cliff.|
|Task 2||Modify the script and use block to achieve the effects of this example.|
Attached – Line-patroling sensor structure diagram
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.