Pages: [1]   Go Down
Author Topic: Clever low voltage monitor (no external components)  (Read 595 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found this clever little snippet of code that will return the supply voltage for the arduino using no external components! Would be great for those lipo projects !!!

http://code.google.com/p/tinkerit/wiki/SecretVoltmeter
« Last Edit: January 28, 2013, 05:27:18 am by hotshotharry » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just in case the link vanishes I have copied the code here

Code:

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println( readVcc(), DEC );
  delay(1000);
}
« Last Edit: January 28, 2013, 05:27:35 am by hotshotharry » Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing new. It has been done for decades.
Logged

Pages: [1]   Go Up
Jump to: