Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getting precise adc readings, originally from http://hacking.majenko.co.uk/node/57
- 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 = 1125300L / result;
- // Back-calculate AVcc in mV return result;
- }
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- Serial.println( readVcc(), DEC );
- delay(1000);
- }
- So now, using that, your ADC code could now look like this:
- unsigned int ADCValue;
- double Voltage;
- double Vcc;
- Vcc = readVcc()/1000.0;
- ADCValue = analogRead(0);
- Voltage = (ADCValue / 1023.0) * Vcc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement