Voltage value

Hello,
I am working with Arduino UNO with a 6 volt battery from the power jack.
Do you think that is possible to read from some pin the voltage value and write it into the serial?
Thanks for the reply.

void setup ()
{
  Serial.begin (115200) ;   // or whatever baud rate
}

void loop ()
{
  float voltage = analogRead (0) * 5.0 / 1024 ;  // or whichever _analog_ pin
  Serial.print (voltage) ;
  Serial.println ("V") ;
  delay (1000) ;
}

Note with 6V to the jack the Arduino supply might be a tad below 5.0V - a multimeter can tell the true voltage.

Generally when powering from the jack you need at least 7.5V.

And there's a catch anytime you want Arduino to read it's own battery supply. If the voltage of the supply falls and therefore the voltage into the Arduino, then the reference voltage falls too so the analogRead will read too high. For instance if the input voltage, and therefore the analog ref, is at 4.8 then 4.8 will read at 1023. Battery full. But it really isn't.

If you want Arduino to measure it's own battery it's best to use the internal 1.1V reference voltage and use a resistor divider to take the battery voltage down to that level. That way, even when the battery voltage falls you still have a good constant 1.1V to compare to.

With a 6volt battery on the DC jack, the Uno is not getting the full 5volt supply.
The DC jack needs at least 6.7volt.
Better connect a battery to Vin. Then you gain the 0.7volt that is otherwise lost in the reverse protection diode.

Arduino is not able to measure a 6volt battery with default Aref.
As soon as the regulated supply drops below 5volt (battery <6volt), readings become unstable.

You can solve that by comparing the battery voltage to the internal 1.1volt Aref.
In software: Google Code Archive - Long-term storage for Google Code Project Hosting.
Or in hardware with a voltage divider that drops 6volt to 1volt, and read agains 1.1volt Aref.
analogReference() - Arduino Reference
Leo..