Go Down

Topic: Reading voltage from the Arduino board itself (Read 1 time) previous topic - next topic

torix

Hi all,

Just wondering if it is possible to read the current system voltage of the board itself. Are there any libraries for this? I'm experimenting with a Arduino Nano at the moment.


Best regards
  torix

dc42

Yes you can. Assuming you are using the default 5V analog reference, you can get the ADC to read the internal bandgap voltage reference. Looking at the code for analogRead, I believe that on the atmega328-based boards, you can so this by calling analogRead(28). The reading you get will be 1024 * (Vbg/Vcc) where Vbg is a fixed voltage for any particular chip, nominally 1.1V but possibly anywhere between 1.0V and 1.2V. Since Vbg is fixed, you can calculate Vcc from the reading.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

madepablo


dc42


I don´t know if it could help, but follow this topic:
http://forum.arduino.cc/index.php/topic,15629.0.html


The "tinkerkit secret voltmeter" linked to in that thread uses the same technique that I described, but using direct access to the ADC instead of analogRead.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

madepablo

Hi dc42,
I didn´t know. I am newby and i was only trying to contribute... In any case, may be by the use of this alternative method you could save one pin. I don´t know, as i said, i do not have so much experience on electronics ;-)
Cheers

LQVE


Yes you can. Assuming you are using the default 5V analog reference, you can get the ADC to read the internal bandgap voltage reference. Looking at the code for analogRead, I believe that on the atmega328-based boards, you can so this by calling analogRead(28). The reading you get will be 1024 * (Vbg/Vcc) where Vbg is a fixed voltage for any particular chip, nominally 1.1V but possibly anywhere between 1.0V and 1.2V. Since Vbg is fixed, you can calculate Vcc from the reading.


Thank you. It is interesting to know that the "pin" 28 is for the internal bandgap. Could you tell how to find the code for analogRead()?

dc42


Hi dc42,
I didn´t know. I am newby and i was only trying to contribute...


No worries, I wasn't trying to belittle your valuable contribution, just pointing out that the underlying mechanism was the same.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

dc42


Thank you. It is interesting to know that the "pin" 28 is for the internal bandgap. Could you tell how to find the code for analogRead()?


On my system, it's in C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\wiring-analog.c.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up