Built-in Light Sensor

To try out the built-in light sensing capability of the micro:bit, run the JavaScript Blocks code below.

From the editor, you can click on Download button (bottom right) and then copy the downloaded file onto your micro:bit. Alternatively, you can Click here to open the editor in a separate browser tab.

The light level block returns a value between 0 and 255 where 0 is dark and 255 is very bright. To fit this into a single digit range between 0 and 9 this number needs to be divided by 28.

You may be looking on the front of the micro:bit for a light sensor, but you won't find one. The micro:bit actually uses the LEDs of the display as a light sensor.

The technique for this relies on the fact that when an LED is reverse-biased (the wrong polarity for producing light) it can be filled with a small amount of charge. If you then let one of the pins for the LED act as an input and the other as a low output, the charge on the LED will leak away until the digital input stops being HIGH and becomes LOW. The time taken for this to happen depends on the amount of light falling on the LED. You can read more about this technique here

This guide was first published on Mar 09, 2018. It was last updated on Mar 09, 2018. This page (Built-in Light Sensor) was last updated on Mar 09, 2018.