analogRead will not reach 512

Hi,

i set up a simple circuit which reads from analog and outputs the value to some LEDs. It all works, but the highest the value reaches is 500, even when Vin and the analog pin are tied together.

I have tried other analog pins and i get the same result.

anyone know why this is?

It all works, but the highest the value reaches is 500, even when Vin and the analog pin are tied together.

You may damage your Arduino by connecting an analog input to Vin. In the common configuration the highest voltage that may be applied to an analog input pin is 5V. Vin is usually at least 2V higher than 5V, in many situations it reaches 9V, much to high for the ADC.

So tell us or better show us how you have wired it up and what code you are using. Otherwise we are just guessing what is wrong. You may have already damaged all your pins by connecting them to Vin.

Thanks for the warning: i'm using a nano and was told to put anything i wanted at 5v to be on Vin.

i have now changed that and it seems to be working (though its hard to tell as my potentiometer is of questionable quality)

cant find any signs of damage on any pins, so i think i'm alright :slight_smile:

Your original problem, sounds like you were not applying voltage to Vin, but it was leaking back some from your other 5v source (probably USB). When it leaked back, it did not get quite up to the 5v, so your readings would not show full.

What power source were you using?

USB power.

not sure if its related but i set up a circuit to show me the current analogRead value from a potentiometer using 8 LED's and a shift register, but it doesnt seem to be working.

//Pin connected to ST_CP of 74HC595
int latchPin = 3;
//Pin connected to SH_CP of 74HC595
int clockPin = 4;
//Pin connected to DS of 74HC595
int dataPin = 2;
int potIn = 0;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  //count up routine
    potIn = analogRead(1);
    //ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, potIn);   
    //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(latchPin, HIGH);
  
}

this is with the middle pin of the Potentiometer on A1, and the other two pins on either gnd or 5V.

the problem i see is that the value reaches 1023 4 times as i rotate my potentiometer, at exact intervals, it is 0 when turned to gnd and 1023 when at 5V

the problem i see is that the value reaches 1023 4 times as i rotate my potentiometer, at exact intervals, it is 0 when turned to gnd and 1023 when at 5V

I don't understand what you are doing.
The code looks like you are sending stuff out to an 8 bit shift register. That means 8 bits or values from 0 to 255. You are feeding it with 10 bits, values from 0 to 1023. So yes what you see is exactly right.

As Grumpy says, your 8 bits (led,s) can show a maximum of 256, so you could have never seen 1023.
Can you use your serial monitor to display such debugging info?

oh god

sorry

its been too long since i played with electronics: i totally thought 2^8 was 1024.

ooops :blush: