micro:bot Kit Experiment Guide
Experiment 1: Driving and Turning
The “Hello World” for the robotics world is getting your robot moving! Driving forwards, backwards and steering is goal #1 when you are dealing with wheeled / moving robots. This experiment will cover just that: getting your robot moving using our moto:bit software package for Microsoft MakeCode. Once you get through this first experiment you will be golden!
- 1x micro:bit board (Not Included)
- 1x Micro B USB Cable (Not Included)
- 1x moto:bit carrier board
- 2x Wheels
- 1x Assembled shadow chassis
- 2x Hobby Gear Motors
- 1x 4xAA Battery Holder
- 4x AA Batteries (Not Included)
Didn’t get the kit? Have no fear! Here are the parts you will need to complete this experiment…
Motors and Selecting the Right One
Introduction to the Motors and Controlling Them
Motors take electrical energy and turn it into mechanical energy through putting a current through a coil of wire that creates a magnetic field. This then interacts with magnets in the motor, causing a push / pull effect. If you do that in a proper spacing and timing then you can spin a shaft.
These motors operate in a similar was as mentioned above, but they have a bit of help; a gear box. The ratio of the gearbox is 120:1, which means that for every 120 rotations of the motor shaft you get one rotation at the end of the gear box. This is a good thing because it gives our robot enough strength (torque) to turn wheels. In this case our gearbox also changes the axis of the shaft so that we can easily use them to drive our robot.
You should have already hooked up the motors during the assembly process of putting the robot together. But, we have a couple of things that we would like you to double check!
First of all make sure that your red and black wires are plugged into your moto:bit and that they are in the correct ports. If you look closely the right and left ports are opposite from one another.
Why is that? Well, in robotics the right and left motors are mirrors of one another, which means they go in opposite directions from one another to go forward, hence the ports being backwards. If you plug them in as the same direction your robot would spin in a circle rather than drive forward! Weird, but true.
Running Your Script
We are going to use Microsoft MakeCode to program the micro:bit. Please open a browser window and navigate to makecode.microbit.org. This should open the MakeCode environment that you used to install the moto:bit package in.
Now, you can either download the following example script below and drag and drop it onto your micro:bit, or use it as an example and build it from scratch in MakeCode.
Code to Note
On Button Pressed
On Button Press is an event function. Any code blocks that are placed inside of the block will only execute when that event happens. In this block when the A button is pressed on your micro:bit your robot will start moving. When it gets to the end of the program it will stop again until you press the A button again.
Turn Motors block gives you the ability to turn the motors
OFF in software. They are naturally
OFF, so anytime you want to drive motors, you need to set them to
ON. A good practice is to turn them
OFF when your robot completes its task or should not be moving for long periods of time, this saves batteries and wasted power consumption.
Move Motors At
Move Motors block is the basis of the moto:bit software package. You use this block by selecting which motor you want to control (RIGHT or LEFT), its direction (FORWARD or REVERSE) and the throttle / power percentage you would like the motor to spin at (0-100%). For your bot to move forward you need to have both motors drive in the same direction. To turn, or pivot, you set the motor directions in an opposite configuration.
pause block is like a code stop sign. It tells the micro:bit to wait for a given amount of time in milliseconds. While it is waiting whatever you told before the
pause will keep happening. So, if you want your robot to drive forward for 2 seconds, you set the robots motors to drive forward and then pause for 2000 milliseconds and then have the motors do something else, like stop.
What You Should See
Once your script uploads to your micro:bit make sure the motors switch is changed from “STOP MOTORS” to “RUN MOTORS.” Press the A button on your micro:bit and your robot will drive forward for 1 second, pivot and the drive forward for another second then stop.
Robot not moving - Make sure your motors are hooked up correctly in the motor ports and your motor power switch is set to “run”, the battery pack is plugged in and you have fresh batteries
Moving in reverse?! - You can flip the wiring of your motor or use the
Set Motor Invertblock in your
On Startblock to change what is forward vs. reverse.
moto:bit package is not showing up - Try installing it again from the add package option in MakeCode