How to use The Sound Sensor Module
The sound sensor module utilizes a microphone to sense any sounds. In this guide, we will be using the Sound Sensor Module from our shop.
Parts
Wiring Guide
Step 1: Connect the sensor pins to the Arduino
Sensor | Arduino |
---|---|
G | GND |
+ | 5V |
D0 | Pin 3 |
Programming
Step 1: Declare the pin connected to the sensor as well as a boolean value
int sensorPin = 3;
boolean val = 0;
Step 2: Activate the pin connected to the sensor as well as activating the serial monitor
void setup(){
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
Step 3: Read the sensor pin and put the value into val
val = digitalRead(sensorPin);
Step 4: Create an if/else
statement for when the sensor hears sound
if (val == HIGH) {
Serial.println("ON");
}else{
Serial.println("OFF");
}
delay(1000);
Full Code
int sensorPin = 3;
boolean val = 0;
void setup(){
pinMode(sensorPin, INPUT);
Serial.begin (9600);
}
void loop (){
val = digitalRead(sensorPin);
if (val == HIGH){
Serial.println("ON");
}
else{
Serial.println("OFF");
}
delay(1000);
}
Output
Serial Monitor