Hello, I am using a Box for a research project that has an Arduino Due inside. While using it it runs out of battery and my team would like to have an indicator of how much battery is left in order to prevent this.
Is there a way to measure this without adding any hardware to the Arduino?
What do you need to know in order to help me? I only know it uses 3.7V battery
I've seen a few pages*, but I understand they are for different boards and I don't know much about microcontrollers to know what to change
The processor on the Due runs at 3.3V. Your 3.7V battery is probably a rechargeable lithium battery, which at full charge can be as high as 4.2V. But it's not clear how your Due could be powered by a single lithium battery because the dropout voltage for the 3.3V regulator used on the Due can be as high as 1.2V, requiring an input voltage of as high as 4.5V to operate properly. Can you provide more information about the battery supply (one cell, or two in series?) and how (which pin) it is connected to the Due?
In any case, I don't think it will be possible to measure battery voltage without adding any external parts. But you would only need two resistors to create a voltage divider.
I don't think so either. I've now had a quick look at the datasheet for the SAM3X8E and it doesn't look like the ADC subsystem can measure the internal reference voltage like the 328P can. That would indicate that the UNO trick can't be replicated on the DUE and external components would be required.
If you go down the external components route, then you may find this of interest:
It is for a 328P so it may not work on the DUE with MΩ resistor values. A bit of experimentation may be needed.
The solution I like best uses a P-channel mosfet and a capacitor to allow switching the divider current on only when you need to measure the battery voltage. It's a couple pages further on in the Jeelabs writeup:
Yes, but most Arduinos have one or more stable internal references that are independent of VCC noise and variations. The Due is the only one I know that hasn't got any.
Leo..
Sorry, the one you linked to in post#5 will work with a Due.
There is another circuit with an N-channel fet and 1.1volt Aref I was thinking off.
I would still go for a simple voltage divider with higher value resistors.
The Due is not made for ultra low power, so a few uA extra won't matter.
Leo..
I understand that the only option is to add the voltage divider. Is there a subtly to be considered being a Due board or can I search for any example. Which of the links you presented would explain also how to program it later?
The batteries I have are LIPo akku lithium-Ion polymer batteries of 3.7V 200mAh 7.4Wh
My supervisor is still looking for the correct screw to open the boxes, so I can post soon how it is connected.
A good reference voltage is needed when you want to measure battery voltage accurately,
But I think OP only wants to roughly see if the battery is almost flat, say 3.5volt per cell.
Then a simple voltage divider and default Aref (3.3volt) should be enough.
OP didn't say how the Due is powered. I don't think a single cell would be enough. Maybe they are using two cell in series. I would divide to about 2.5 or 3volt.
Leo..
True, but that only happens when the battery drops to a point where also VCC begins to drop.
As long as VCC stays 3.3volt, there is no problem.
That's why I asked how the Due is powered.
It has a combination of a switchmode buck converter to make 5volt, followed by a linear NCP1117 regulator to make 3.3volt for the MCU.
Leo..
The first image shows the type of battery. I had to change the old one.
The second shows where it connects: 5V pins
And finally the battery connects to the red board before going to the main board.
I am very sorry I don't know what any of this means. Do you still think its possible?
The hole marked EXT_sw (battery+) can be used to connect your voltage divider to.
Try a 100k resistor between that via (hole) and an analogue pin of the Due, and a 330k resistor from Due pin to ground, with an optional (better) 100n capacitor between Due pin and ground.
See what values you get at different battery voltages.
Leo..
The battery shown has a protection circuit built-in (over/under voltage and current limit),
which will switch the battery off a ~2.7volt.
You can calculate returned A/D value for ~3.5volt low battery warning point from the resistor values,
assuming Aref is 3.3volt.
Leo..
Anyway, it appears we have the battery feeding an external 5V boost converter, feeding a 1117 3.3V linear regulator on the Due, feeding the processor. That should mean the 3.3V Vcc is constant until the very end, so a divider should work fine.
It should also work if you replaced the boost converter with a better 3.3V LDO with a dropout voltage under 0.2V, and powered the Due at the 3.3V pin. That's unless the Due, or something else, needs the 5V supply.