The Mini Ultra Pro was designed to be ultra low power when operating from the Li-Ion or Li-Polymer battery. Starting from V3 of the Mini Ultra Pro, we have added a simple battery voltage monitoring on pin A5. A simple resistor divider circuit (using a pair of high resistance value to reduce current consumption) with a decoupling capacitor (that also helps to hold the voltage as the internal ADC circuitry on the microcontroller has a limited input impedance range) is used.
The voltage divider will scale the maximum voltage of 4.2V of battery down to just below 3.3V to fit into the microcontroller ADC input voltage range.
VADC = (R16/(R15+R16))*VBAT VBAT = VADC*((R15+R16)/R16) VBAT = VADC*((3.3M+1M)/1M) VBAT = VADC*4.3 V
The following will convert the raw ADC voltage on pin A5 into the battery voltage. We perform some averaging here that basically increases the resolution of our reading.
int adcReading; unsigned char counter; float batteryVoltage; adcReading = analogRead(A5); // Discard inaccurate 1st reading adcReading = 0; // Perform averaging for (counter = 10; counter > 0; counter--) { adcReading += analogRead(A5); } adcReading = adcReading / 10; // Convert to volts batteryVoltage = adcReading * (4.3 / 1023.0);
Do that note that if no valid battery is inserted, the reading will be a random value.