How could you use a light sensor to show when clouds passed over your school?
A cloud passes over your school and the classroom gets dimmer. By the time you look up, the sun is back. Could you set up a light sensor to leave a record of that change?
You already know how to read a digital input. The micro:bit can tell whether button A is pressed or released. A light sensor with an analogue output gives you a voltage that can vary as the light changes.
As the light changes, the sensor voltage can change too. The board uses analogue-to-digital conversion, or A D C, to turn the voltage into a whole-number code. Check your board's documentation. On a micro:bit running MicroPython, an analogue read on pin zero returns zero to one thousand and twenty-three.
Your program calls the micro:bit's analogue read function on pin zero. Which number could the function return directly? Pick the value that fits the documented range.
Connect the sensor's analogue output to pin zero and share the board's ground. Cover the sensor for the dark reading, then use a lamp for the bright reading without changing the circuit. Here the dark reading is one hundred and twenty counts. The bright reading is higher, at eight hundred and forty.
Start when the elapsed time is zero seconds. For a two-second interval, add two seconds to get the next target time. Add two again for four seconds, then again for six. Schedule each read from the original start, so time spent saving one sample doesn't push the next target back.
Now you want four samples at three-second intervals. The first sample is taken when the elapsed time is zero. Which list gives all four target times? Pick one.
Press button A to start. Pin one lights a status L E D through a resistor. The program opens a CSV file and writes the headings. At each scheduled time it records the elapsed milliseconds just before reading pin zero, then saves both values. The light goes out after the file closes.
Suppose the log shows six hundred and twenty. That's the board's ADC code, so report it as a raw count. Writing six hundred and twenty lux would claim a light measurement you haven't made. Your dark and bright checks show how the sensor responds, but they don't establish a conversion to lux.
After capture, copy the CSV from the micro:bit and open it. This example has four data rows, gaps close to two seconds and codes within range. If asked how you measured and stored data from an analogue input, give the board, sensor, range, references and interval. Include the checked log extract.