8. Case 07: Auto Lamps

8.1. Introduction

  • The auto lamps are able to turn on when the night is approaching and to turn off while the daylight comes.

8.2. Function

  • Detect the light level with the light sensor on micro:bit, if the light level is too low, program to turn on the lamps; or to turn off the lamps.

8.4. Picture


8.5. Hardware Connection

Connect the yellow LED to P1 port on IoT:bit.


8.6. Software Program

Click “Advanced” in the MakeCode drawer to see more choices.


For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “iot-environment-kit” in the dialogue box to download it.


Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

8.7. Program

Detect if the light level is below 100.


If yes, set to light on the LED; or light off it.


Link: https://makecode.microbit.org/_RJV5CuH4i1f9

8.8. Result

  • If the light level is too low, program to turn on the LED automatically; or to turn off it.