D - If Hot

​ ​

In this section, we are taking our code to a new level. As humans, we see, smell, touch, taste and hear the world around us, and we are going to use some of those senses to help the micro:bit do something similar, by utilizing different sensors built into it.

The first sensor we'll work with is the ability that the micro:bit has to detect temperature and along with it, we'll learn the concept of if statements in coding.

If statements provide computers with the ability to choose between different options or paths. It opens many different possibilities and makes our programs more interesting and diverse.

circle-info

We don't need a physical micro:bit to test the temperature option. The emulator provides a way for us to see and test different temperature levels.

chevron-right​Temperaturehashtag

Getting a temperature reading from the micro:bit is very simple. We use the provided block temperature (C), wrapped by the show number block.

Don't forget to test your progress using the micro:bit emulator, or a micro:bit, if you have one available.

chevron-right​If Statements - Conditionalshashtag

If-else statements are used to control what the code will execute when a particular condition is fulfilled. In a way, they provide options for our code to make choices.

  • Add the if block to our existing code

  • Add the comparison block located in the Logic section

  • Complete the if block by:

    • Adding the temperature block

    • Change the < (less than) sign in the middle to be > (greater than)

    • Add a number that would indicate a hot temperature

By now you know the routine: test the application in the emulator or on an actual micro:bit if you have one available!

These projects ​​​will help you when working on the main Activities as they all use micro:bits and MakeCode as the brains controlling the visualizations and servo motors. It is time to continue, learning about the other tools. See you in the next section 03 - Servo Motor.

chevron-right🍎Teacher's Corner - If statementshashtag
  • The if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed.. MDNarrow-up-right

More about if statementsarrow-up-right from MakeCode

chevron-rightβ€‹β€‹β€‹πŸŽTeacher's Corner - Logic operatorshashtag

For more information about the provided blocks regarding logical operators visit:

Some more information from MakeCode

chevron-right🍎 Teacher's Corner - Battery packhashtag

his and many other applications created for the micro:bit can be better explored using a battery pack. It is not necessary but gives mobility to the micro:bit.

micro:bit battery pack infoarrow-up-right

Last updated

Was this helpful?