Step 0. Using your web browser, go directly to https://makecode.microbit.org to land the MakeCode for micro:bit home page. You can bookmark this package to easily open this package for next project. In the My Projects section, click on the New Project

For more information about MakeCode, please go to our tutorial: What is MakeCode


Step 1. In the Toolbox, click on the Led category and then click more, and then drag and drop a led enable false block inside the on start block.

Step 2. In the Toolbox, click on the Logic category. Then click and drag the if-then-else block over and place it inside the forever block.

Step 3. Click on the Logic category again. Under the Comparison section, drag “0 = 0” blocks over, and place it on the placeholder of the if-then-else block,  then choose “=” from the dropdown list.

Step 4. Click on the Pins category and drag and drop the digital read pin P0 block and place it on the first placeholder of the Comparison block and change P0 to P2. Also, change the second
placeholder
of the Comparison block to 1 as following picture:

Step 5. In the Toolbox, click on the Music category. Then click and drag the stop melody all block over and place it inside the “then” section of the if-then-else block.

Step 6. Click on the Pins category and drag and drop the digital read pin P0 to 0 block over and place it inside the “then” section and under stop melody all block and then change P0 to P1.

Step 7. Click and drag the start melody xxx repeating  xx block over from music category and place it inside the “else” section and choose music as you like and choose forever for repeating.

Step 8. Right-click on the digital write pin P1 to 0 block and click Duplicate from the shortcut menu and you will get a duplicated block. change 0 to 1 and drag and drop the duplicated block inside the “else” section.

Step 8. In the Toolbox, click on the Basic category, click and drag the pause(ms) block over and place it inside of the forever block, and choose 2000 ms from drop down menu.

Step 9. rename the project name  and download it

Step 10. Download this “.hex” file and send it to your MICROBIT disk.

Below is the full code we have done for you as reference:

Complete wiring and power up, when flame is close the flame sensor, the buzzer will ring and the red LED turn on for 2s. when the flame is left, the buzzer will stop and the LED will turn off.