Analog input values

Hi everybody.

I have set up the following circuit seen on the image. My problem is that when i try to read the values on analog input A0, the serial monitor returns the pin value of A0, which in my case is 14. My arduino is a Arduino UNO.

I have tried all kinds of ways to define the analoginput, but with the same results.

The code i executing is this simple program:

#define soundpin A0               //  reads the power from the light sensor from Analog input 0
#define LED1 2                    //  4 Leds LED's on Digital output pins 3,4,5,6
#define LED2 3
#define LED3 4
#define LED4 5
 
int sound;
 
void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);
 
  // Provide power by using the analog inputs as normal digital pins.  
  pinMode(soundpin, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}
void loop()
{
      sound=analogRead(soundpin);   // this samples the sound constantly
      if((sound)>150)
        {
             digitalWrite(LED1,HIGH);   // set the LEDs on
             digitalWrite(LED2,HIGH);
             digitalWrite(LED3,HIGH);
             digitalWrite(LED4,HIGH);
        }  
        else if((sound)>100)
        {
             digitalWrite(LED1,HIGH);   // set the LED on
             digitalWrite(LED2,HIGH);
             digitalWrite(LED3,HIGH);
             digitalWrite(LED4,LOW);   // set the LED off
        }
        else if(sound>50)
        {
             digitalWrite(LED1,HIGH);   // set the LED on
             digitalWrite(LED2,HIGH);
             digitalWrite(LED3,LOW);   // set the LED off
             digitalWrite(LED4,LOW);
        }
         else if(sound>25)
        {
             digitalWrite(LED1,HIGH);   // set the LED on
             digitalWrite(LED2,LOW);   // set the LED off
             digitalWrite(LED3,LOW);
             digitalWrite(LED4,LOW);
        }
         else
        {
             digitalWrite(LED1,LOW);   // set the LEDs off
             digitalWrite(LED2,LOW);
             digitalWrite(LED3,LOW);
             digitalWrite(LED4,LOW);
        }
       
     Serial.println(sound);              //output for serial monitor
 
     delay(500);                                   // And a shot delay
}

Why is it that i don't get a value on the serial monitor equal to the volume my PC is outputting?

Thanks in advance, Lasy92.

See
http://forum.arduino.cc/index.php/topic,98852.0.html

Basically it looks like you are trying to make an envelope detector for the sound. If so that circuit is wrong, there should be a diode between the audio input and the pot and I would put something like a 10K in parallel with the capacitor.

i try to read the values on analog input A0, the serial monitor returns the pin value of A0, which in my case is 14.

I find that hard to believe with that software, if you put A1 does it return 15?

I find that hard to believe with that software, if you put A1 does it return 15?

Yes, actually it does... i thought it was pretty weird too.

Basically it looks like you are trying to make an envelope detector for the sound. If so that circuit is wrong, there should be a diode between the audio input and the pot and I would put something like a 10K in parallel with the capacitor.

And actually, currently not using a tripot, im using a 10k resistor instead.

I have changed the code.

This code prints 0 in serial monitor.

currently not using a tripot, im using a 10k resistor instead.

Surely you must be using two resistors because a single resistor can not replace a pot.

It is vital that you actually post what you have not what you hope to have.

Anyway comments still the same that is not how you make an envelope follower.

Let me have a guess, did you get that from the instructables web site, most projects on there are so crap in there implementation.

Let me have a guess, did you get that from the instructables web site, most projects on there are so crap in there implementation.

Yes i did...

But isn't a 10k trimpot just a variable resistor that goes up to 10k resistance? And replacing it by a 10k resistor would just be like have the trimpot at its max? :slight_smile:

But isn't a 10k trimpot just a variable resistor that goes up to 10k resistance?

No it is not.
It is a potential divider:-

Okay, that great! I got it to work, with a simple envelope follower, like you mentioned. I'm using a 10 microF capacitor and 10K resistor.

Is it any way possible to calculate the most ideal sizes of these components?

You have been a big help, i really appreciate it! :slight_smile:

Is it any way possible to calculate the most ideal sizes of these components?

without the diode the circuit is useless and is subjecting the arduino input to a negative voltage which could well damage it.

The capacitor and resistor for a filter and the time constant of that filter is given by multiplying the resistor value in ohms with the capacitor value in Farads. You need the time constant to be the period that you want to follow the audio with. I would aim for 0.25 second for a start. It depends on how responsive you want it to be.

Please do not use instructable circuits as they often can damage the arduino or the components they use. Mainly they are written by idiots who are 1000% smarter than the people who post comments on them.