ARDUINO ANALOG INPUT PROBLEM

hi, i am fairly new to this whole Arduino thing. i am trying to sense a voltage using an analog input on the Arduino Uno. I want to sense a 5V rail(for now). I have a 3.3k resistor which is connected to the 5V rail, then a 1k resistor with a .1uf cap in parallel with the 1k for a little filtering to ground. the problem i am having is that the sensed voltage seems “stuck” when I convert it to a voltage. my sketch does the following:

Vsense = sense(Vcc_railPin); // read rail voltage

voltsnow = ((Vsense*5)/1024)*4.33; //convert counts to volts

Vcc_railPin is the analog input A1. sense is a function that reads the input 5 times and averages the 5 samples.

what is happening is: when i run off the usb the rail is 4.940V, the sensed voltage is 1.123V(read with meter), the output to the LCD displays 4.33V.

when i connect to a supply which is fed to a 5V regulator, the rail is 5.01V, the sensed voltage is 1.142(read with meter), the output to the LCD still displays 4.33V! no change even though the rail has gone up.

Vsense is initialized as an int, the voltsnow is initialized as float.

Aref is not connected to anything so the Aref should be the 5V rail?

i am displaying the sensed voltage to 3 decimal places. i can’t figure out why the displayed voltage does not change even though the rail has gone up by 70mv. i thought since the Arduino is 10 bit that i would be accurate to ~5mv so the display should be accurate to 5mV.

what am i missing here?

Looks like you are using the Vdd to the processor as the ADC’s Reference voltage. When the Vdd (rail) changes the reference voltage to the ADC also changes therefore the ADC will always give the same reading when Vdd changes.

The measure the processors Vdd you need to supply an independent reference voltage the the ADC. Most likely there is a pin on the Arduino 's processor that can be configured as Vref input. Feed this with a regulated voltage. See the processor data sheet for details.

My ADC tutorial.

[<LINK_TEXT text=“https://sites.google.com/site/qeewiki/b … alog-input”>https://sites.google.com/site/qeewiki/books/avr-guide/analog-input</LINK_TEXT>

Cheers

Q](https://sites.google.com/site/qeewiki/books/avr-guide/analog-input)

Vsense=0;

for(int i=0;i<5;i++){

Vsense+ = sense(Vcc_railPin); // read rail voltage and accumulate 5times

}

voltsnow = ((Vsense)/1024)*4.33; //convert counts to volts

Hope it is what you want to do.