Example Code for micro:bit-Light-operated Sprite
Last revision 2026/01/14
The article provides a comprehensive guide on using a micro:bit to control a Maqueen Lite robot based on light detection. It includes necessary hardware and software preparations, a wiring diagram, example code, and instructions on how to operate the robot using a flashlight. When light is detected, the robot's motors activate, and when the light is absent, the motors stop, showcasing a simple interactive robotics project.
Hardware Preparation
- Maqueen Lite x1
- micro:bit V1/V2 x1
- MicroUSB cable x1
- Flashlight x1
Software Preparation
- Programming Platform: makecode
- Libraries: maqueen, neopixel
Wiring Diagram
No additional wiring is required except inserting the micro:bit into Maqueen Lite.
Other Preparation Work
- Load MakeCode Graphical Library for Maqueen as described in the previous example.
- Prepare a flashlight.
Sample Code
Code Idea: when light is detected, all the motor are turned on, otherwise, they are turned off.
Code URL: https://makecode.microbit.org/_bxXUwrdzudDa
Code File: maqueen10.hex
Code Screenshot:
Result
Download the codes, power on Maqueen, and put it on the floor, it won't move. Turn on the flashlight, direct it at the front of the microbit, and Maqueen car begins to move forward; turn off the flashlight, and it stops.
Was this article helpful?
