# How can I measure the supply voltage of batteris without a multimeter?

My system consists of two XBee S1s and a Raspberry Pi. I've attached a TMP36 sensor and a LDR to the first XBee S1 and transmit those infromations to the second XBee S1 via the ZigBee protocol. The second Xbee S1 is connected via USB adapter to the Raspberry Pi. My first XBee S1 is powered by batteris at 5V.

As the voltage given by the batteries decreases over time, I would like to have an indeication of the voltage supplied by the batteris in order to know when I should change them. Can you tell me how can I do that? My idea is to make a gauge with 4 LEDs attached to the Raspberry Pi. The problem I am facing is that I do not know how can I send the supply voltage via the Xbees(as the XBee 1 itself is powered by that battery).

PS: I don't want to use a multimeter every time I am wondering how much voltage is provided by the batteries.

If the first XBee has an analog input then use it to measure the battery voltage. simulate this circuit – Schematic created using CircuitLab

Figure 1. Battery voltage sense.

Create a potential divider to bring the maximum battery voltage below the maximum input voltage for the ADC.

You would then need to figure out the scaling factor and set the remote to control your gauge. This would be easy to achieve with a potentiometer on the analog in during setup.

You haven't specified which Xbee you have (there are lots), but IIRC all the 2.4GHz XBees have an onboard 10-bit ADC with several channels.

You'll have to check the reference voltage for your particular XBee, but I think they are typically set up with a 1.2V Vref, so you need to divide down the 0-5V from the battery to a 0-1.2V range (leave a little bit of wiggle room). Let's say the maximum voltage your batteries might reach is 6V, then you need a voltage divider to scale the voltage by 1.2V/6V = 0.2.

Also, keep in mind that the ADC input impedance is 10kΩ or greater, which isn't great, so you need to either design a voltage divider with significantly smaller resistor values, or (better) use an op-amp to buffer the divided-down voltage into the ADC input.

• Thank you for your answer. I am using XBees S1, their reference voltage is 5V. Can you please precise me how did you calculate the scaling factor? Thanks – traviata Mar 6 '16 at 10:29
• You really should link a datasheet, "XBees S1" isn't really unambiguous. Also, are you sure it's 5V? Most XBee's have a $V_{REF}$ max of $V_{DDAD} = V_{CC}$, which is typically 3.3V. Anyway, you calculate the voltage divider scaling factor by taking $V_{REF}/V_{IN(MAX)}$ (the reference voltage of the ADC divided by the largest voltage your battery might reach. – uint128_t Mar 6 '16 at 16:37