Micor:bit AI Lens Line-tracking Car

by ElecFreaks in Teachers > Coding

1029 Views, 1 Favorites, 0 Comments

Micor:bit AI Lens Line-tracking Car

913-1.png

Result
The car drives along with the black line. (Note: the background color must be pure white for this function)

Supplies

  • micro:bit * 1
  • Nezha Expansion Board * 1
  • Planet X series-AI Lens * 1
  • Planet X series- Motor Brick * 2
  • RJ11 wire * 1
  • n * Bricks

​Hardware Connection

913-1.png

Connect the micro:bit to Nezha expansion board, and connect the AI Lens to the IIC port on the Nezha expansion board with RJ11 wires, then connect the two motors to M1&M2 accordingly as the picture shows.

Bricks Build-up

913-2.jpg
913-3.jpg
913-4.jpg
913-5.jpg

Programming

913-2.png

Go to the MakeCode programmming page https://makecode.microbit.org/#editor

913-3.png
913-4.png
913-5.png

Add planet X package and click extensions on the menu of the settings on the right upper side.

Search with PlanetX in the dialogue box to add the package.

Add Nezha package in the same way.

After finishing the above steps, now we need to programme:
Initialize the AI lens via IIC port in the On start brick. Set the AI Lens in the line-tracking mode. Get one image from the AI Lens in the forever brick and set the motor M1 at speed 10% if the black line in the image being detected deviating to the left; and set the motor M1 at speed 60% if the black line in the image being detected deviating to the right side. Or set both the speed of M1 and M2 at 60%.

Link: https://makecode.microbit.org/_XdtPA8Hepc44