Using internal\extenal reference when measuring voltage

Hi all,

I would like to measure a battery voltage (lithium 3.7v) using AREF pin as reference.

I saw those code examples-
when using internal (default) reference:

float ref_voltage = 5.0;
adc_value = analogRead(ANALOG_IN_PIN);
adc_voltage  = (adc_value * ref_voltage) / 1024.0; 

when using the AREF as reference:

float ref_voltage = 4.096;
analogReference(EXTERNAL);
adc_value = analogRead(ANALOG_IN_PIN);
adc_voltage  = (adc_value * ref_voltage) / 1024.0; 

My question is, by using the analogReference() function, we are already telling Arduino to use the reference voltage from the default \ AREF. if so, why all of the examples using explicitly the variable 'ref_voltage'?

doesnt the code supposed to look something like:

analogReference(EXTERNAL);
adc_voltage  = (adc_value * getReferenceVoltage()) / 1024.0; 

Thanks

There is no function getReferenceVoltage().

I know there is no such function.. im asking- why do we tell to Arduino to take external reference voltage and on the same time, give it explicitly- 4.095v
Instead of just take that value from AREF pin

Thanks

this is not the internal analog reference v's. The author is using the actual maximum measured volts of the input to determine the resolution of the analog reading.

1 Like

@dudir

If you choose the option EXTERNAL, then you must connect an external stable supply voltage from 1.1V to 5V at the AREF-pin of the UNO Board (Fig-1).
adc3280exterRef
Figure-1:

To what would the Arduino compare the external reference voltage so it can measure it? The whole point of the external reference is to have something that is independent of how the Arduino is powered. The power can fluctuate and that will influence the result if you would measure the reference voltage. The external reference is (supposed to be) very stable.

1 Like

The Arduino doesn't know the actual voltage of the INTERNAL (1.1 +/-0.1), EXTERNAL (whatever you connect to AREF), or DEFAULT (whatever is on the Vcc pin) voltage references. It needs that value for the conversion calculation. You have to supply that value to get accurate conversions from analog readings to voltage.

Are you connecting the AREF pin to a 4.096V voltage reference? Then you have to put that value in your sketch.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.