1. Overview
The sound sensor acts as a microphone that can capture sound information in the environment.
It is consists of a sensitive capacitor microphone for detecting sound and an amplification circuit. It works based on the propagation and vibration of sound. When sound travels near the sensor, the sound wave causes the sensor to vibrate. Then, the sensor converts sound vibrations into electrical signals and sends them for further processing or analysis.
2. Parameters
3. Principle
When you speak loudly or play music to the MIC, these sound signals are converted into electrical ones, which are output at analog ports.
The amplifier circuit on the module amplifies the sound detected by the MIC. We can adjust the amplification by rotating the potentiometer. It is the maximum when we adjust the potentiometer clockwise to the end.
4. Wiring Diagram
The sound sensor is an analog module. It needs to be connected to a red socket of the main board.
Here we connect the module to socket 7. From the port view of the kidsIOT board, socket 7 is the analog port io35.
5. Test Code
/*
Project name: 9_sound
Function: Read the analog value of the sound sensor
Author: keyestudio
Hardware connection:
- Connect to port 7
Library:
- none (no need to import additional library)
Cautions:
- Connect to port 7
- Before uploading test code, please correctly connect to the development board and port
- Set the baud rate to 9600 before using serial monitor printing
*/
#define sound_Pin 35 //set pin to IO35
void setup() {
//Set the baud rate
Serial.begin(9600);
//set IO35 to input
pinMode(sound_Pin, INPUT);
}
void loop() {
//Read the sound analog value
int sound_value = analogRead(sound_Pin);
//Print the sound analog value
Serial.print("Analog value:");
Serial.println(sound_value);
}
6. Test Result
After uploading the test code, open the serial monitor and set the baud rate to 9600, and the serial monitor prints the analog values of the sound sensor. Make some noise to the microphone, and these values changes.
We can’t add a delay to the code because the sound grabs the sound signals very quickly.