Space In HIndi

 


Pages

Popular

Sound sensor

 Sound sensor

The sound sensor is a small board that combines a microphone (50Hz-10kHz) and some processing circuitry to convert sound waves into electrical signals. This electrical signal is fed to on-board LM393 High Precision Comparator to digitize it and is made available at OUT pin.



The module has a built-in potentiometer for sensitivity adjustment of the OUT signal. You can set a threshold by using a potentiometer; So that when the amplitude of the sound exceeds the threshold value, the module will output LOW otherwise HIGH. Apart from this, the module has two LEDs. The Power LED will light up when the module is powered. The Status LED will light up when the digital output goes LOW.

Interfacing Sound sensor with Arduino UNO 

Start by connecting VCC pin on the module to 5V on the Arduino and GND pin to ground. Now connect the OUT pin to the digital pin #7 on your Arduino.



Programming 

The following code detects claps and prints message on the serial monitor. 

#define sensorPin 7 // Variable to store the time when last event happened 

unsigned long lastEvent = 0; 

void setup() 

    pinMode(sensorPin, INPUT); // Set sensor pin as an INPUT 

    Serial.begin(9600); 

 }

 void loop()

 {

 // Read Sound sensor

 int sensorData = digitalRead(sensorPin); // If pin goes LOW, sound is detected

 if (sensorData == LOW) 

{

 // If 25ms have passed since last LOW state, it means that

 // the clap is detected and not due to any spurious sounds

 if (millis() - lastEvent > 25)

 {

    Serial.println("Clap detected!");

 } 

// Remember when last event happened 

lastEvent = millis();

 }

 } 

Output of the code for sound sensor is on Serial monitor as shown below.



No comments: