Sound Sensor is not working

Hello,

I am new to this forum and I hope that I am posting this in the right spot :).

I am currently working on a VU-Meter using the Esp32 Dev Kit V4 from Az-Delivery. Power supply, LEDs etc are all working well, but I ran into trouble with my microphone.

If I understand correctly, I can not send hyperlinks as a new user and I am very limited with pictures, so I will just say that I bought the "5 Pack High Sensitivity Microphone Sensor Detection Module" (what a name) from Youmile from Amazon.

I hooked up the sensor this way: ESP 32 5V -> Sensor VCC; ESP32 GND -> Sensor GND; Sensor Out -> ESP32 GPIO 33. The ESP32 is powered via the USB-Port. This is just for testing without the LEDs.

My Code is basically just the following:

#define micPin 33

void setup ()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(analogRead(micPin));
}

Depending on how I set the potentiometer on the sound module I get a reading of around 320 or 4095. Talking makes it jump to the other extreme.

I am completely new to these sound sensors, so I am a bit confused. I tried some Code to get Amplitudes from digital signals, but the sensor from that example spat out 1s and 0s with the code I posted.

My plan is/was to calculate the number of pixels which light up from the analogread value, but that obviously does not work.

Can you guys help me out here? It would be greatly appreciated.

Nils

PS: I am sure that this is not the best way to post Code and I apologize upfront. I am sure you can give me some hints to do it correctly.

Also: I kinda thought that I logged into a German forum, but I am writing this in English since the entire page is English too. Should you guys be German I apologize dearly for the inconveniance. If you are not I apologize dearly for my bad English :).

Sooo, I just noticed that I am stupid. Maybe I should use digitalRead and not analogRead for a digital sound sensor :upside_down_face:. I popped this change into my code and now I am only getting 0s. Changing the potentiometer settings does not appear to be doing anything.

Do you have a link to the sound sensor? Are there any specs?

Some sound sensors have a binary-digital output that goes high when you're above the threshold and zero when you're below the threshold. That kind won't work as a VU meter.

Some put-out a varying DC voltage relative to the loudness.

Others put-out a biased audio signal (i.e. a voltage "wave" which would be negative half the time if not biased).

1 Like

Let's see if I can post a link :slight_smile:

Yes, that sensor only tells you you've reached a certain loudness or not and it puts-out a binary 1 or zero so it's useless as a VU meter. :frowning:

...Or since you apparently have 5 of them, you could adjust all 5 differently and connect each one to an LED to make a 5-LED VU meter without the Arduino! :smiley: :smiley:

This SparkFun board has all 3 of the outputs I mentioned, and it's well documented. The Envelope output is the easiest to use in your VU meter application, although the audio output can also be used.

With the audio output you have to do some "processing" such as finding the peak or the moving-average* because the waveform voltage changes too quickly.

  • Actually, the true-average will be equal to the bias, or equal to zero if you subtract-out the bias. So you have to subtract-out the bias and then find the average of the positive values, or the average of the absolute values.
1 Like

What a bummer. I didn't even think about the possibility of the sensor only putting out a digital signal. I should really start reading the datasheet before buying stuff ^^.
Thanks a lot for your idea, but I already have the W2812b LEDs and the ESP32, so I'll keep trying :).
I thought about using a 3-pin 3,5mm terminal block. I actually ordered the block a few days back and it should come tomorrow, so thats a good thing.
Can I just hook the left and right channel up to different GPIO pins and run an analogRead or do I have to be on the lookout for anything special (apart from using the right pins)? And what are the max Values when doing so (need that to calculate the amount of pixels and sensitivity)?
I cut the LED stripe anyway and I could put the the 2 pieces next to each other to show the left and right channel.

Thank you again for taking the time to answer my questions :).

Nils

The maximum value from an analogRead is 1023 on a Uno and nano, as they have a 10 bit A/D converter.

Reading two channels is a simple as using another pin but the unit will run at half the speed and thus limit the top frequency you can detect to half what you can using only one channel.

Will this have a noticable effect on the VU-meter?

Sorry to bother you again, but since I cant do anything with the 3,5mm jack right now, I decided to test my button. I want to use it to switch between the VU-meter mode and normal light effects.

My code is as follows:

#define ButtonPin 32

void loop()
{
Serial.begin(9600);
Serial.println(digitalRead(ButtonPin));
}

The serial monitor doesnt write anything though. Shouldnt it be all 1s and 0s? When I connect the wires directly without using the button nothing happens either. I tried a different GPIO pin and turned the button 90 degrees.

This is how I hooked up the button to the ESP32.

My first thought was that the button is defective, but that doesnt really make sense because the serial monitor should still put out something, right?

That code should not even compile as it doesn't have a setup function.
So I doubt it is actually running.
Also serial begin should be done only once, that is what the setup function is for.
Try this and remember to but all the code you post in code tags.

#define ButtonPin 32
void setup()
{
    Serial.begin(9600);
   while( !Serial) delay(20); // you need this on your processor in order for the serial line to be established
   pinMode(ButtonPin , INPUT); // pins default to an input but it is good to specifically do this
}

void loop()
{
    Serial.println(digitalRead(ButtonPin));
    delay(800); // to stop the serial monitor from being overloaded
}

The // in the code means the rest of the line is a comment.

A better way of wiring up the button is between input and ground, and enabling the internal pull up resistor in the pinMode call, so you don't need a resistor.

1 Like

Works like a charm. You are my hero, thx a lot :). Love the profile pick btw

1 Like

One more thing. I think a good way to do my project would be to make the button code the void loop and have the vu-meter and different light effects as functions that I can put into the void loop.

Ill just post a few snippets of the code and hopefully get the code tags right.

void loop() 
{ 
  ButtonStatus = digitalRead(ButtonPin);          
  
  if (ButtonStatus != PreStatus)                // was button pressed
  {
    if (ButtonStatus == 1)
    {
      ButtonCount ++;                           //yes? counter goes up
    }
  }

  if (ButtonCount % 2 == 0)                     // counter devideable by 2?
  {
    //ButtonCount = 0;                           
    VU_Meter();                                 // vu-meter function is used
  }

  else if (ButtonCount % 3 == 0)
  {
    Lampe_1();                                  // first light effect
    ButtonCount = 0;
  }

  else
  {
    Lampe_2();                                  // 2nd light effect function
  }

}

I declared the variables up top, didnt want to post the whole thing. The functions for the vu-meter and the light effects are below this. Example:

void VU_Meter()
{
  int i = 0;
  
  Volume_L = analogRead(Input_L);
  Volume_R = analogRead(Input_R);

 .
 .
 .
}

just as an example. Im assuming that I have to declare the functions at the top somehow? The way it is now, they are below the void loop and I am assuming the loop doesnt know that these funtions are a thing.
I really hope that Im not overstepping with all the questions, but I am in a certain flow right now and having fun :)...

In a normal C compiler you would have to, but in an Arduino environment, like the IDE, it does that automatically and hides it from you, so there is no need for you to do this.

1 Like

Ah ok that explains why I cpuldnt find anything regarding this. Thanks again :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.