yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
World of Module Sensor Kit📖
1.Introduction
  • 1.1 Introduction
  • 1.2 Building block list
2.Programming preparation
  • 2.1 About BBC microbit
  • 2.2 About Microbit expansion board
  • 2.3 MakeCode Programming Guide
  • 2.4 Programming block reference manual
  • 2.5 Python Programming Guide
  • 2.6 Python API
3.Basic course(MakeCode)
RGB light module
  • 1.Introduction of module
  • 2.Light up a RGB
Button module
  • 1.Introduction of module
  • 2.Button detection
Rocker module
  • 1.Introduction of module
  • 2.Control rocker
Photosensitive module
  • 1.Introduction of module
  • 2. Read the light intensity
Infrared module
  • 1.Introduction of module
  • 2. Obstacle detection
TemperatureHumidity module
  • 1.Introduction of module
  • 2.Read temperature humidity
Ultrasonic module
  • 1.Introduction of module
  • 2. Ultrasonic ranging
Digital Tube module
  • 1.Introduction of module
  • 2. Digital tube display
Human body infrared module
  • 1.Introduction of module
  • 2.Human body detection
Color Recognition module
  • 1.Introduction of module
  • 2. Color recognition
Servo
  • 1.Introduction of servo
  • 2.Drive servo
4.Advanced course(MakeCode)
  • 4.1 Table lamp
  • 4.2 Rocker control light
  • 4.3 Emergency light
  • 4.4 Infrared warning device
  • 4.5 Hand-held rangefinder
  • 4.6 Human body warning device
  • 4.7 Color recognition
  • 4.8 Thermometer
  • 4.9 Smart wiper
  • 4.10 Rotating rangefinder
  • 4.12 Piggy bank
5.Creative cours(MakeCode)
  • 5.1 Running box
  • 5.2 Temperature-humidity measurement
  • 5.3 Lifting platform
  • 5.4 Interactive box
  • 5.5 Moving basket
  • 5.6 Automatic door
  • 5.7 Sunflower
  • 5.8 Flying penguin
  • 5.9 UFO catcher
  • 5.10 Color sorter
6.Basic course(Python)
  • 6.1 Light up a RGB
  • 6.2 Button detection
  • 6.3 Control rocker
  • 6.4 Read the light intensity
  • 6.5 Obstacle detection
  • 6.6 Read temperature humidity
  • 6.7 Ultrasonic ranging
  • 6.8 Digital tube display
  • 6.9 Human body detection
  • 6.10 Color recognition
  • 6.11 Drive servo
7.Advanced course(Python)
  • 7.1 Table lamp
  • 7.2 Rocker control light
  • 7.3 Emergency light
  • 7.4 Infrared warning device
  • 7.5 Hand-held rangefinder
  • 7.6 Human body warning device
  • 7.7 Color recognition
  • 7.8 Thermometer
  • 7.9 Smart wiper
  • 7.10 Rotating rangefinder
  • 7.11 Piggy bank
8.Creative course(Python)
  • 8.1 Running box
  • 8.2 Temperature-humidity measurement
  • 8.3 Lifting platform
  • 8.4 Interactive box
  • 8.5 Moving basket
  • 8.6 Automatic door
  • 8.7 Sunflower
  • 8.8 Flying penguin
  • 8.9 UFO catcher
  • 8.10 Color sorter
Download
  • Assembly Steps
  • Code
  • MicroPython_library
Download ZIP

Welcome to World of Module Sensor Kit repository

8.7 Sunflower


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 a sunflower. We can use the joystick to control the photosensitive module up, down, left, and right, or press the button to let the sunflower automatically track the brightest light.

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 bottom servo is connected to P1, and the upper servo is connected to P10. As shown below.

image.png 

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-Sunflower.py) to the micro:bit board.

2.4 When a "7" 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.

image.png 

4. About wiring

image.png  

5. About code

# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor
from microbit import *
import WOM_Sensor_Kit
 
display.off()
x = 200
y = 250
WOM_Sensor_Kit.WOM_init_display(7)
value = [0, 0, 0, 0, 0, 0]
minimum = 1023
 
while True:
    WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
    WOM_Sensor_Kit.WOM_servo360(pin1, 200)
    WOM_Sensor_Kit.WOM_servo360(pin10, 250)
 
    if WOM_Sensor_Kit.WOM_button(pin0) == 1:
        WOM_Sensor_Kit.WOM_servo360(pin1, 200)
        WOM_Sensor_Kit.WOM_servo360(pin10, 300)
        sleep(500)
        value[0] = WOM_Sensor_Kit.WOM_light(pin2)
        WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
        print(value[0])
        WOM_Sensor_Kit.WOM_servo360(pin1, 250)
        WOM_Sensor_Kit.WOM_servo360(pin10, 300)
        sleep(500)
        value[1] = WOM_Sensor_Kit.WOM_light(pin2)
        WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
        print(value[1])
        WOM_Sensor_Kit.WOM_servo360(pin1, 250)
        WOM_Sensor_Kit.WOM_servo360(pin10, 240)
        sleep(500)
        value[2] = WOM_Sensor_Kit.WOM_light(pin2)
        WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
        print(value[2])
        WOM_Sensor_Kit.WOM_servo360(pin1, 200)
        WOM_Sensor_Kit.WOM_servo360(pin10, 240)
        sleep(500)
        value[3] = WOM_Sensor_Kit.WOM_light(pin2)
        WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
        print(value[3])
        WOM_Sensor_Kit.WOM_servo360(pin1, 130)
        WOM_Sensor_Kit.WOM_servo360(pin10, 240)
        sleep(500)
        value[4] = WOM_Sensor_Kit.WOM_light(pin2)
        WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
        print(value[4])
        WOM_Sensor_Kit.WOM_servo360(pin1, 130)
        WOM_Sensor_Kit.WOM_servo360(pin10, 300)
        sleep(500)
        value[5] = WOM_Sensor_Kit.WOM_light(pin2)
        WOM_Sensor_Kit.WOM_display(WOM_Sensor_Kit.WOM_light(pin2))
        print(value[5])
        WOM_Sensor_Kit.WOM_servo360(pin1, 200)
        WOM_Sensor_Kit.WOM_servo360(pin10, 300)
        sleep(500)
        for i in range(6):
            if value[i] < minimum:
                minimum = value[i]
                print(minimum)
        if value[0] == minimum:
            WOM_Sensor_Kit.WOM_servo360(pin1, 200)
            WOM_Sensor_Kit.WOM_servo360(pin10, 300)
            sleep(5000)
        if value[1] == minimum:
            WOM_Sensor_Kit.WOM_servo360(pin1, 250)
            WOM_Sensor_Kit.WOM_servo360(pin10, 300)
            sleep(5000)
        if value[2] == minimum:
            WOM_Sensor_Kit.WOM_servo360(pin1, 250)
            WOM_Sensor_Kit.WOM_servo360(pin10, 240)
            sleep(5000)
        if value[3] == minimum:
            WOM_Sensor_Kit.WOM_servo360(pin1, 200)
            WOM_Sensor_Kit.WOM_servo360(pin10, 240)
            sleep(5000)
        if value[4] == minimum:
            WOM_Sensor_Kit.WOM_servo360(pin1, 130)
            WOM_Sensor_Kit.WOM_servo360(pin10, 240)
            sleep(5000)
        if value[5] == minimum:
            WOM_Sensor_Kit.WOM_servo360(pin1, 130)
            WOM_Sensor_Kit.WOM_servo360(pin10, 300)
            sleep(5000)
        minimum = 1023

6.Writing and download code

6.1 You should open the Mu software, and enter the code in the edit window, , as shown below.

Note! All English and symbols should be entered in English, use the Tab key (tab key) to indent and the last line must be a space.

6.2 You can click the “Check” button to check if our code has an error.

If a cursor or underline appears on a line, it indicates a syntax error, please check and modify. If there is no error in the program, the bottom left of the interface will prompt that there is no problem in detection.

image.png  

6.3 Click the ‘REPL’ button to check whether the WOM_Sensor_Kit Python library has been downloaded.

If not, please refer to [Preparation before class] --> [Python Programming Guide] .

image.png 

6.4 After the program is written, use a micro USB cable to connect the computer and the micro:bit board. Please click the ‘Flash’ button to download the program to the micro:bit motherboard (You need to click the ‘REPL’ button again to close the function of importing library files before you download the program).

image.png 

6.5 If the download failed, please confirm whether the micro:bit is connected to the computer through the micro USB data cable, and confirm whether the WOM_Sensor_Kit Python library has been imported.

7. Experimental phenomena

After the program is downloaded successfully. We can use the joystick to control the photosensitive module up, down, left, and right, or press the button to let the sunflower automatically track the brightest light.


Automatic door
Flying penguin

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文