# Having trouble reading low/high from this sound sensor

#### zirconx

Joined Mar 10, 2010
97
Hi,I'm having some trouble getting accurate readings from this sound sensor. It runs on 3-5v, and signals LOW when sound is above an (adjustable) threshold. I'm reading the output pin on my voltmeter as well as a Pine64 SBC. (similar to a Raspberry Pi).

A couple links on this particular sensor:
https://www.electronicshub.org/interfacing-sound-sensor-with-arduino/
http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-sound-detection-sensor-tutorial-and-user-manual/
I bought it from here: https://www.banggood.com/Microphone-Sound-Sensor-Module-Voice-Sensor-High-Sensitivity-Sound-Detection-Module-Whistle-Module-p-1235446.html

The problem I am having is the signal does not go low enough. When powered by 5v, I get a 5v signal when there is no sound. When there is sound (I'm using a tone generator app on my phone), the signal goes to 3v. I would expect it to go to 0v.

When powered by 3.3v (which is how I will use it on the Pine64), a LOW signal is only 1.8v. This is not low enough to trigger a LOW reading on my Pine64. I tried adding a resistor to ground. That adjusts the HIGH/LOW signals downward, but not enough that I can get a reliable reading either way.

The sound indicator LED on the board seems to light reliably and solid when I provide the test tone signal.

When I turn the adjustment knob most of the way down, I can get a 0v signal, but then it never goes HIGH either (it's too sensitive).

Am I using this wrong? Do you think I got a bad batch (I've tried two of them)? Thanks for any help.

#### Attachments

• 3 MB Views: 6

#### spinnaker

Joined Oct 29, 2009
7,835
Did you try blocking the microphone to rule out any ambient sound?

#### sghioto

Joined Dec 31, 2017
1,038
When powered by 3.3v (which is how I will use it on the Pine64), a LOW signal is only 1.8v.
From the voltage readings the output may be oscillating. Can you put a scope on the output? What are the readings when not connected to the Pine64?
SG

#### zirconx

Joined Mar 10, 2010
97
I have tried it unconnected to the Pine64, the readings were (pretty much) the same.

I agree from the voltage readings it seems like it could be oscillating. I don't have a scope but the voltage readings look stable. They match what the audio-signal indicator LED is showing on the board - it's on solid, and the voltage seems to be a solid 1.8v, for example. I don't see the LED flickering.

I didn't try blocking the mic, but the LED audio-signal indicator seems to be working. In a quiet room the LED is off (and I read 3.3v). Then I turn on the tone generator and the LED goes solid, and the voltage drops to 1.8v.

If I had an analog input I could work with this, but the Pine64 doesn't have any.

Given this circuit (thatI found on one of the pages I linked earlier), is there anything I could check or do differently?

#### Raymond Genovese

Joined Mar 5, 2016
1,658
It is a very cheap unit and you could have a crappy pot on it, or something else. Look at the schematic here https://www.electronicshub.org/interfacing-sound-sensor-with-arduino/

Can you put your meter on the analog out point and see if it systematically changing with sound? With no power, can you see if the pot is systematically changing or jumping?

edited to add: you posted the schematic as I was typing. So that LM393 is function as a simple comparator INA and INB with the pot setting the value to decide if OUT goes low or stays high.

Checking the analog out is one thing as I mention. Checking the pot is another.

Last edited:

#### sghioto

Joined Dec 31, 2017
1,038
I don't see the LED flickering.
If the oscillation is fast enough you would not notice any flickering. You really need to look at the output with a scope.
Edit: You are checking the unit with a tone generator. So the unit will be switching ON and OFF at the signal frequency.
SG

#### zirconx

Joined Mar 10, 2010
97
If the oscillation is fast enough you would not notice any flickering. You really need to look at the output with a scope.
Edit: You are checking the unit with a tone generator. So the unit will be switching ON and OFF at the signal frequency.
SG
Hmm it was a 600hz tone, you think the unit might be switching on and off at that frequency? I also tried blowing into the mic and got the same result.

This $43 "scope" would probably let me see what is happening, right? It has a 200Khz bandwidth. https://www.amazon.com/Quimat-Oscilloscope-BNC-Clip-Assembled-Finished/dp/B077D62Z1P #### sghioto Joined Dec 31, 2017 1,038 This$43 "scope" would probably let me see what is happening, right?
Yes, In fact I have that exact unit.
Hmm it was a 600hz tone, you think the unit might be switching on and off at that frequency?
Yes I do.
SG

#### Raymond Genovese

Joined Mar 5, 2016
1,658
The digital out should oscillate with a 600 Hz tone. If you are reading the output of the 393 digitally, it should be a series of lows and highs - that would be working normally. How do you think it should work? Are you saying that the pine never sees a low with the tone on?

#### KeithWalker

Joined Jul 10, 2017
796
I have tried it unconnected to the Pine64, the readings were (pretty much) the same.

I agree from the voltage readings it seems like it could be oscillating. I don't have a scope but the voltage readings look stable. They match what the audio-signal indicator LED is showing on the board - it's on solid, and the voltage seems to be a solid 1.8v, for example. I don't see the LED flickering.

I didn't try blocking the mic, but the LED audio-signal indicator seems to be working. In a quiet room the LED is off (and I read 3.3v). Then I turn on the tone generator and the LED goes solid, and the voltage drops to 1.8v.

If I had an analog input I could work with this, but the Pine64 doesn't have any.

Given this circuit (thatI found on one of the pages I linked earlier), is there anything I could check or do differently?
The comparator is not oscillating. The AC signal from the microphone is not detected so the comparator is being turned on and off by positive and negative half cycles of the amplified AC signal. That's not a very good design.

#### Raymond Genovese

Joined Mar 5, 2016
1,658
The problem I am having is the signal does not go low enough. When powered by 5v, I get a 5v signal when there is no sound. When there is sound (I'm using a tone generator app on my phone), the signal goes to 3v. I would expect it to go to 0v.

When powered by 3.3v (which is how I will use it on the Pine64), a LOW signal is only 1.8v. This is not low enough to trigger a LOW reading on my Pine64.
Can you please respond to this query @zirconx :

How are you determining that it is not triggering a low reading on your pine? Are reading the sound bit and it is NEVER 0 while the tone is being presented? Can you post the code fragment whereby you made the determination that it can't trigger a low reading?

I am asking because the sound bit should be changing from 1 to 0 and 1 to 0 and so on when you are presenting the tone. Are you saying that it NEVER goes low or assuming that it will not be read as a low because you see 1.8V on the meter?

I am saying that your pine should be reading a series of 1 and 0 in the presence of the tone if it is working correctly.

#### zirconx

Joined Mar 10, 2010
97
Can you please respond to this query @zirconx :

How are you determining that it is not triggering a low reading on your pine? Are reading the sound bit and it is NEVER 0 while the tone is being presented? Can you post the code fragment whereby you made the determination that it can't trigger a low reading?

I am asking because the sound bit should be changing from 1 to 0 and 1 to 0 and so on when you are presenting the tone. Are you saying that it NEVER goes low or assuming that it will not be read as a low because you see 1.8V on the meter?

I am saying that your pine should be reading a series of 1 and 0 in the presence of the tone if it is working correctly.
Indeed this is what was happening.

I have a software program written in nodejs that writes the pin value to console whenever the value changes. When I had a resistor hooked up between signal and ground, to bring the output lower, I did get oscillating 1's and 0's from my program. I thought that was because the voltage was near the threshold of LOW/HIGH, but perhaps it was just oscillating due to the tone. I will do some more testing with different sounds, I don't recall if I tried my blowing on the mic test at that point. My plan is to couple the mic (probably with a zip tie) to a water pipe and be able to tell when the shower/tub is on.

I know that when I had only the voltmeter hooked up, blowing on the mic caused the voltage to change from 3.3v to 1.8v. Which still doesn't seem right.

Yes, In fact I have that exact unit.

Yes I do.
SG
I'm also considering this one: https://www.amazon.com/SainSmart-Portable-Handheld-Digital-Oscilloscope/dp/B074QBQNB7

If I could find a decent deal on a "real" scope for close to that price I'd get it instead. I looked in the Marketplace here but didn't see anything.

#### Raymond Genovese

Joined Mar 5, 2016
1,658
So, the voltmeter will produce something like an average. With something like a 600 Hz square wave, that is as you would expect. After reading a little more carefully, I began to suspect that it was working just fine. They are more like a clap switch in a digital mode - just plain sound detection. You can get a little better with A to D and the analog out (but you still are sampling a wave), but if you do not have that, you will have to program your away around what you want to do.

#### zirconx

Joined Mar 10, 2010
97
Ok so after reading through all this, and doing some more testing, I think you are right, it's working correctly. I expected the sensor to go LOW and stay there while there was sound, but like you said, it probably doesn't work that way.

I am seeing oscillating 1's and 0's out of my program whenever there is sound above the threshold. So I think I can work with that in software - If the state hasn't changed for 1 second and it's HIGH, then the water is off. If the state has changed within the last second, then the water is on.

Thanks for all the help.

#### Raymond Genovese

Joined Mar 5, 2016
1,658
My plan is to couple the mic (probably with a zip tie) to a water pipe and be able to tell when the shower/tub is on.
You still may be able to do it, but you are going to have to sample the port over a period of time and get an average value. Do that for no water running and water running. How long to sample can be determined empirically. Compare the averages at different time periods - maybe a second or two is all you need. BUT, any increase in sound levels from "no water running" will look like "water running". Bang on the pipes and it will look like water running from the program's point of view. The power of the technique is limited.

#### zirconx

Joined Mar 10, 2010
97
Yea you are right, the ON state needs to be more than just has it changed in the last second, it needs to be has it continued to change for the last several seconds. That will omit banging on the pipes, etc.

My measurements don't need to be precise, +/- 10 seconds is fine.

#### Yaakov

Joined Jan 27, 2019
1,612

#### spinnaker

Joined Oct 29, 2009
7,835
Ok so after reading through all this, and doing some more testing, I think you are right, it's working correctly. I expected the sensor to go LOW and stay there while there was sound, but like you said, it probably doesn't work that way.

I am seeing oscillating 1's and 0's out of my program whenever there is sound above the threshold. So I think I can work with that in software - If the state hasn't changed for 1 second and it's HIGH, then the water is off. If the state has changed within the last second, then the water is on.

Thanks for all the help.
Probably represents a sound level. Is there a proper datasheet on this thing instead of someone's project that needs to be weeded through?

Wait based on the schematic (if it is correct) that does not make sense.

#### djsfantasi

Joined Apr 11, 2010
6,335
When using sound as a control signal (I.e. a digital output), there is additional processing beyond mere detection required.

Just detecting sound levels alone will oscillate. Plus, you have the issue of background noise.

First, I’d experiment to determine the level of background noise. Then, in the output stream, I’d use an op amp as a differential amplifier subtract out the background noise and keep the voltage differential between background and detected noise. This is how you’d eliminate the 3.3V you’re seeing when the water isn’t running. I’d wire the op amp to magnify the remaining signal to full scale.

Then, the signal IS going to vary. So I’d add an envelope follower to integrate the signal. Since you’re talking about a ten second window, you have a broad range of RC values to perform the integration.

#### djsfantasi

Joined Apr 11, 2010
6,335
When using sound as a control signal (I.e. a digital output), there is additional processing beyond mere detection required.

Just detecting sound levels alone will oscillate. Plus, you have the issue of background noise.

First, I’d experiment to determine the level of background noise. Then, in the output stream, I’d use an op amp as a differential amplifier subtract out the background noise and keep the voltage differential between background and detected noise. I’d wire the op amp to magnify the remaining signal to full scale.

Then, the signal IS going to vary. So I’d add an envelope follower

OR!

You’re reading this with an Arduinos, right?

Don’t use digitalRead(). Use analogRead() with an analog pin. Then, in your sketch, you can subtract the 3.3V or just ignore anything below 3.3V. Then, I’d take several measurements (with a slight delay) and average the results. This rolling average will produce a number at which sound is continuously detected.