# Can I read the battery level of a coin cell battery on the 3.3v in?

Hi there,

I have been looking to see if it is possible to read the battery level of a coin cell battery attached to the 3.3v pin. All I can find are guides to reading from the AO pin and I am wondering if this would even be possible or not using something like analogRead(3.3vpin) But I can see from reading the analogRead() documentation that I can only read from the A0 to A7 pins.

Is it hopeless for me to read the battery level of a coin cell on a 3.3v pin?

What prevents you from connecting a voltage divider to A0 and power it by your battery?

Regarding the measurement you need to make sure you have a voltage reference that is independent from Vcc changes. Many ADC have a bandgap reference available to counter that problem. You just need to figure out how it is setup.

I'm afraid I'm relatively new to Arduino and the hardware world so I am not fully following what you are saying here. I have only taken baby steps really into this field as of yet.

Steen_Petersen:
I'm afraid I'm relatively new to Arduino and the hardware world so I am not fully following what you are saying here. I have only taken baby steps really into this field as of yet.

No problem, maybe I can help you with a few baby steps.

You need to get the voltage from your battery to a pin that has a analog-to-digital converter (ADC). e.g AN0

If the voltage is within the range of the ADC you can simply connect it with a wire. If the voltage is higher than what the ADC can measure you need to divide the voltage. That is done via a voltage divider e.g. two resistors in series between the voltage and ground.

As you can see on the wiki page the ratio of the two resistors depends on the ratio of the maximum input voltage (your battery) and the maximum output voltage (the ADC maximum input voltage).

But this gives you only the ratio. You need to choose one resistor value. High value means lower current which is good for saving the battery. But the ADC has a capacitor that needs to be charged so at the same time a high value high means you need to give the ADC more time to charge the sampling capacitor. (Not an issue in your case because the battery voltage does not need to be measured very often).

Looking at the datasheet I think you do not need a voltage divider for a 3V coin cell. But for batteries with higher voltages you would.

Now regarding the reference. A SAR ADC (most ADC in MCU are SAR, Nordic called it SAADC in the datasheet) works by comparing the signal voltage step by step. First is it higher or lower than halve the reference voltage this give the first bit (MSB). Then it compares is it higher or lower than 1/4 or 3/4 the reference depending on bit 1. This gives bit 2. And this continuous depending the number of bits of the ADC. Look at the animations here.

Important is that the result is a comparison of your signal voltage to the reference voltage. If the reference voltage is your battery voltage aka Vcc the result will always be maximum. Even if the battery voltage goes down the battery signal voltage is equal to the battery voltage.

To avoid that you need a reference voltage that does not change when the battery voltage goes down. This is where a bandgap reference comes in. It is a circuit most ADCs have built in now. But you need to enable it, because in other cases you want to use Vcc as reference e.g. for measuring a potentiometer .

Have a look at the nRF52840 datasheet. Section 6.23.2 Reference voltage and gain settings.