5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10

Micro python Robot Course 4: Whistle

Posted by SuFiona on

Learning goal

This lesson we will learn how to control buzzer of Tiny-bit microbit robot to whistle.


1.The position of the buzzer on the robot car


2.The micro:bit pins connected to the buzzer.

From the hardware interface manual, we can know that the buzzer is directly driven by the micro:bit P0 pin.



from microbit import *

import music


while True:

    for freq in range(880, 1760, 16):

        music.pitch(freq, 6)

    for freq in range(1760, 880, -16):

        music.pitch(freq, 6)


Programming and downloading

1.You should open the Mu software, and enter the code in the edit window, , as shown in Figure4-1.

Note! All English and symbols should be entered in English, and the last line must be a space.

image.png Figure 4-1

2.As shown in Figure 4-2, you need to click the Check button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.

image.png Figure 4-2

3.You need to connect the micro data cable to micro:bit and the computer, then click the Flash button to download the program to micro:bit as shown in Figure 4-3.

image.png Figure 4-3

4.After downloading the program, we can hear the Tiny-bit car start to whistle.

The code of the experiment:4.Whistle.zip 

Micro python Robot Course:


Leave a comment

Please note, comments must be approved before they are published