I am trying to get a Sound-Sensor to work. But with no luck. What could I be missing?
The sound sensor example which I am inspired from could be accessed from the link:
Below is my code:
const int soundPin = 7;
int soundVal;
void setup ()
{
pinMode (soundPin, INPUT);
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop ()
{
soundVal = digitalRead(soundPin);
Serial.print("Sound Value is: " +soundVal);
}
The output for soundVal is nothing. I am getting output something like this:
Sound Value is:
Sound Value is:
Sound Value is:
...
I tried working with a different sound-sensor, but still no luck.
My next problem is, it gives output "0" irrespective of whether i make sound or not (and never "1").
15:37:34.097 -> Sound Value is: 0
15:37:34.097 -> Sound Value is: 0
15:37:34.097 -> Sound Value is: 0
15:37:34.117 -> Sound Value is: 0
15:37:34.150 -> Sound Value is: 0
Like @TomGeorge pointed out, the output is digital and so will be HIGH (no sound) or LOW (sound).
Try this code:
const int soundPin = 7;
int soundVal;
void setup ()
{
pinMode (soundPin, INPUT);
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop ()
{
soundVal = digitalRead(soundPin);
if (soundVal == LOW)
{
Serial.print("Sound detected");
}
}
You may need to adjust the sensitivity (blue pot) to get an output.
There is more example code on the page that you linked.
Now, I am getting the output as:
15:58:33.355 -> Sound detected
15:58:33.355 -> Sound NOT detected
15:58:33.389 -> Sound NOT detected
15:58:33.422 -> Sound NOT detected
15:58:33.422 -> Sound detected
15:58:33.455 -> Sound NOT detected
15:58:33.455 -> Sound NOT detected
I think the soundsensor is very sensitive as of now. It is picking up background noise. I guess I will have to adjust the sensitivity and try again.
How to get Arduino to work with 2 sound-sensor-modules?
(I can get it to work with 1 sound-sensor-module)
const int soundPinRight = 7;
const int soundPinLeft = 8;
int soundValRight;
int soundValLeft;
void setup ()
{
pinMode (soundPinRight, INPUT);
pinMode (soundPinLeft, INPUT);
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop ()
{
soundValRight = digitalRead(soundPinRight);
soundValLeft = digitalRead(soundPinLeft);
if (soundValRight == LOW)
{
Serial.println("Sound Right detected");
}
if (soundValLeft == LOW)
{
Serial.println("Sound Left detected");
}
}
There is only one single port for '5V' so I connected it to the breadboard. And then connected the breadboard to the 2 sensors. The problem is sensitivity does not work anymore on the sound-sensors.