Cannot get a simple circuit working

Hi guys.

I have now tried few projects involving sound and it was mostly failure even though I have no idea why. So this time I tried very simple circuit:

circuit

Then I have used this code to monitor the output

int maximum=0; //declare and initialize maximum as zero
int minimum=1023; //declare and initialize minimum as 1023
int track=0; //variable to keep track 
void setup()
{
  Serial.begin(9600); //set baud rate
}
void loop()
{
  //record the highest value recieved on A5
  if (analogRead(5)>maximum) maximum=analogRead(A5);
  //record the lowest value recieved on A5
  if (analogRead(5)<minimum) minimum=analogRead(A5);

  track++;//increase track by 1 after every iteration

  //display both the maximum and minimum value after 5 second
  //track is used to determine the time interval it takes for 
  //the program to display the maximum and minimum values
  //e.g. here i use 1000 so as to display the min and max values
  //after every 5 second
  if (track==5000)
  {
    Serial.print("Maximum:\t");
    Serial.println(maximum);
    Serial.print("Minimum:\t");
    Serial.println(minimum);
    track=0; //set back track to zero
  }
}

and when I got always the same reading I tried simplier monitoring but still nothing.

I have used this microphone and this resistor.

Please I am truly getting desperate.

Thank you in advance for any help.

Jane, when you post code you need to do it between “code” tags, not between “quote” tags.
Code tags are produced by the </> button in the “Reply” window.
Quote tags italicize the code, making it harder to read, and also make it harder to copy and paste into an IDE for modifying and verification.

Edit: Do you really want to do 2 analogue reads each time?
This might be better, and will take half the time:-

int temp = analogRead(5);
if(temp > maximum)
    maximum = temp;

And you probably need an amplifier on the condenser microphone.

Hi sorry, changed.

JaneDawwon: Hi sorry, changed.

Thanks for that. And I just edited my post with a couple of suggestions.

Thank you for your responce. I tried version with amplifier but it would not work either so I thought I am going to try something simple to see where the problem lies. According to this (https://electronpi.wordpress.com/2013/05/28/getting-going-with-an-electret-microphone-and-an-arduino/) tutorial even this simple thing should work.

JaneDawwon: Thank you for your responce. I tried version with amplifier but it would not work either so I thought I am going to try something simple to see where the problem lies. According to this (https://electronpi.wordpress.com/2013/05/28/getting-going-with-an-electret-microphone-and-an-arduino/) tutorial even this simple thing should work.

The other thing you need to do with an amplified signal is to make sure the input can't swing below 0V, or the input could be damaged. I'll take a look at your link now.

And totally by coincidence, I'm making a condenser mic circuit at the moment too, to use for a sound-trigger.

Edit: I just looked at that link. Your circuit should work for loud sounds, but amplification is really needed. I'm using a single-stage transistor pre-amp, centred on half the supply voltage, with a gain of 50. That feeds into a peak detector for my purpose as a trigger.

What are you actually trying to do? Record sound, or just detect it's presence?

Edit2: A coupling capacitor is a good idea, too, when amplifying the signal. I'm using an 0.1uF monolithic ceramic cap.

Thank you for that. Before this one I started making this project http://www.arduino-hacks.com/arduino-vu-meter-lm386electret-microphone-condenser/) with basically the same resolut so thats why I went for the simpler one. I have no idea whats wrong. Maybe the there is something wrong with the analog ins but I dont know how to test that.

When I take everything from the arduino. It shows exactly the same values - maxium 320, minum 0.

Again thanks for your help.

Edit: I would like to precicesly detect sound amplitude so as the tutorial suggests sort of VU meter.

Edit no. 2 - I am probably stupid but I have tried yelling at it (usually works, doesnt it :)) and it actually goes over the intial value so it probably works! The problem with the code is that it does not reset and for some reason it was always displaying 300. Now its on 13 and 13 and I can get it go higher. Anyway thank you for your help I am going to try adding the amp and other things and I hope Ill see where I made the intial mistake.

Once again THANK YOU!

JaneDawwon: Thank you for that. Before this one I started making this project http://www.arduino-hacks.com/arduino-vu-meter-lm386electret-microphone-condenser/) with basically the same resolut so thats why I went for the simpler one. I have no idea whats wrong. Maybe the there is something wrong with the analog ins but I dont know how to test that. Again thanks for your help.

You could do a simple test with a pot, one end to +5V, other end to GND, wiper to the analogue input pin then print the 'analogRead()' result to the serial monitor. You should get values from 0 to 1023 as you turn the pot.

First, with your current circuit, make sure you have the condenser mic connected the right way around. You can test which pin is which very easily. One will be connected to the mic's aluminium case. That's the negative pin, which should be connected to ground in your circuit.

Sadly I dont have anything to test it with yet but I am pretty sure I have the moc the right way around so I will just go ahead and add all those other things one by one.

May I just ask you one more thing?

Now I have noise always equal 14. I have a simple curcuit connecting LED to see if it reacts well and I am also monitoring it through the serial monitor.

For the analouge output I have this code " analogWrite(ledPin, VU / 4); " Could you tell me how to make it “analogWrite(ledPin, [VU / 4] - 14)” so that 14 noise wont be there?

Thank you so much.

JaneDawwon: Sadly I dont have anything to test it with yet but I am pretty sure I have the moc the right way around so I will just go ahead and add all those other things one by one.

May I just ask you one more thing?

Now I have noise always equal 14. I have a simple curcuit connecting LED to see if it reacts well and I am also monitoring it through the serial monitor.

For the analouge output I have this code " analogWrite(ledPin, VU / 4); " Could you tell me how to make it "analogWrite(ledPin, [VU / 4] - 14)" so that 14 noise wont be there?

Thank you so much.

So you're saying that it's working now? Reading back over your last couple of posts you've left me a bit confused. (It's after 1am here, well past my bedtime and I'm very tired, so can't help a lot at the moment.)

The problem with subtracting 14 is that if it's truly noise it won't always be 14, so you could end up with a negative value. But if you must do it, you do it before dividing by 4.

analogWrite(ledPin,(VU-14)/4);

And are you sure it's "noise" and not just a DC offset? Try a coupling cap between the condenser mic output and the analogue pin. 0.1uF should be fine.

Anyway, as I say, I'm way too tired to think clearly just now, and could too easily overlook things, so I'm off to bed.

Hi thank you for your replies. It does seem to work and those 14 points arent that big of a deal. The problem is again when I try to go further to add the op amp from the tutorial here (https://electronpi.wordpress.com/2013/05/28/next-step-op-amp/) I once again get meaningless value that does not change.

I am not using the LM358N tho so maybe thats the problem (I am using LM386 mentioned in different VU tutorial.)

Well I will retire as well today and I will try again tommorrow.

Thank you again for your kind guidence and good night!

EDIT: How can I tell if something is just a DC Offset? I had this problem before but when I played some sound the sound dipped bellow this "noise floor". Is that the same thing?

I just measured the DC offset of my electret mic, with a 10K pullup resistor, and it's 3.46V. That allows the signal a good swing above and below the DC offset without any clipping.

Removing the DC offset altogether by capacitive coupling to 0V would mean that the signal would swing above and below 0V, which you probably don't want in a single-supply circuit. Ideally you probably want to reference the signal to 1/2 the supply voltage, or to clip the negative swing and work with the signal's positive peaks. I know virtually nothing about VU meters, but that seems to be the best way to accomplish your goal of driving a solenoid as a VU meter.

I'm surprised that 'analogRead()' gives you a standing value as low as 14 from the condenser mic. Mine would give a value of a little over 700 from 3.46V, then the value would swing up and down around that value with sound input.

Anyway, as I say, I know very little about VU meters, so might be on the wrong track, so I'll leave it to people more knowledgable on the subject.

And I'm not sure that it was wise to start yet another thread on this subject. You should have continued with the thread(s) you started the other day. Now people have to look at several threads to get the full picture of what you're trying to do - driving a solenoid (as a VU meter) with an Arduino and electret mic for sound input.

Hi, thank you I guess you are right about another thread but they usually die pretty soon and this was in a way different project. Anyway thank you very much for your help I am going to look into all your suggestions.