Free Shipping Over $119



Micro python Robot Course 6: Sound sensor

Posted by SuFiona on

Learning goal

This lesson learns how to use the sound sensor on the Tiny-bit microbit robot.

Preparation:

1.The position of the sound sensor module in the robot.

image.png

! ! ! Note:

In this experiment, we need to install the jumper cap in the position shown below.

image.png 

2.The micro:bit pins connected to the sound sensor.

From the hardware interface manual, we can know that the sound sensor is directly driven by the micro:bit P1 pin.

image.png Code

from microbit import *

horn = Image("00090:"

             "90990:"

             "99990:"

             "90990:"

             "00090")

 

calibration_Val = pin1.read_analog()

sleep(500)

 

while True:

    Voice_Val = pin1.read_analog()

    if Voice_Val > calibration_Val + 50:   

        # Detected changes in the external environment of the

        # current environment,

        # this parameter can be changed by yourself

        display.show(horn)

        sleep(200)

    else:

        display.show(Image.HAPPY)

 

Programming and downloading

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

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

image.png Figure 6-1

2.As shown in Figure 6-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 6-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 6-3.

image.png Figure 6-3

4.After downloading the program, we can a heart pattern is displayed on the micro:bit dot matrix. When we Shooting table, micro:bit dot matrix will display a horn pattern.

image.png    image.png

The code of the experiment: 6.Sound sensor.zip

Micro python Robot Course:

0 comments

Leave a comment

Please note, comments must be approved before they are published