micro:bit V1 / V2 · MakeCode or Python
micro:bit automatic nightlight
Use a light reading and a simple rule to turn the onboard LED display on in the dark. Start in the simulator, then try the same logic on a board.
Start with the basics
What you will build
The LED display turns on when the surroundings become dark and off when they become brighter.
Before you start
- No external circuit is needed. Begin with a loop and a condition in the official example.
Model and software requirements
- The official project supplies MakeCode, Python and HEX entry points. V1 and V2 can use the onboard light reading.
- Use the original editor's example. A light threshold is an adjustable example, not a universal calibration value.
Similar products, older hardware and other software versions are not automatically interchangeable.
Materials & equipment checklist
Check items as you prepare them. Follow each source for part specifications, kit contents and assembly requirements.
This checklist is for the physical route. Simulator-only use does not require these hardware items.
0 of 3 required materials ready
Checks stay on this page only and are not uploaded. Refreshing or leaving resets them.
Required materials
- × 1
Needed for the physical route, not for the simulator. The light sensor uses the onboard LED display.
Material referencehttps://microbit.org/projects/make-it-code-it/nightlight/ - × 1
For transfer and USB power; use the connector required by the board.
Material referencehttps://microbit.org/get-started/user-guide/transfer-code-to-the-microbit/ Use available light and a way to shade the board; the original project specifies no purchase model or quantity.
Material referencehttps://microbit.org/projects/make-it-code-it/nightlight/
Optional materials
- × 1
Only if running away from USB power.
Material referencehttps://support.microbit.org/support/solutions/articles/19000013982-connecting-a-power-supply-to-the-micro-bit - × 2
For the optional compatible battery holder; follow the official power guidance.
Material referencehttps://support.microbit.org/support/solutions/articles/19000013982-connecting-a-power-supply-to-the-micro-bit
Equipment & tools
- A computer with a browser. The simulator is enough to explore the rule; physical testing needs a board and USB data cable.
Build route
Follow the original instructions in order. This overview does not replace wiring diagrams or calibration procedures.
- 1
- 2
Try the official program
Choose MakeCode or Python. In MakeCode, change the simulated light level to observe the rule.
Open this step - 3
Transfer to hardware
Follow the official transfer procedure and power the board by USB or a compatible battery pack.
Open this step - 4
Adjust the threshold
Compare brighter and shaded conditions, then adjust the program's threshold for the test environment.
Open this step
First-run checks
- Shading and illumination produce the expected LED changes.
- Changing the threshold changes when the LEDs turn on.
Outside this project's scope
- This is a sensor-and-control exercise, not a room light, precise lux meter or mains appliance controller.
- Simulator success does not verify the real sensor, cable or power supply.
Assembly and operation notes
- Handle the board by its edges and follow the official battery and board safety guidance. Do not connect mains electricity.
What to include in your budget
- Count the board or kit, data cable and optional batteries separately. The simulator route does not require a hardware purchase.
Original documentation and code
- Official nightlight project and codePublic resource
MakeCode, Python and HEX entry points are on the original page; source content is CC BY-SA 4.0.
https://microbit.org/projects/make-it-code-it/nightlight/ - Transfer codePublic resourcehttps://microbit.org/get-started/user-guide/transfer-code-to-the-microbit/
- Power requirementsPublic resourcehttps://support.microbit.org/support/solutions/articles/19000013982-connecting-a-power-supply-to-the-micro-bit
- Board safetyPublic resourcehttps://microbit.org/get-started/user-guide/safety/
Sources accessed: 2026-10-14. This page is compiled from the original documentation and has not been hardware-tested by RoboFacet. Check the original source for kit contents, prices and software updates.