Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

Content

  1. Introduction
  2. Preparations
  3. About the Sound Detection Sensor
  4. Examples

Introduction

The Sound Detection Sensor is a small board that combines a microphone and some processing circuitry, it has the ability to detect different sizes of sound. This sensor can be used to for a variety of uses from industrial to simple hobby or playing around.

In this lesson we will guide you through hooking up and using the Sound Detector. It will examine how the circuit works, explain some details about getting the best performance from the Sound Sensor, then present some projects that demonstrate how to use it.

Preparations

Hardware

Software

About Sound Detection Sensor

The Sound Detection sensor module has a built-in capacitive electret microphone which is highly sensitive to sound. Sound waves cause the thin film of the electret to vibrate and then the capacitance changes, thus producing the corresponding changed voltage, so it can detect the sound intensity in ambient environment. Since the change is extremely weak, it needs to be amplified. We use a LM393 as the power amplifier here. You can adjust the sensitivity with by adjusting the Potentiometer. When the sound level exceeds the set point, an LED on the sensor module is illuminated and the output is sent low.

Note: This sound sensor is used to detect whether there’s sound surround or not, it cannot recognize the frequence or volum, please don’t use the module to collect sound signal.

Examples

Digital Detect Sound Sensitive Lights

In this example, we are going to connect the Sound Detection sensor module to the Arduino digital pin to control the on-board LED, so that the LED will light up every time the sensor detects sound.

Note: The sensitivity of the Sound Detection sensor is adjustable – you may adjust it by the potentiometer.

Connection

First, please plug OSOYOO Magic I/O shield into UNO board:

Overhere we use the D2 as the digital pin to connect with the sound sensor, build the circuit as below (please put the switch on sound sensor to D):

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

int digit_sensor = 2; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int digitValue ; //  value from the digit input pin void setup () { pinMode (ledPin, OUTPUT); pinMode (digit_sensor, INPUT); Serial.begin (9600); } void loop () { digitValue=digitalRead(digit_sensor); if (digitValue==LOW) { digitalWrite (ledPin, HIGH); delay(50); } else { digitalWrite (ledPin, LOW); delay(10); } }

Running Result

A few seconds after the upload finishes, you can clap or knock something next to the sensor, when the volume reaches to a certain value, the LED attached to pin 13 on the Osoyoo Uno board will light up.

Note: If the LED is not lighting up or the LED is always bright, you need to change the sensor sensitivity by rotating the potentiometer.

Analog Detect Sound Sensitive Lights

In this example, we will show how to use the analog pin to detect the sound. The microphone sensor will detect the sound intensity of your surroundings and will light up an LED if the sound intensity is above a certain threshold.

Connection

Overhere we use the A0 as the analog pin to connect with the sound sensor, build the circuit as below (please put the switch on sound sensor to A):

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

const int ledPin = 13; //pin 13 built-in led const int soundPin = A0; //sound sensor attach to A0 int threshold = 600; //Set minimum threshold for LED lit void setup() { pinMode(ledPin,OUTPUT);//set pin13 as OUTPUT Serial.begin(9600); //initialize serial } void loop() { int value = analogRead(soundPin);//read the value of A0 Serial.println(value);//print the value if(value > threshold) //if the value is greater than 600 { digitalWrite(ledPin,HIGH);//turn on the led delay(200);//delay 200ms } else { digitalWrite(ledPin,LOW);//turn off the led } delay(1000); }
This is the code to make a LED blink with sound. You have to set the threshold so it’ sensible enough to make the led blink, you can also see the value of sound intensity on Serial Monitor.

Running Result

After copying and uploading this code, when the volume reaches to a certain value, the LED attached to pin 13 on the Uno board will light up. If the sound does not sense very well, try changing the threshold value or changing the sensor sensitivity by rotating the potentiometer.

You can open the Serial Monitor by going to Tools > Serial Monitor or pressing the magnifying glass-button in the Arduino software window.

What prints out is the analog and digital values of from the sound sensor module. The analog value should spike up when a noise occurs and stabilize when it gets quiet again. Now in the code there is an “int threshold = 600;” line that needs to be changed to something very close but higher than the value you get from the Serial Monitor when it is quiet around you. For instance if you see an analog value of 500, then threshold should be changed to perhaps 503 or 505. When a sound occurs, the analog value will rise and go above the threshold value. When that happens your LEDs will turn on. When it gets quiet again the analog value will go back to 503 and the LEDs go dark again.