Go Down

Topic: Clever low voltage monitor (no external components) (Read 618 times) previous topic - next topic

hotshotharry

Jan 28, 2013, 11:15 am Last Edit: Jan 28, 2013, 11:27 am by hotshotharry Reason: 1
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

hotshotharry

#1
Jan 28, 2013, 11:17 am Last Edit: Jan 28, 2013, 11:27 am by hotshotharry Reason: 1
Just in case the link vanishes I have copied the code here

Code: [Select]


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);
}

dhenry


Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview