I am using the MKR NB1500
I am trying to read the Voltage of a 1.8 Ah Battery which is fully charged according to a Voltmeter showing 4.17 V.
I would have expected a rawADC reading of ~4096 but it stays somewhere around 3250.
I am using an Arduino MKR NB1500 which is only attached to the battery and the USB cable (PC). this is the code:
int rawADC;
void setup() {
Serial.begin(9600); // start Serial port with a baudrate of 9600bps
analogReference(AR_DEFAULT); // the upper value of ADC is set to 3.3V
analogReadResolution(12); // this will give us 4096 (2^12) levels on the ADC
}
void loop()
{
rawADC = analogRead(ADC_BATTERY); //the value obtained directly at the PB09 input pin
Serial.println(rawADC);
delay(2000);
}
Output:
18:18:58.403 -> 3242
18:19:00.429 -> 3246
18:19:02.427 -> 3248
18:19:04.434 -> 3243
Any idea what I am doing wrong?
Impossible to answer without an schematic showing ALL connections and component values.
So you put over 4V in an adc with reference of 3.3v and expect it to read max?
You might also expect the adc to get damaged...
You will need a voltage divider.
HI, @gallus1234
Please read: operating voltage is 3.3V
The microcontroller on the this board runs at 3.3V, which means that you must never apply more than 3.3V to its Digital and Analog pins. Care must be taken when connecting sensors and actuators to assure that this limit of 3.3V is never exceeded. Connecting higher voltage signals, like the 5V commonly used with the other Arduino boards, will damage the board.
Thanks.. Tom...
![]()
What is your AREF voltage?
Hi @gallus1234 ,
I've used the following on a couple of projects.
See -Battery Status Monitoring System
I removed lines 17, 28 - 42 to remove the IOT code & it worked reasonably well. Although it will not work as well as using a dedicated LiIon Fuel Gauge and Battery Monitor
HTH?
@gallus1234, stop cross-posting. Threads merged.
@Paul_KD7HB you find the full schematic here (click resources and at the bottom you find the interactive viewer) schematic
and the important part below (do not know how to upload the full schematic). There is Voltage divider, before the PB09 Input, that is why this should work:
@build_1971 & @TomGeorge there is a voltage divider from battery to ADC. See the schematic above
That is fine, but the problem is in your project, so a schematic of how you have done it may explain the problem.
Make the resistors of your divider 100 times smaller... this is asking for disturbances.
And change the ratio such that you expect 90% reading at full charged battery.
@Paul_KD7HB pure Arduino MKR NB1500 nothing else attached except the battery to the jst plug. I actually wanted to do this tutorial for the mkr wifi battery tutorial but even though I changed the resistors according to the schematic above, I did not get the expected result. That is why I debbuged every line, and recogniced the ADC read is already different to what I expect.
@build_1971 that is the buit-in divider of the board, I asume somebody has given it some thought why to use these values. Also the tutorial above seems to work with this divider for the mkr wifi.
Well the board is developed to minimise power consumption. So high resistances make sense.
Good thing is that the resistors are on board. Presumably close to the analog input. And with a copper ground plane beneath. And a proper cap. So that will reduce pickup of a lot of mess.
Did you measure battery voltage when the MCU is running??? The voltage will be lower during operation than the open source voltage. Your system is measuring 3V3 as battery voltage. That means the battery must have a very large load (since it is a 1.8Ah battery, I presume it should be able to deliver 1A without too much loss of source voltage). Still worth checking though...
What else is connected that could use more than 1A (presumably more than 2A...).
Thanks @build_1971, the battery voltage was measured with the battery unplugged.
Nothing else is connected. Very odd, as mentioned the tutorial above (and others) do exactly the same but get different results.
Can you measure voltage while sketch is running on battery?
If it really is that low, then your battery is close to dead (we did not check that yet...).
You are right. But it is 4.17V too. I recap, that nothing except usb cable and battery are attached to the mkr nb 1500 board. The sketch does not do any fancy thing so my feeling is either I have set something previously which i have to reset (is there something like permanent storage even after reflashing with the sketch?) or something is broken.
Qny suggestion welcome though. And thanks @build_1971 for the effort.
Can you measure voltage at the pin?
Can you make a voltage divider to feed 0.5 Vbatt?
no cant measure voltage at the pin, too narrow. Also for the divider I would have to manipulate the board or the battery wiring which I am not very confident with. I am currently testing what is the lowest value I get with the ADC to see if this has shows the expected value.
Hi,
Have you got your project on a protoboard ?
OR
Have you gone to a PCB before proving your circuit?
Can you please post some images of your project so we can see your component layout?
If it is a PCB, can you post jpg exported images of your PCB design?
Thanks... Tom...
![]()
That is their entire circuit @TomGeorge
What is being discussed is the battery monitoring circuit built into the MKR NB1500.
Personally I would like to see actual measurements of the resistors used in the divider. We already know that at least one of them differs from what is stated in Arduino's own tutorial and what is in the schematic.
Tutorial: 1MΩ/330kΩ
Schematic: 1.2MΩ/330kΩ
Actual board: ???????
Maybe @pert can shed some light as to what is going on.
