The micro:bit does not have a special light sensor device fitted. However, it can use the LEDs of the matrix display to estimate the amount of ambient light. Using the editors, you can return a light level value (0-255) that you can use in your program.

Note that the LED column and row mapping is different on a V2 micro:bit to a V1

A V2 micro:bit uses the top row of LEDs for light sensing, whereas on V1 this is spread across the display. In practice, this means that if you cover the top row of LEDs on a V2, the light level will read 0.

MakeCode Editor

The light level block can be found under Input

As an example, the light level could be asigned to a variable

Python Editor

The light level can be read using display.read_light_level()for example:

from microbit import *
while True:
lightLevel = display.read_light_level()

Examples of  light sensing can be found in the micropython documentation

Further Information

Documentation and

This light sensing method uses an LED both as an output device, and an input device. When the output pin of the microprocessor drives a voltage across the LED, the LED lights up. If the micro-controller then sets that drive pin as an input, and times how long it takes for the voltage at the top end of the LED to collapse, that time is roughly proportional to the amount of ambient light. This method should be considered an approximation of the light level and will not be as accurate as using a dedicated light sensor such as an Light Dependent Resistor (LDR).

There is some background into the general technique in these links, which include details on not just how to sense ambient light with LEDs, but how to transfer small amounts of data wirelessly using the same technique.

Keywords for search: light sensing, light sensor, measure light level