- Move Motor Sensor Car
- AA Batteries
- USB Cable
Line Following Car
In this project we program the sensors on the Move Motor Car to detect and follow lines.
In this project we will be programming the Move Motor Car to follow a line track.
You will need the following:
- A Microbit
- A Move Motor Car (with 4 AA batteries)
- A USB cable
- A track drawn on paper or printed out using the attachment 'mbmmlfc tiles.pdf'
If you are drawing your own track make sure you use a thick black marker with clear lines.
We are going to programming a Microbit to act as the brains of the Move Motor car. To do this we will need to add the kitronik-move-motor extension to our project. This has custom blocks that let us program the Move Motor car.
Add the kitronik-move-motor extension to your project. Once you add it you will notice that there is a new set of 'MOVE Motor' blocks in your toolbox.
To add an extension follow these steps:
- Click on 'Advanced' in the toolbox
- Click 'Extensions'
- Type the name of the extension in the search box
- Click on the extension in the search results
- The extension and all it's blocks will be added to your toolbox
We need to create the following 3 variables:
- left - this will store the value of the left line sensor (how dark or bright it is).
- right - this will store the value of the right line sensor (how dark or bright it is).
- difference - this will store the value of the difference between the left and right variables.
Create the 3 variables and then add the following code to your project.
In the Variables toolbox, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
To make the car look even better and to give us some extra feedback, we are going to use the LEDs on the Move Motor car to light up different colours depending on if it's going straight, left or right.
Add the following code to your project to setup a variable for the LEDs.
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.