Sound Sensor

From Waveshare Wiki
Jump to: navigation, search
Sound Sensor
Sound-Sensor

Sound Sensor
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Features

  • Onboard audio power amplifier LM386
  • Audio signal gain up to 200
  • Adjustable accuracy
  • Signal output indicator

Specification

Item Parameters
Audio Amplifier Chips LM386 (Magnification 200x)
Operating Voltage 3.3V-5.5V
Dimensions 39.0mm*21.0mm
Fixed hole size 2.0mm

Pinouts

PIN Description
DOUT Digital data output
AOUT Analog data output
GND Ground
VCC Power input (3.3V~5.3V)

Working principle

LM386 is an audio-integrated power amplifier, which has the advantages of low power consumption, adjustable inner chain gain, large power supply voltage range, fewer external components, and low total harmonic distortion.
It is mainly used in low-voltage consumer products. To minimize peripheral components, the voltage gain is built in at 20. By adding an external resistor and capacitor between pin 1 and pin 8, the voltage gain can be adjusted to any value up to 200.

Configure Pico

MicroPython and C examples are provided for this sensor, to use it with Pico, you need to first flash firmware to the Pico according to the example.
Please refer to the guides of Raspberry Pi about how to flash the firmware. We recommend you use the firmware from the Demo codes archive.

Hardware connection

Hardware Connection
Sound Pico Description
VCC 3.3V Power input
GND GND Ground
AOUT GP26 Analog data output
DOUT GP22 Digital data output

Examples

Download the example

Open the terminal of Raspberry Pi and run the following command to download the example:

sudo apt-get install p7zip-full
cd ~
sudo wget  https://files.waveshare.com/upload/b/bc/Sound-Sensor-code.7z
7z x Sound-Sensor-code.7z -o./Sound-Sensor-code
cd ~/Sound-Sensor-code
cd Pico/c/build/

C

  • The following tutorial is for operation on Raspberry Pi, but due to the multi-platform and portable nature of CMake, it can also be compiled successfully on a PC, but the operation is slightly different and needs to be judged by the user.

To compile, make sure that in the c directory:

cd ~/Sound-Sensor-code/Pico/c/

Create and enter the build directory in the folder, and add the SDK.
Where ... /... /pico-sdk is the directory of your SDK.
Our sample application has a build in it, so go directly to it.

cd build
export PICO_SDK_PATH=../../pico-sdk
(Note: Be sure to write the right path to your own SDK)

Execute cmake to automatically generate the Makefile file.

cmake ..

Execute make to generate the executable file, the first compilation time is longer.

make -j9

When the compilation is complete, the uf2 file will be generated.
Press and hold the button on the Pico board, connect the Pico to the USB port of the Raspberry Pi via the micro USB cable, and then release the button. Once connected, the Raspberry Pi will automatically recognize a removable disk (RPI-RP2), and copy the main.uf2 file from the build folder to the recognized removable disk (RPI-RP2).

cp main.uf2 /media/pi/RPI-RP2/

Python examples

In Windows PC
  • Hold the BOOTSET button of the PICO board, and connect the Pico board to Raspberry Pi by USB cable
    • After connecting, release the button, and a portable disk (RPI-RP2) is recognized.
  • Copy the rp2-pico-20210418-v1.15.uf2 file to the portable disk (RPI-RP2).
  • Open the Thonny IDE (Please install the newest version that supports the Pico board or update).
  • Choose Tools -> Options -> Interpreter, and choose the Pico and the port.
Pico-lcd-0.96-img-config.png
  • Download the demo codes, unzip and find the MicroPython example.
  • Choose File -> Open -> Sound_Sensor.py and run it.
Pico-lcd-0.96-img-run.png
In Raspberry Pi
  • Flash the uf2 file to the Pico board just like in the Windows PC.
  • Open the Thonny IDE of Pi, make sure that it is the newest version, or update it.
  • Choose Tools -> Options... -> Interpreter.
    • Choose Pico and the Port.
Pico-lcd-0.96-img-config2.png
  • If your Thonny IDE cannot support the Pico board, you can update it and try again.
sudo apt upgrade thonny
  • Choose File -> Open... -> python/Sound_Sensor.py and run it.

Expected result

  • The indicator lights up when the microphone of the module is near the source and goes off when it is far from the sound source.
  • As the distance between the sensor and the sound source changes, the serial port output data changes accordingly.

The examples provided are based on the STM32F103RBT6 and the STM32H743, the connection provided is based on the STM32F103RB.
If you want to use other STM32 boards, please change the connection and you may need to port the codes yourself.

STM32

Hardware connection

Hardware connection-STM32
Connect to STM32F103RBT6
Sound STM32 Description
VCC 3.3V Power input
GND GND Ground
AOUT PA6 Analog data output
DOUT PA4 Digital data output

Examples

The examples are based on the HAL library. Please download the demo codes, unzip them, and find the STM32 examples.

  • Open the project from Sound-Sensor-code\STM32\STM32F103RB\MDK-ARM by Keil.
  • Build the project and program it to the STM32 board.
MQ5 STM32 2.jpg
  • Connect the UART1 of the STM32 board to the PC and check the serial data by SCCOM software.
STM32 Sound 1.png

Expected result

  • The indicator lights up when the microphone of the module is near the source and goes off when it is far from the sound source.
  • As the distance between the sensor and the sound source changes, the serial port output data changes accordingly.

The examples provided are based on the Arduino UNO, if you need to use other Arduino boards, please check if the board is compatible with the UNO.

Arduino

Hardware connection

Hardware connection-Arduino
Connect to Arduino UNO
Sound Arduino Description
VCC 5V Power input
GND GND Ground
AOUT A0 Analog data output
DOUT D2 Digital data output

Examples

  • Please download and install Arduino IDE to your PC.
  • Download the demo codes, unzip, and find the Arduino examples.
  • Open the Sound_Sensor.ino file by the Arduino IDE.
STM32 Sound 1.png
  • Build and upload the codes to the UNO board.
  • After uploading, you can open the Serial Monitor of IDE and check the data.

Expected result

  • The indicator lights up when the microphone of the module is near the source and goes off when it is far from the sound source.
  • As the distance between the sensor and the sound source changes, the serial port output data changes accordingly.

Resources

FAQ

 Answer:

The sound sensor can output either analog data or digital data. You can check the analog data by an oscilloscope, or get the analog data via an AD convertor directly.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

The AOUT pin outputs the sound signal, the sound can be heard if you connect a speaker to it. The rate of the sound signal is too fast which requires a high sample rate.
For example, the sample rate of a phone is 8kHz. The amplitude of the waveform indicates the intensity of the sound, and the greater the sound, the greater the amplitude.
Therefore, the AD value collected by the microcontroller cannot represent the sound. This module also does not measure the decibel level of sound.
The DOUT outputs digital data 0 or 1, if the sound is louder than the threshold value, it will output low voltage 0.
Sound Sensor FAQ.png

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

A potentiometer is used for increasing the increment. D potentiometer is used for setting the threshold value for digital output.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

50Hz ~ 20KHz.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

Perhaps you'd like:

Color Sensor

Color-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Flame Sensor

Flame-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Hall Sensor

Hall-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Infrared Reflective Sensor

Infrared-Reflective-Sensor-1
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Laser Sensor

Laser-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Liquid Level Sensor

Liquid-Level-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Moisture Sensor

Moisture-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

MQ5 Gas Sensor

MQ-5-Gas-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Rotation Sensor

Rotation-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Sound Sensor

Sound-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

DHT11 Temperature-Humidity Sensor

Temperature-Humidity-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

Tilt Sensor

Tilt-Sensor-1
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}

UV Sensor

UV-Sensor
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
{{{6}}}
{{{7}}}
{{{8}}}
{{{9}}}
{{{10}}}
{{{11}}}
{{{12}}}
{{{13}}}
{{{14}}}
{{{15}}}
{{{16}}}
{{{17}}}
{{{18}}}
{{{19}}}
{{{20}}}
{{{21}}}
{{{22}}}
{{{23}}}
{{{24}}}
{{{25}}}
{{{26}}}
{{{27}}}
{{{28}}}
{{{29}}}
{{{30}}}
{{{31}}}
{{{32}}}
{{{33}}}
{{{34}}}
{{{35}}}
{{{36}}}
{{{37}}}
{{{38}}}
{{{39}}}
{{{40}}}
{{{41}}}
{{{42}}}
{{{43}}}
{{{44}}}
{{{45}}}
{{{46}}}
{{{47}}}
{{{48}}}
{{{49}}}
{{{50}}}
{{{3}}}
{{{4}}}

{{{5}}}



Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)