Science Oxford Logo

CCC - Hot or Code? Winter Warmers

Resources for the 'Hot or Code? Winter Warmers' Creative Computing Club.

During this workshop, you will create a cosy winter project using a BBC micro:bit, lighting it up in the dark and checking the temperature of hot drinks.

This page recaps what we discussed as a group.

To recap the torch, click here.

To recap the temperature sensor, click here.

To skip to the examples and ideas, click here.


Getting started

Download the starter code, go to the editor, and drag-and-drop the starter code into the window.


Follow the instructions to pair your micro:bit and create your first program!

Instructions-- Step 1: Pair your microbit. Step 2: Put the code on your micro:bit. Step 3: Experiment with the code blocks on the right. Step 4: Experiment with new blocks from the menu on the left.

Creating a light-reactive torch

To make the micro:bit respond to the light levels, you need to create an 'if then else' statement.

if the light level is high, then make something happen, else make something different happen.

Code Comparison-- Left: on button A pressed, show icon. Right: forever, if 'button A is pressed' then, show icon

These two blocks of code are equivalent.

The one on the right makes it easier to build more complex programs.

Using the code on the right, at the moment a heart will show on the micro:bit's display if button A is pressed.

Add to it, by clicking the + button at the bottom.

Make something different happen when the button is not pressed (else), for example clear the screen.

forever, if 'button A is pressed' then, show icon, else, clear screen

Now, you should see a heart when you click the button, and it will go away again afterwards. You can add a pause block after the icon to make it stay for longer!


Finally, update the code blocks so that the heart is displayed dependent on light level, instead of on a button press.

You can find the less than block in the Logic menu.

forever, if 'light level' less than 200 then, show icon, else, clear screen

Decide what you want to happen when the light is low, and edit the code.

Experiment with your physical micro:bit to see what is a good number to set the light level to - try covering the screen with your hand, or putting the micro:bit under your table!


Coding the temperature sensor

Using the temperature sensor is very similar to using the light sensor!

Right click on your light level if-then-else block, and duplicate it.

Put the copy of the code underneath the code that is already there, still inside your forever loop.

forever, if 'light level' less than 200 then, show icon, else, clear screen

Change the light level block to a temperature block, then change the number to something more appropriate - have a look at the emulator's temperature gauge!

Edit the code in this new if-then-else block to decide what happens when the temperature is too low.


You can add extra options to your if-then-else block to make one thing happen if the temperature is too low, and something different happen if the temperature is too high!

start of new code... if 'temperature' less than 10 then, show icon, else if 'temperature' greater than 40 then, show icon, else, clear screen

What next?

Get creative and add different features to your micro:bit.

The links below will help you with a couple of our ideas!