Our Goal


Requiered Materials


Background


Principle of line follow

Dual patrol module

Hardware connect


As above picture, connect the dual patrol module to P13、P14 of robit with 3 pin wires.

Software


makecode

Coding


Step 1

Note:If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Project file menu.

Step 2

On start, set the left wheel to M1, the right wheel to M2 and the speed is 10.

Set the infrared ray sensor to variable left and right to read the parameters of P13 and P14.

If at least one of the left and right infrared rays does not receive feedback (the edge is detected), set the left and right motor speed to a negative number. Set random number from 0 to 100, if it is less than 50, the M1 servo stops; if it is more than 50, the M2 turns left.

Set the speed of the servo in 10 and go ahead if the the infrared ray sensor nothing.

Program

Program link:https://makecode.microbit.org/_gTCFqyau8Uud

If you don’t want to type these code by yourself, you can directly download the whole program from the link below:

Note: The items can absorb the infrared ray default ro black lines.

Result


The robit car will detect edge and then back to avoid falling.

Think


In what conditions that the distance is 0 ?

Questions


More Information