Welcome to World of Module Sensor Kit repository
5.1 Running box
Note: Please use the double-headed data cable provided by us to connect the Micro:bit board and expansion board to the computer, otherwise it will not be possible to drive the servo due to insufficient power.
1. Learning target
In this lesson, we will use the micro:bit board, building blocks and sensor modules to build an running box.
When a person is detected passing by, the sensor will be triggered, and an alarm image will be displayed on the dot matrix.
Running box will swing its arms and move forward slowly.
2. Servo calibration
Before assembling the building blocks, we need to use code to calibrate the servo to a fixed angle.
If calibration is not calibrated before using, it is easy to jam the servo during use and cause the steering gear to stall and damage the servo.
Calibration method:
2.1 Connect the brown line of the servo to GND (black), the red line of the servo to VCC (red), and the yellow line of the servo to IO on expansion board.
The left servo is connected to P1, and the right servo is connected to P2. As shown below.
2.2 Then connect the computer to the Micro:bit board and expansion board through the double-head micro USB cable we provided.
2.3 Download the servo calibration code (Servo-calibration-running-box.hex) to the micro:bit board.
2.4 When a "1" pattern is displayed on the dot matrix of the Micro:bit board, it means the servo be calibrated successfully.
3. Building blocks assembly
Please follow the steps we provide to assemble the building block models.
Pay attention to the installation direction of the servo when assembling, otherwise the servo will be damaged due to the wrong angle of the servo after running the program.
After the assembly is completed, please check the wiring of the servo as shown below.

4. About wiring
5.Programming method
Mode 1 online programming: First, we need to connect the micro:bit to the computer by USB cable. The computer will pop up a USB flash drive and click on the URL in the USB flash drive: http://microbit.org/ to enter the programming interface. Add the Yahboom package https://github.com/YahboomTechnology/Module-World to program.
Mode 2 offline programming: We need to open the offline programming software. After the installation is complete, enter the programming interface, click【New Project】, add Yahboom package: https://github.com/YahboomTechnology/Module-World , you can start programming.
6. Code
The summary program is shown below.

Code-① indicates the initialization of each module, and the initialization drives the servo to 180°. This is the initial angle we set and the angle (Keep the servo on the running box upright). Then, the dot matrix displays a heart heart and pauses for 5 seconds for the human body infrared module is initialized.
Code-② is the servo control function, which controls two servos forward.
Code-③ is the servo control function, which drives the two servos backward.
Code-④ is the servo control function, which drives the two servos stand upright.
Code-⑤ is an infinite loop function, which constantly detects whether someone is moving in the current environment. If it detects that someone is moving, it will swing the servo and move forward slowly, otherwise the servo will stand upright.
Code-⑥ is an infinite loop function, which continuously detects whether someone is moving in the current environment. If someone is moving, an alarm sound effect is played.
Code-⑦ is an infinite loop, continuously detecting whether someone is moving in the current environment. If someone is moving, the dot matrix of the board will display an alarm pattern, otherwise it will show a smile.
7. Experimental phenomena
After the program is downloaded successfully. We can see a love heart displayed on the Micro:bit board, indicating that it is still being initialized, and the human infrared module cannot be triggered at this time.
After 5 seconds, Micro:bit shows a smile pattern, it means that the module is in normal working condition. When the human body infrared module detects that there is a human body moving, the dot matrix will switch to an alarm pattern, the buzzer will play the alarm sound, and the escape box will swing its arms and move forward slowly.
Note: The detection angle of the human body infrared sensor module is 120°.
The recognition effect is the best when the human body is directly in front.