Turn the Micro:bit into a Light Sensor

Use code to find out how bright or dark it is.

Step 1

Create a new blank JavaScript Blocks project.

Step 2

The micro:bit measures the light around it by using some of the LEDs on the LED screen.

The first time you use it, this reading will say 0. After that, it will say the real light level. This is because the light sensor (the part that can find the light level) has to be turned on first.

Enter this code:

When you press button B on the micro:bit, this program shows the light level on the LED screen.

Step 3

To test it out, run it on the micro:bit.

Can you make the value change by shining a light on it?

What is the lowest number possible? 

What is the highest number you can make it display? 

How long does it take to react to a change in light?