<< Back to activities

Binary's UFO (micro:bit) kit - Monitoring for Aliens

This activity shows how to use Microsoft Make code - drag and drop blocks to detect alien activity using the motion sensor.

Start >>

Step 1 - Wiring up Binary's UFO

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

Calibrating the motion sensor:

NOTE: Please allow 5 seconds for movement to be detected

 

       

 

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 http://microbit.org/ to access the BBC micro:bit website.

When it loads, click on "Let's Code" shown in the image at the top of the page.

 

 

 

Next >>

Step 3 - Start a new project using the 'JavaScript Blocks Editor (PXT)'

 There are lots of different types of editors you can use to program the BBC micro:bit. We are going to use the 'Makecode Editor' for this project. Click on the 'Let's Code' button shown below.

 

 

Next >>

Step 4 - Set up your project

To begin setting up your new project, click on the 'New Project' button

 

 

 

When the new project loads you will see two blocks on the page, an 'on start' and 'forever' block. Delete these blocks by dragging them over the tabs to the left

 

  →  

 

Next we need to change the name of the script, click in the 'Untitled' box located next to the download button at the bottom of the page. This will allow you to change the name to something meaningful i.e. Binary's UFO monitoring

 

  →  

 

 

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 click on the 'Logic' tab and select the 'if' statement

  • Drag the 'if' statement inside the 'forever' loop - this will always repeat the 'if' statement  

  • Next, click on the 'plus' symbol on the bottom left corner of the 'if' statement section  

  • This will create an 'else' statement that will be used later  

Next >>

Step 6 - Check for movement

Here we will set a variable to read the motion sensor to detect movement

 

  • Click on the 'Logic' tab and select the '0 = 0' block

  • Drag the '0 = 0' block to the right of the 'if statement'

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

  • Drag the 'digital read pin' block onto the left of the '0 = 0' block and change the pin from 'P0' to 'P1'

  • Next click on the 'Basic' tab and select the 'show leds' block

  •  Drag the 'show leds' block into the 'then' section underneath the 'if statement'

  • Create a face on the 'show leds' block

Next >>

Step 7 - Display a warning

Here we will build ontop of step 5

  • Click on the 'Logic' tab and select the '0 = 0' block

  • Drag the '0 = 0' block to the right of the 'if statement'

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

  • Drag the 'digital read pin' block onto the left of the '0 = 0' block, change the pin from 'P0' to 'P1' and the '0' to '1'

   

  • Next click on the 'Basic' tab and select the 'show leds' block

  •  Drag the 'show leds' block into the 'do' section underneath the 'if statement'

Next create a 'x' on the 'show leds' block - this is done by clicking in the individual desired boxes

 

Click on the 'Pins' tab, select the 'digital write pin' block and place underneath the 'show leds' block - this resets the sensor so it looks for more movement

   

Click on the 'Basic' tab, select another 'show leds' block and place in the 'else' section of the 'if' statement

   

Create a happy face on the 'show leds' block - this is done by clicking in the individual desired boxes

Next >>

Step 8 - Set off the alarm!

This stage builds on the previous stage using a condition from a 'while true' statement (this should be done on the same script as previous step)

 Click on the 'Loops' tab, select the 'while true' statement and drag it onto the page

   

 Click on the 'Logic' tab, select the '0 = 0' block, drag and drop to the right of the 'while true' statement - this will replace the 'true' part of the statement

   

Click on the 'Pins' tab, select the 'digital read pin' block and replace the first '0'

   

Change the value of the second '0' to '1' and the pin from 'P0' to 'P1'

Click on the 'Music' tab and select the 'play tone' block

Place the block below the 'digital read pin P1 = 1' block

Duplicate the 'play tone' block two times by right clicking it

Place the two duplicated blocks underneath the first 'play tone' block

 Now change the 'play tone' blocks to your desired tone and beat

Next >>

Step 9 - Flashing LED's when movement is detected

So far you should have created all the code from steps 5 - 8:

Now we need to set off the LED's when movement is detected

Right click on the 'digital write (0,1) 1 to pin P0' block, in the 'do' section, and duplicate it

   

 Change the pin on the second 'digital write (0,1)' block from 'P0' to 'P2

Click on the 'Basic' tab, select the 'pause' block, drag and place it underneath the 'digital write P2 to 1' block

    

Change the '100' to a desired value - for now i am going to change it to '1000'

 Next duplicate the 'digital write P2 to 1' block,drag and place underneath the 'pause (ms) 1000' block

   

Change the '1' to a '0'

Repeat the previous stages until you are happy with the amount the LED's flash

Next >>

Step 10 - Does it work?

Now on the virtual micro:bit, click on pin 1 and see if your code is correct

When pin 1 is pressed, an 'x' shoud show and sound should play

NOTE: you will not be able to test the LED lights until you download the code.

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 bottom of the editor is a button that says 'Download'

Once you have saved it into a file you will see that it is at the bottom of your browser. Select the arrow and click ‘show in folder’

Next >>

Step 12 - Find your downloaded code file

This will open the folder containing all your downloaded files - this will include a file called something like 'microbit-UFO-Monitoring-for-Aliens.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 if Binary's UFO has found aliens!!

Next >>