Measuring 5V power using analog pins

I was working on a project with an Arduino UNO R3 and I was wondering whether it is safe to measure the Arduino's own 5V power output with it's Analog IN A2 pin. The limit for input to these pins is 5 volts I think so the 5V output should never exceed this amount.
Sorry if this is a dumb question.

A very short time ago the same question appeared in Forum. Search for it! Lots of work and replies there!

josh4000:
Sorry if this is a dumb question.

There are no dumb questions.

Yes, you can measure the voltage you create with one pin on another.

Klaus_K:
There are no dumb questions.

Yes, you can measure the voltage you create with one pin on another.

Yes, but when Vcc goes low the reference voltage will also go lower and the readings will not be accurate.
Check reply #1.

Beyond safety, you have to consider some things. analogRead(), by itself, uses VCC as a reference. So as the power supply voltage varies, so does the reference. So the reading won't reveal anything, it will always be maximum. Secondly, unless you use a voltage divider, you are at the high end of the measurement window, so even if you had a fixed reference of exactly 5.00000V, any VCC over 5V would just read maximum.

Make a voltage divider with 2 resistors to get measured voltage into the 1.1V range.
Then use the INTERNAL voltage reference instead of the default EXTERNAL voltage reference to make your readings.

CrossRoads:
Make a voltage divider with 2 resistors to get measured voltage into the 1.1V range.
Then use the INTERNAL voltage reference instead of the default EXTERNAL voltage reference to make your readings.

I don't remember the outcome of the previous question about this matter. It was quite extencive. Did it end like this? I'll try to find that thread.

There is a way to do it - Using the default Vcc ADC reference, you can read/measure the internal 1.1V reference (by reading internal registers).

For example, if Vcc is low 1.1V will read high and if Vcc is high 1.1V will read low. So, you can calculate Vcc from the "error".

The 1.1V reference isn't perfect (but it is super-stable) so you may have to make a calibration adjustment in software (which will be different for each ATmega chip).

I've never studied the internal registers, but [u]here[/u] is the code.

I wonder why OP wants to measure the 5volt rail of an Uno, which seems completely irrelevant to me.
Leo..

Here is a more readable version of the ATmega code referred to above, which uses the internal 1.1V reference to measure Vcc in mV. You need to separately calibrate the code for each processor chip. Very useful for battery powered projects!

// Read 1.1V reference against AVcc
// return battery voltage in millivolts
// must be individually calibrated for each CPU

unsigned int readVcc(void) {

  unsigned int result;

  // set the reference to Vcc and the measurement to the internal 1.1V reference

  ADMUX = (1<<REFS0) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
  delay(2); // Wait for Vref to settle

  ADCSRA |= (1<<ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // wait until done
  result = ADC;

  // second time is a charm

  ADCSRA |= (1<<ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // wait until done
  result = ADC;

  // calibrated for my Miniduino

  result = 1195700UL / (unsigned long)result; //example: 1126400 = 1.1*1024*1000
  return result; // Vcc in millivolts
}

You need to separately calibrate the code for each processor chip

I'd expect it to be about as accurate as normal Arduino analogRead() results even without calibration.
The datasheet says the internal ref is about +/- 10% from the nomonal 1.1V, but then USB voltage and/or most simple 5V regulators are also in about that range of accuracy...

Correction: To get the most accurate results, calibrate the code for each individual CPU chip.

westfw:
I'd expect it to be about as accurate as normal Arduino analogRead() results even without calibration.
The datasheet says the internal ref is about +/- 10% from the nomonal 1.1V, but then USB voltage and/or most simple 5V regulators are also in about that range of accuracy...

Every voltage regulator has some dependance on the supply voltage. Check that!

Op

This thread might be of interest to you.

Making accurate analog measurements and detecting power fails:

larryd:
Op

This thread might be of interest to you.

Making accurate analog measurements and detecting power fails:
https://forum.arduino.cc/index.php?topic=547472.0

It could have been this I aimed at in reply #1. Searching for info, doing some work, is hard. A ready made pill to swallow is more convienient.

Hummm

Does it seem like someone throws a pebble into the water, the school of fish chases after it, then with ‘baited breath’ wait for another pebble to be tossed into the water.

larryd:
Does it seem like someone throws a pebble into the water, the school of fish chases after it, then with ‘baited breath’ wait for another pebble to be tossed into the water.

No, baited breath comes from eating worms.

Railroader:
Yes, but when Vcc goes low the reference voltage will also go lower and the readings will not be accurate.

That depends on what you want to measure. If you are interested in the absolute value you are right, then you need a fixed voltage reference. But when you are interested in reading a variable resistor and you only want to know relative value e.g. position you are fine using Vcc as reference.

Klaus_K:
That depends on what you want to measure. If you are interested in the absolute value you are right, then you need a fixed voltage reference. But when you are interested in reading a variable resistor and you only want to know relative value e.g. position you are fine using Vcc as reference.

It might be like You say but OP is asking for absolute voltage readings as I understand. Check his very first post.

You CAN (on many arduino's anyway) measure the supply voltage with no external components.
However the simple way is to add a resistive divider. You do need to scale the input as although Vin would not exceed Vcc it would of necessity exceed the value of your voltage reference; and you cant use Vcc as a reference to measure Vcc.
Then you need to decide what voltage refernce to use depending on the precision and accuracy you desire, and the specific chip you are using.

http://www.skillbank.co.uk/arduino/measure-usb.htm