<< Back to activities

Binary's UFO (micro:bit) kit - What is the warmest / coolest place you can find?

This activity shows how to use Microsoft Make code - drag and drop blocks to detect the temperature in the area.

Start >>

Step 1 - Wiring up Binary's UFO

Firstly wire up Binary's UFO to the BBC micro:bit as shown below:

Next >>

Step 2 - Access the BBC micro:bit editor to be able to "code" on the micro:bit

When you are coding using the BBC micro:bit, you need to do it through their online Editor. 

Click on this link www.microbit.co.uk to access the BBC micro:bit website. 

When it loads, click on "Let's Code" shown in the image below:

Next >>

Step 3 - Start a new project using the 'Block Editor'

There are lots of different types of editor you can use to program the BBC micro:bit. We are going to use the 'Block Editor' for this project. Click on the 'Start with this editor' button shown below.

Next >>

Step 4 - Set up your project

Once you have clicked on the 'let's code' button from the previous step you will be presented onto a new screen with a screen as shown below, as we want to make new code we are going to click on 'new project'

When you can see the script window. Click on the script name as shown in the image below in a red box. This will allow you to change the name to something meaningful i.e. Binary's UFO Warm or Cold

Next >>

Step 5 - Start to Code

  • Click on the 'Basic' tab and select the 'forever' loop

The 'forever' loop will always repeat any statements and/or blocks located inside of it.

  • Drag the 'forever' loop over onto the blank page

Next >>

Step 6 - Setting the variable 'temperature'

  • • Click on the 'Variables' tab and then click on make a variable and call it ‘temperature’.

  • Now, drag the ‘set temperature to 0’ block into the forever block.

 

    • Next click on the 'Pins' tab and select the 'digital read pin' block

     

    • Drag the 'digital read pin' block onto the end of the 'set temperature to' variable

    • Change the pin form 'P0' to 'P1'

     

    Just to show that the BBC micro:bit is up and running, program the LEDs to display a ‘T’, for temperature.

    • Click on the 'Basic' tab and select the 'show leds' block

    • Drag the 'show leds' block underneath the 'set temperature to' variable

    • Next draw a 'T' shape by clicking on the boxes in the 'show leds' block

Next >>

Step 7 - Displaying a reading

We now need to display the reading. When button B is pressed, the LEDs on the BBC microbit display the value being read by the sensor

Click on the 'Input' tab and select the 'on button A pressed' block and drag it onto the blank page

Click on the 'A', a drop down menu should appear, select the 'B'

   

Next click on the 'Basic' tab, select and drag the 'show number' block into the 'on button B pressed' block

   

Click on the 'Variables' tab and drag the 'temperature' block into the '0' on the show number block.

Next >>

Step 8 - Boiling or Cold!

Click on the 'Input' tab, select the 'on button A pressed' block and drag it onto the page

  • Next click on the 'Logic' tab and select an 'if statement'

  •  Drag the 'if statement' in between the 'on button A pressed' block

  • Next click on the 'Logic' tab and select a '0 <0' block

  • • Drag the '0 < 0' block onto the end of the 'if statement' Change the ‘<’ to ‘>’ while you’re here too.

  • • Drag the 'temperature' variable and replace the first '0' in the 'if statement' and I have changed the second ‘0’ to ‘260’.

     Now it needs to show a response when the temperature goes above the desired variable

    • Click on the 'Basic' tab, select and drag the 'show string' block into the 'do' section of the 'if' statement

       

    • Rename the 'show string' block from 'hello!' to 'BOILING!'

    • Next click on the 'Logic' tab, select another 'if' statement and drag it underneath the previous 'if' statement

          

    •  Again click on the 'Logic' tab and select the ' and ' statement 

    • Drag the 'and' statement over to the end of the second 'if' statement

    • Next right click on the 'temperature > Your variable' block, duplicate it and drag it to the first blank box on the 'and' statement below

           

    • Change the variable on the 'temperature > variable' statement so it is lower than the previous variable

    • Right click on the first 'temperature > Your variable' block, duplicate it and drag it to the second blank box on the 'and' statement below

           

    • • Next change the '>' symbol to '≤' on the previously placed 'temperature > 260' statement, by clicking on the symbol.

    • Click on the 'Basic' tab and select the 'show string' block

    • Drag the 'show string' block, place it in the 'do' section on the second 'if' statement and rename it to 'PERFECT!'

    • Next click on the 'Logic' tab, select and drag the 'if' statement and place underneath the second 'if' statement

         

    • Duplicate the  'temperature ≤ Your variable' block from the second 'if' Statement and snap it onto the right of the third 'if' statement below

          

    • • Change the variable on the second 'temperature ≤ variable' statement so it is lower than your previous variable, I have changed the ‘≤’ to ‘<’ and the value to ‘100’.

    • Click on the 'Basic' tab and select the 'show string' block

    • Drag the 'show string' block, place it in the 'do' section on the third 'if' statement and rename it to 'FREEZING!'

Next >>

Step 9 - Ready to test!

You are ready to test your code !! You can do this before you put it on Dimm. On the right side of the editor is a 'Virtual' micro:bit - its a version of the real thing that you can use to test. 

At the top of your editor, click on the 'Run' button. 

Next >>

Step 10 - Does it work?

Now, on the virtual micro:bit, to start with it should show the letter 'T' ,but click on all the inputs you have defined in the script and see if they work!

NOTE: to fully test the code you will need to download the .hex file to the micro:bit 

Clicking on button 'A' should show the number '0' due to the temperature sensor not beingr connected

Clicking on pin 2 should scroll 'FREEZING!', this is again due to the temperature sensor not being connected

Next >>

Step 11 - Download the code ready for Binary's UFO

It is now time to see it work on Binary's UFO. 

On the top of the editor is a button that says 'Compile' - shown below in a red box

Click on it - the page will download a file to your computer

 

Next >>

Step 12 - Find your downloaded code file

Click on the downloaded file at the bottom of the browser - select 'Show in Folder'

This will open the folder containing all your downloaded files - this will include a file called something like 'microbit-Binary-s-UFO-Warm-or-Cold.hex'

Right click on the file and choose to copy it (this is ready for the next step)

Next >>

Step 13 - Plug in the micro:bit

Now you need to plug the micro:bit on Binary's UFO, into your computer - using the USB cable that came with the micro:bit.

When you plug it in, a window should pop up on screen that looks a bit like this:

 

 

Next >>

Step 14 - Paste the code file to the micro:bit

 Right click on a blank space within the micro:bit folder and choose 'Paste' - it will display a window a bit like the below as it copies the file to the micro:bit.

Next >>

Step 15 - See what temperature Binary's UFO can find

Next >>