Code Example for micro:bit-Button Lamp
This article presents a comprehensive code example for creating a button-controlled lamp using a micro:bit, providing detailed hardware and software preparation steps, wiring diagrams, and sample programs in Mind+ and Makecode, enabling users to build an interactive LED project.
Hardware Preparation
![]() |
![]() |
|---|---|
| BOS0002 Push Button Module | BOS0017 LED Module |
![]() |
![]() |
| MBT0039 Micro:bit | BOS0040 Micro:bit BOSON Expansion Board |
Tips: micro:bit and Micro:bit BOSON expansion boards are used in the programming example.
Software Preparation
Wiring Diagram
Other Preparation Work
- Connect the micro:bit to the BOS0040 Micro:bit BOSON Expansion Board.
- Ensure all components are properly wired as per the diagram.
Sample Code
Mind+ Sample Program

Result
The LED turns on when the button is pressed and off when released. Refer to the demo video:

Additional Information
Flow Chart:

Was this article helpful?




