Skip to content

Activity

Nightlight

Intermediate | MakeCode, Python | LED display, Light sensor | Input/output, Light, Selection, Sensors, Weather & climate

Step 1: Make it

What is it?

A nightlight that lights up your micro:bit’s LED display in the dark.

moon over micro:bit with all its LEDs lit

How it works

  1. Like the Sunlight sensor project, this uses the micro:bit’s LEDs as a light sensor input. Cover the display with your hand and see if it lights up.
  2. It uses selection to sense if the light falling on the micro:bit falls below a certain level – is less than (<) 100. If it is dark, it lights up the micro:bit display, else it clears the screen so the LEDs are dark.
  3. You may need to adjust the threshold number 100 depending on the lighting conditions where you are.
  4. What do you think you could use this nightlight for? Could it help improve safety for people or animals in the dark?

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • a source of light and something to cover the micro:bit with

Step 2: Code it

Step 3: Improve it

  • Change the image to show a moon or star when it gets dark.
  • Attach the micro:bit to your bag or clothing to use this as an additional safety light when walking or cycling – can you make it flash to stand out more?
  • Try this MakeCode project that makes the LED display get lighter and darker depending on the amount of light falling on the micro:bit. Where else have you seen things that react to light in this way?