Hardware requirements:



Upload the program to Arduino


Example programs


Script description
In Example 21 Value of line-follower sensor we introduced the principles of the line-patroling sensor, of which the detection range is from 1 to 2 cm. So taking advantage of this principle, you can control mBot robots to judge from the changes in the external environment.
When mBot is placed on a white (or light color) table, the infrared light can be reflected, and the value is 3 (both Sensor1 and Sensor2 output 1); when mBot is picked up to be 1-2cm from the table surface, which exceeds the detection range, the infrared light cannot be reflected and the values is 0 (both Sensor1 and Sensor2 output 0).
When the value of the line-patroling sensor is 0, it can be deemed that mBot is picked up and it will sound an alarm.


Extended tasks
Make mBot sound an alarm when it is picked up and show on the stage the value of the line-patroling sensor.


Attached – Line-patroling sensor structure diagram