Heya, so, i have a project that needs to detect a peak in sound and send a push notification whenever the sound peaks. I got an ESP8266 wifi board up and running, and it works fine, everything is good.
But, i tried adding a sound sensor, as shown in the image and whenever i try to connect the microphone output to D7 or D2, digitalRead() always returns LOW, and whenever i connect it to D4, it always returns HIGH, and i don't understand why.
(The ESP board connections are omitted for clarity. Also, Fritzing didn't have the sensor i use, so the actual sensor is this one - If there is need for the full diagram, i'll update it here)
I also tried connecting the mic output to the Analog IN pins, and they all seem to return values that doesn't seem to correlate to the ambient sound.
Thanks in advance!
This is all the code related to the sensor, again, the ESP part was omitted for clarity - I'll edit if needed
int soundVal = 0;
void setup() {
Serial.begin(74880);
Serial.println("Starting");
}
void loop() {
soundVal = analogRead(0); // Or digitalRead for the digital pins when i tried them
Serial.println(soundVal, DEC);
}
The sound sensor looks very much like a digital (HIGH/LOW output) device and as such needs to be read using digitalRead()
Try the code and connections here Guide for Microphone Sound Sensor Arduino | Random Nerd Tutorials
The sound sensor looks very much like a digital (HIGH/LOW output) device and as such needs to be read using digitalRead()
I already tried digitalRead(), it returns HIGH on pin D4, and LOW on pin D2 and D7 no matter the ambient sound or sensitivity on the potentiometer.
Actually, that link you sent is the one i was using as reference when i first connected the sensor, the only difference is that i didn't use the LED part, and i'm trying to simply print the sensor status (HIGH or LOW) directly to Serial
It makes no sense that the sensor should give different results on different digital pins.
Please post the code that you used to read the output of the module
Please post the code that you used to read the output of the module
Here it is:
int soundVal = 0;
void setup() {
Serial.begin(74880);
Serial.println("Starting");
}
void loop() {
soundVal = analogRead(0); // Or digitalRead for the digital pins when i tried them
Serial.println(soundVal, DEC);
}
Also placed it on the original post. This is the sound sensor part of the code, the ESP8266 doesn't interfere with any of the pins or variables in it.
I also noticed that "pinMode(pin, INPUT)" seems to output 0 repeatedly, then breaks Serial as soon as i clap or snap, it kind of outputs some weird symbols and stops printing
EDIT: on pin 4 it outputs:
f000, len 1384, room 16
tai1
1
before repeating "1"
And the code when using digitalRead() ?
And the code when using digitalRead() ?
The output i said was using digitalRead(), I sent the wrong snippet, sorry
Using analogRead() outputs what seems to be random data that doesn't match any ambient sound around, no matter what sensitivity on the potentiometer
Concentrate on digital input. If the input does not change then I would suspect a faulty detector or faulty wiring