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
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
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
Programming
Go to the MakeCode programmming page https://makecode.microbit.org/#editor
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%.