Sound Sensor
Sound sensors can detect and measure ambient sound levels. Microphones could be considered specific and accurate sound sensors in which human speech is detected and can be played back or analyzed to create voice-controlled solutions.
Components
Component | Purpose |
---|---|
Arduino Nano | This will be the microcontroller |
KY037 sensor | This will be the sound sensor |
Circuit Diagram

Connections
KY037 sound sensor pins
Nano Pin | KY037 Pin |
---|---|
A0 | AO |
5V | VCC |
Gnd | Gnd |
Code
sound_sensor.ino
/*
Project: Sound Sensor
Project Description: This sketch reads values from a sound sensor and prints them to the serial monitor.
Author: STEMVentor Educonsulting
This code is copyrighted. Please do not reuse or share for any purpose other than for learning with subscribed STEMVentor programs. This code is for educational purposes only and is not for production use.
*/
// LIBRARIES
// PIN DEFINITIONS
#define SOUND_SENSOR_PIN A0
// GLOBAL VARIABLES
// INITIALIZE OBJECTS
// LOCAL FUNCTIONS
// Read Sound sensor values
void readsoundValues(){
float sound_value;
float percent_value;
sound_value = analogRead(SOUND_SENSOR_PIN);
Serial.println("Sound level is: " + sound_value);
// For ESP32, max analog read value is 4098
// For Arduino Nano, max analog read value is 1024
percent_value = map(soundValue, 0, 1024, 0, 100);
Serial.println("Sound % level is: " + percent_value);
}
void soundSensorSetup() //sound sensor setup
{
//Define the pin mode
pinMode(SOUND_SENSOR_PIN, INPUT);
}
/* SETUP CODE: runs once when the board starts up or resets */
void setup()
{
// Start the serial communication with baud rate suitable for your components.
Serial.begin(9600);
soundSensorSetup();
Serial.println("The Sound sensor is ready!");
}
/* MAIN LOOP: runs repeatedly at a very high frequency (1000s of times a second) */
void loop() {
readsoundValue();
delay(1000);
}