Coding Ireland STEM Report 2024 Have Your Say
Robotics
Expert
60 mins
235 points
What you need:
  • Computer/laptop
  • Microbit
  • Move Motor Car
  • USB Cable

Move Motor Straight Line

The Move Motor is a brilliant and fun car to program but like nearly all cars like this, the motors don't run at exactly the same speed. This means that when you program it to go in a straight line it often goes slightly left or right. In this lesson we will learn how to tweak the motors to compensate for this and make it drive in a straight line.

1 - Create a new project

Go to the https://makecode.microbit.org/ website, create a new project and add the kitronik-move-motor extension.


2 - Check how straight

First let's check how straight your Move Motor car drives before we make any adjustments.

Add the following code to make it drive in a straight line.

Download the code onto the Microbit in your Move Motor car and then turn it on to observe how straight it drives.

You will see in the example with this step that this one moves slightly to the right.

It might drive in a perfect straight line, in which case it doesn't need to be adjusted. However, the motors are also affected by the battery voltage, so it might not stay straight forever!

3 - Adjust the motors

To adjust the motors, add a bias to [Left] by (0) block inside the forever block above the move [Forward] at speed (50) block. This block will "bias" the motors by a certain amount to either the left or right, depending on what you set it to.

If your Move Motor car turned more to the left in your test then set it to bias to [Right] by (0) otherwise leave it as bias to [Left] by (0). In our example the car moved to the right so we will leave it as bias to [Left] by (0)

In the next step we will set the value of how much bias to apply.

4 - Set the 'bias' value

The bias value in the bias to [Left] by (0) block can be a number from 0 to 10. We could enter a number, download the code to our Microbit, test it, change the number, download it again, test it again and so on but a better way would be to create a variable to use and then adjust the variable up and down using the A and B buttons.

Create a variable called biasValue and add the following code to:

  1. Use the biasValue variable in the bias to [Left] by (0) block.
  2. Add 1 to the biasValue when you press the B button.
  3. Subtract 1 from the biasValue when you press the A button.

5 - Test and adjust

Download the code onto your Microbit and try testing it again. This time try pressing the A or B button to adjust the bias value and make the car go in a straight line.


Join our club 😃

To view the remaining 2 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more