The Bit:Bot Robot is a feature-packed little robot that is almost ready to go, requiring no soldering, no wires and nothing more than a screwdriver to complete it.
There are loads of ways of achieving this but this is a really simple one to get you started. Once you have mastered the basics, you can try adding reverse or perhaps use the addressable LEDs to greater effect!
What you will need:
This is the program for the micro:bit that you are using as a remote control
This is the program that runs on the micro:bit that is on your Bit:Bot
You are going to need to create two programs – one to run on the standalone micro:bit (which will act as your remote control) and one to run on the Bit:Bot. We'll do the program for the remote control first. This program is made up of 2 main parts:
Let's break the program down and look at what it is doing:
The micro:bit radio can be used to transmit on 256 different channels or groups – 0 to 255. This means that you can share data between many micro:bits in the same group, or in a classroom environment it can be useful to assign each student their own group number to use so that their projects do not interfere with one another. In this case, we are setting this micro:bit to operate on group 1 the moment the program starts.
Next we have a forever loop. This means that the instructions in the loop are executed continuously over and over until the power is turned off.
Next we have an if statement that checks to see if button A on the micro:bit has been pressed. If it has, the micro:bit will broadcast a packet that contains the string "A" and the number 1. It also switches on one of the LEDs at position 0, 0 of the display using the plot command. This is to show the user that the button on the remote has been pressed.
If the button is not pressed (else), the micro:bit broadcasts a similar packet, but with a 0 rather than a 1. It also switches off the LED at position 0, 0 using the unplot command.
This if statement is very similar to the one for the A button, but instead checks the B button and broadcasts a slightly different packet and uses an LED at location 4,0 to tell the user that the button has been pressed.
Now let's take a look at the program for the micro:bit that is on the Bit:Bot robot. This program is made up of 3 main parts.
You might have noticed that the program uses some bright green blocks that aren't in the normal command set. This is because Bit:Bot has its own library of commands. To access them, you need to add the library by clicking Add Package. In the search box, type BitBot and then click on the BitBot package to add it to the list of commands.
Firstly, the micro:bit on the robot needs to be set to the same group as the remote control.
This part of the program looks for an incoming signal sent from another micro:bit. It is looking for a packet of data made up of a string and a number value which will temporarily be stored in variables called name and value.
If the string received is "acc" (remember we used this to represent the accelerometer value) then the numerical value is stored in a variable called speed. We'll use this later to tell our robot how fast to go.
If the string received is "A", we know this is the data from button A being pressed which will be either 0 or 1. This value is stored in a variable called A.
If the string received is "B", we know this is the data from button A being pressed which will be either 0 or 1. This value is stored in a variable called B.
The forever loop part of the program is the part that makes the robot actually move and it also lights up some of the NeoPixel LEDs around the edge of the robot.
The first command in the forever loop is show leds. You need to use this command every time you want the LEDs to change state.
The first if statement is checking to see if the variable A is equal to 1 (i.e. button A is pressed). If A = 1 then the pixel at address 0 is set to green. Don't forget, it won't actually change colour until the program gets back to the show command.
The drive block controls the speed and direction of the left motor – a positive number makes it go forwards and a negative number makes it go backwards. If A does not equal 1, then the button is not pressed so the speed is set to zero so the wheel stops and the pixel is set to red.
The second if statement is almost identical to the first, but it looks to see if the B button is pressed and controls the right wheel rather than the left.
One of the sensors that the Bit:Bot robot has is a pair of light sensors. These can be found on the top of the robot on either side, just in front of the LEDs.
The light sensors return a value of between 0 (pitch black) and 1024 (daylight). The readings from these sensors can be used to make a robot that follows a bright light, the torch on a smartphone for example.
This is the most basic light seeking program using just 2 blocks.
Slightly more advanced light following with threshold to trigger movement and sharper turns.
Try out this more advanced program which also uses the addressable LEDs as a bar graph to show the light level on each of the two sensors.
Here is a really simple example:
If the light is stronger on the right-hand sensor, the left-hand wheel turns faster which makes the robot turn right (towards the light). If the light is stronger on the left sensor, the right wheel turns faster and the robot turns to the left.
With the light in the middle and so equal on both sensors, the robot will drive straight. It’s not particularly agile, but it works. Let’s try making it more agile:
Firstly, we initialise a variable called threshold. You can play with the value of this to see what effect it has, but for now set it at 500.
In the forever loop, the first thing we do is check that the value of both sensors added together is greater than our threshold. If it isn't, the robot won't move at all.
If the light level is great enough, the robot then checks which light sensor has the greatest value and moves towards it.