long walk off a short pier!!!

I configured my arduino for the poor man’s voltmeter using code in the playground with limited success and need help to figure this out. I have a 10k resistor from the 5V Vin on the arduino going to analog0 input and another 10k resistor going from analog0 input to ground. According to the notes for this voltmeter in the playground this should work and indeed it does. Once I bring up the serial monitor it consistently shows 5V. If I change the resistor from the 5V to 3.3V it shows up in the serial monitor as well. However, if I hook up a 1.5V or 9V battery instead of using arduino’s output, the serial monitor shows random reading’s from 0.2V to 10.0V??? Also, the readings change all the time. In other words, reading 1 shows 1.2V, reading 2 shows 10.0V 5 seconds later, reading 3 shows 6.2V 5 seconds later, reading 4 shows 4.3V 5 seconds later, etc…If I hook up a small 10V solar cel the same thing happens. It’s only when I use the output from my arduino that the readings are correct and consistent. It is my goal to be able to read the voltage from my solar cel via the arduino. Please help me to see the error of my ways.

Thanks,

Here is the code I am using

int ledPin = 13;
int inputVoltagePin = 0;

void setup(){
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}

void loop(){
// read voltage value
int voltage=analogRead(inputVoltagePin);
int valueVolts=voltage/102;
int valueHundrethsOfMilliVolts=((voltage % 102)*10)/102;
// send formated value to serial com port
Serial.print(valueVolts);
Serial.print(’.’);
Serial.print(valueHundrethsOfMilliVolts);
Serial.println(‘V’);
// flash volts
for(int i=0;i<valueVolts;i++){
digitalWrite(ledPin,HIGH);
delay(500);
digitalWrite(ledPin,LOW);
delay(500);
}
delay(1000);
// flash hundreths of millivolts
for(int i=0;i<valueHundrethsOfMilliVolts;i++){
digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(500);
}
// pause between readings
delay(5000);
}

However, if I hook up a 1.5V or 9V battery instead of using arduino's output, the serial monitor shows random reading's from 0.2V to 10.0V???

Did you connect the grounds (0V) together?

reading 2 shows 10.0V 5 seconds later

On second thoughts, have you checked your arithmetic?

An analogRead can't return a value greater than 1023.

Did you connect the grounds (0V) together?

Nope…but after I did, everything worked fine. Thanks!

On second thoughts, have you checked your arithmetic?
An analogRead can’t return a value greater than 1023.

I’m such a newbie at this stuff that I am not sure what you mean. I know that there is a limit of some kind on what the analogRead can return and 1023 sounds familiar. I definitely saw 10.0 come up several times though.