Lesson 9 Sound Sensor

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp


In this lesson, we will use LED and sound sensors to judge if the ambient noise is too high.


Programming Steps

Step 1

After creating a new project, click on the Simulation icon on the left side of the page to enter the Simulation page.

Step 2

Connect the LED module to D0, the Sound Sensor to A0, and the VCC and GND to 3.3V and GND respectively. The sound sensor can sense the noise level in the environment. When the reading value is higher than the threshold, the LED will light up.

Step 3

Click the Create variable button under Variables category to create two variables: threshold and soVal.

Step 4

Read the value of the sound sensor and assign it to the variable soVal, then print it  in Debug Monitor.

Step 5

Connect the Bluetooth and click on Flash button to compile and download the code. Remember the value under normal conditions, then play a piece of music or slap the microphone, and you can see that the value of sound sensor decreases with the louder sound.

Step 6

Now, set a value slightly less than the current environment based on the value read in the previous step.

Step 7

A judgment condition is set by using the if do block and the Comparison Operator   ( = ) block to judge if the soVal is less than the threshold.

Step 8

If the value of the sound sensor (soVal) is less than the threshold set, set the LED module to 1 to lighten it.

Step 9

Otherwise, set the LED module to 0 to turn it off.

Step 10

Drag the slider to simulate the value of sound sensor and you can find when the  value read is less than 1500, the LED light up; otherwise, it will turn off. Now save  your project, connect the Bluetooth and click Flash to compile and download the code.