Pages: [1]   Go Down
Author Topic: Reading voltage from the Arduino board itself  (Read 977 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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()?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Pages: [1]   Go Up
Jump to: