Go Down

Topic: KY 037 floating output? (Read 589 times) previous topic - next topic

radimvansa

Hi, as my first Arduino project I am trying to detect a simple melody. Therefore I bought UNO R3 (CH340G) and KY 037 sensor (red one with 4 pins, manufacturer HESAI), and now I am trying to get some basic input. I've already read some tutorials and I see that I need to build a pre-amp, but I have trouble getting anything out of that so ATM I'd like to limit points of failure.

I've tried both analog input (A0 connected to A0 on UNO) and digital with threshold, but to no avail. When I use analog read example with plotter I can see that the readings start around 500 and quickly drop to about 280, with some oscilation (about 10 units). Digital read gives me only LOW signal, no matter how I turn the pot on the sensor.

There are two LEDs on the sensor; one is always on as it should signal VCC and GND are connected. When I set the pot too high (turn clockwise - multimeter shows me that I get to maximum at about 70kOhm while the pot should be 100k) the second led turns on, when I get it low it turns off. At about 6-8kOhm the LED faintly blinks when I clasp hands, does not react to whistle or anything better. Okay then, but when reading the digital pin (D0) I don't get anything?

To see if my setup is correct, I've also set up a simple voltage divider using two 10kOhm resistors, and connected the analog pin in between them. Multimeter reads 4.5 volts between VCC and GND (hey, is my USB cable too long? The voltage regulator on board should handle it, shouldn't it?) and 2.25 on the spot where I connected the A0, but when I plot the voltage, I get back to values at 280-290 (while I expect 512 or so). When I pull off some of the resistors I can see a jump by 30 up/down but then it returns to the original value in a couple of seconds.

What am I doing wrong? Btw. I use the GND pin next to digital pin 13 if that makes any difference and 5V in the middle of the power row. I've also tried to use different analog pins but with no difference

Thanks for your hints.

DVDdoug

Quote
To see if my setup is correct, I've also set up a simple voltage divider using two 10kOhm resistors, and connected the analog pin in between them. Multimeter reads 4.5 volts between VCC and GND (hey, is my USB cable too long? The voltage regulator on board should handle it, shouldn't it?) and 2.25 on the spot where I connected the A0, but when I plot the voltage, I get back to values at 280-290 (while I expect 512 or so).
The weird thing is the microphone board was reading correctly at about 500.   Did you check that voltage with your meter?   

And, you are measuring 2.25V referenced to the Arduino ground, right?   

Why is Vcc low?   What are you using for a power supply?  I think you're OK at 4.5V, and apparently your Arduino is running, but that's lower than I'd expect.

Quote
When I set the pot too high (turn clockwise - multimeter shows me that I get to maximum at about 70kOhm while the pot should be 100k) the second led turns on, when I get it low it turns off. At about 6-8kOhm the LED faintly blinks when I clasp hands, does not react to whistle or anything better.
In-circuit you may not get an accurate measurement, and without a schematic I don't know if higher resistance is more gain or less gain.   And, there are 3 terminals on a pot so it depends on which ones you measure.

Quote
I've already read some tutorials and I see that I need to build a pre-amp,
I'm pretty sure the board has a preamp.  

Quote
the LED faintly blinks when I clasp hands, does not react to whistle or anything better.
You are "sampling" the input so depending on how fast you are sampling and how you are reading/compiling the samples you might "miss" a hand-clap.   Try some more-continuous loud sounds.

With a continuous tone you should get "random" readings (from the analog output) centered around 512 (or centered around whatever bias you have).   Louder sounds should deviate farther above & below the bias.   But, it's a "wave" so it passes-through zero (ignoring the bias) twice per cycle and the readings will appear random (within limits determined by the loudness & amplification).


Quote
I've also set up a simple voltage divider using two 10kOhm resistors, and connected the analog pin in between them.
I just built one of those yesterday (to bias audio input).  I didn't bother measuring the voltage but the ADC reads 510.   (I think I used 5% resistors so it could have been worse.)

DVDdoug

#2
Sep 12, 2018, 05:10 am Last Edit: Sep 12, 2018, 05:12 am by DVDdoug
Since I'm starting a new audio project I made a little test program.   It may be of some help to you.    It takes 1000 readings, finds the minimum, maximum, and average, then loops again.

I'm using the usual voltage divider + capacitor circuit (no microphone board) and I'm connected to the headphone output from my laptop.  I'm playing music with the volume set to maximum.

The average is reading between 509 & 510 (close to the 512 ideal).   With no signal I'm getting 509-510 for all 3 values (as expected).    With music playing I'm occasionally getting maximums of more than 600 and minimums of  less than 400. 

Code: [Select]
// ReadAnalogAverage
// For audio input testing
// Prints min, max, and average to the serial monitor
// Should work with a line-level or headphone-level signal
// Typically the input is biased at Vcc/2 for a reading of ~512 with no signal
// Reads input A0

// Global Variables
int Min;
int Max;
int Analog;   
unsigned long Sum;
unsigned long Average;    //Should be equal to the bias.
 
void setup()
{
  Serial.begin(9600);
  delay(100);
}
 
//Main Loop
void loop()
{
Analog;  //Initilize/reset to expected value every time before starting for-loop
Min = 1023;     //Initilize/reset to limit
Max = 0;        //Initilize/reset to limit
Sum = 0;        //Initialize/reset

//Take 1000 readings, find min, max, and average.  This loop takes about 100ms.
for (int i = 0; i < 1000; i++)
{
  Analog = analogRead(A0);

  Sum = Sum + Analog;   //Sum for averaging
 
  if (Analog < Min)
    Min = Analog;

  if (Analog > Max)
    Max = Analog;       
}

Average = (Sum/1000);
         
// print results
Serial.print ( " Min = ");
Serial.print (Min);
Serial.print ( " Max = ");
Serial.print (Max);

Serial.print (" Average = ");
Serial.println (Average);

//  delay(500);    //Optional delay for readability
}  //End

Grumpy_Mike

Quote
as my first Arduino project I am trying to detect a simple melody.
Do you mean just detect when there is a sound or detect it is a melody, or detect it is a specific melody?

The first is easy, the second very tricky, the third impossible on any Arduino class of processor.

radimvansa

The weird thing is the microphone board was reading correctly at about 500.   Did you check that voltage with your meter?   
I don't have an osciloscope and I thought that meter would get mostly noise with the oscilating signal. But it's actually rather below 500 - I wonder if there could be any interference from the serial port when I start reading it.

And, you are measuring 2.25V referenced to the Arduino ground, right?   
Yes - well the difference between both VCC and ground should be equal with equal resistors.

Why is Vcc low?   What are you using for a power supply?  I think you're OK at 4.5V, and apparently your Arduino is running, but that's lower than I'd expect.
I power it only from USB right now. There is a hub and the cable is about 2 m long, so some voltage drop is to be expected. When I pulled the mic from breadboard it went to 4.6V.

In-circuit you may not get an accurate measurement, and without a schematic I don't know if higher resistance is more gain or less gain.   And, there are 3 terminals on a pot so it depends on which ones you measure.
I'm pretty sure the board has a preamp.   
I've found a schematic here, so not sure about the authenticity: https://forum.arduino.cc/index.php?action=dlattach;topic=437492.0;attach=188222

The pot has two pins wired to VCC which agrees with my readings. There's no pre-amp, the analog output goes just through one resistor so it's not even biased.

You are "sampling" the input so depending on how fast you are sampling and how you are reading/compiling the samples you might "miss" a hand-clap.   Try some more-continuous loud sounds.
I've tried whistling quite close to the mic but that did not show anything, the built-in led did not blink. I am sampling the digital output without any delay (except the code to print to serial ofc). The strange thing is that I found some tutorials and example codes that did not have this kind of trouble.

radimvansa

#5
Sep 12, 2018, 09:35 am Last Edit: Sep 12, 2018, 09:37 am by radimvansa
Do you mean just detect when there is a sound or detect it is a melody, or detect it is a specific melody?

The first is easy, the second very tricky, the third impossible on any Arduino class of processor.
Ouch, the third one - so am I out of luck? I've found that there are FFT/FHT libraries for Arduino, so 'reading tones' should be possible. So reading tones to a buffer, normalizing and then some primitive matching - is that too much? Where's the catch?

Grumpy_Mike

The catch is reading tones is difficult with a FFT due to all the harmonics, and the results are ambiguous. It takes time to get the samples in and then do the FFT so you do not get a continuous stream of data but an intermittent one.

Down load the free application called Audacity this will run on your computer. With it you can take audio samples and plot the FFT graphically. Look at this and you will see you don't stand a hope in hell recognising tones let alone tunes.

slipstick

If your melody was played entirely in pure sine waves, so single frequencies, you might get somewhere near with some effort. But with any normal instrumentation with all its complex harmonics there is nowhere near enough computing power in any Arduino.

Steve

radimvansa

Hmm, so I need to rethink the project. It was meant to be a present for my 3y daughter - a singing flower that can recognize her singing the song https://youtu.be/fMWSRl_m08A?t=22 and play it back (hey the original on youtube sounds like Arduino, though it's from 1952, doesn't it? :)). + maybe a couple of other children melodies.

So I need to base the detection just on amplitude, not frequency, right? (+ other sensors, I have planned to add PIR sensor and also humidity sensor to see when the plant gets watered).

I just got a new Nano, so I'll try if I am getting weird analog readings there as well.

Grumpy_Mike

Quote
I just got a new Nano, so I'll try if I am getting weird analog readings there as well.
You should get exactly the same results on a Nano as you did on an Arduino. They are both the same processor, just a different IC package.

radimvansa

You should get exactly the same results on a Nano as you did on an Arduino. They are both the same processor, just a different IC package.
And I did :-/ I was hoping that the board was faulty in some way, but apparently I am just doing something wrong. I've also tried the potential divider with 1k resistors (just to be sure) but no difference...

The only thing that could be wrong my attention is the low voltage I am getting - with Nano it's now 4.3V, when I connect it directly to laptop (without some extenders) it gets 4.6V. I'll try some external power in case this makes a difference...

Grumpy_Mike

#11
Sep 14, 2018, 11:03 am Last Edit: Sep 14, 2018, 11:04 am by Grumpy_Mike
Quote
The only thing that could be wrong my attention is the low voltage I am getting
No.

You haven't actually posted the code, nor the results you are getting. My guess is you are getting what you should do.

Post the code and say what it does and what you expect it to do.

radimvansa

Okay, I finally found the issue - the jumper wire I've used to connect to A0 was faulty (not conducting at all). Stupid me for not checking that part before.

Thanks for your help, guys...

Go Up