Hi, I have bought a 3000Mah lipo battery that I run my arduino mega with.. (because of my fear of blowing up myself and my batteries I decided to buy a powerbank and just hack it instead). I am using my mega with a touchscreen and for my project I want to show how much juice there is left on the battery, maybe showing warnings when the battery gets low. Anyways I have no idea how to do this... ( I do not want to show it in percent, I was thinking more like showing four blocks that indicate 1/4, 2/4, 3/4 and 4/4ths. as percent is not necessary)
Currently the battery is connected to a protection and charging circuit, from there it goes to GND and VIN.
Should I take a wire directly from + on the battery to an analog pin, or should I take it from the protection circuit?
is there any library for this, do I need one?
Any information regarding this will be appriciated alot as I need my project done in two weeks!
Voltage applied to Vin should be above 6V. If you apply 5V to Vin your aduino gets only around 4 Volts. In most cases it's enough to make it work, but could lead to unstable behavior.
A powerbank should ofcourse be connected to the Mega's USB socket, with a USB lead.
The Mega's USB socket is poly-fuse protected, so safer than the 5volt pin.
Much safer to use the powerbank as-is, and have some sort of timer (coulomb counter) running on the Mega.
Leo..
Well, I havent experienced any unstability, and last time I had an external powersupply connected to 5+ and gnd and connected my pc, I fried it. So ill keep it on vin aslong as it works, but thanks for the advice. regarding the USB cable, it would not fit in the case of my project as compact is a must.
But why do I need a resistor from the battery to the analog pin?
3.7V is the voltage of a single-cell LiPo battery.
It is possible that the powerbank is stepping it up to 5V, as that is the usual voltage output for USB charging/powering phones and the like.
You have the powerbank connected to VIN, which is fine.
Now the problem is that if you try to measure that voltage using an analog pin, as the voltage starts to drop, so does the internal Vref voltage (the default is the same voltage as on VIN).
What I suggest you do is use the EXTERNAL AREF pin, connected to the 3.3V output of your board, and a suitable voltage divider to drop the 5V applied to your analog input to a maximum of 3.3V. The divider resistances of 3K9 (VIN to analog input) and 5K6 (analog input to GND) will give you 2.95V analog input from the 5V coming from the powerbank. You can then use the map() function to scale the analog input to actual volts.
EDIT : The internal 32K resistance of the AREF pin will make the 2.95V less : see the reference linked to below. What I usually do is use a 20-turn trimpot to set my analog input coming from my power supplies to a suitable voltage, but then I have the luxury of always using a higher voltage on VIN. That was a load of rubbish - the divider goes onto the analog input pin, not AREF - got a bit confused
Read this page from the reference how to use the EXTERNAL reference, especially the warnings at the end.
The lipo battery is connected to a charging, short circuit and boost circuit, which makes the one cell battery put out 5volts. but the battery is 3.7volts.
I dont really understand what you ment with the Aref pin, can you explain more?
daba:
It is possible that the powerbank is stepping it up to 5V, as that is the usual voltage output for USB charging/powering phones and the like.
Powerbanks are indeed designed to produce a constant 5volt to power/charge USB devices, until the battery goes flat.
daba:
You have the powerbank connected to VIN, which is fine.
No, it's not.
V-in needs at least 6volt for the Mega's regulator to make a stable 5volt.
daba:
What I suggest you do is use the EXTERNAL AREF pin, connected to the 3.3V output of your board, and a suitable voltage divider to drop the 5V applied to your analog input to a maximum of 3.3V...
Why that.
The Mega has two INTERNAL reference voltages. 1.1volt and 2.56volt, that can be selected with code.
Leo..
My question was not about my powerbank. It was about how to measure the voltage of the battery the arduino is running on, and making 4 blocks that show how much power there is left on the cell printed to a touchscreen.
so far I have got one answer that I feel like trying, which is connecting an analog pin to a resistor of 330 Ohm and connecting that directly to the cell.
Is this go, or no go?
If not, what else should I do that doesnt require anything else than passive components (resistors, capacitors etc.). -And is a possible solution of the problem I have.
And, connecting the 5v output from the cell circuit, is fine. I have had zero problems with it. (maybe not in the books, but reality isn't a book). However, if you try it with 3v, it will not work.
Wawa:
V-in needs at least 6volt for the Mega's regulator to make a stable 5volt.
Yes, you are correct, I meant to say connect to 5V pin, which will be fine
Wawa:
Why that.
The Mega has two INTERNAL reference voltages. 1.1volt and 2.56volt, that can be selected with code.
Leo..
Agreed, and on the Mega, it's OK to use them, but I was giving advice for other boards that don't have the luxury of the additional INTERNAL references, only the EXTERNAL AREF pin.
Recommended in the linked reference text is to connect the external reference voltage via a 5K (4K7 ?) resistor, which will reduce the reference to approximately 2.88V, and that should be the limit of the voltage applied to the analog input pin - 1K8 series and 10K0 to ground will give 2.79V max, which is a good target.
sumfuk:
My question was not about my powerbank. It was about how to measure the voltage of the battery the arduino is running on, and making 4 blocks that show how much power there is left on the cell printed to a touchscreen.
so far I have got one answer that I feel like trying, which is connecting an analog pin to a resistor of 330 Ohm and connecting that directly to the cell.
Is this go, or no go?
If not, what else should I do that doesnt require anything else than passive components (resistors, capacitors etc.). -And is a possible solution of the problem I have.
And, connecting the 5v output from the cell circuit, is fine. I have had zero problems with it. (maybe not in the books, but reality isn't a book). However, if you try it with 3v, it will not work.
For you - on the Mega only - you can use the INTERNAL 2.56V reference, and a potential divider to an analog input from your supply voltage to drop it t a maximum of 2.56V.
You really should power your Mega using the 5V pin, not VIN, as the 5V regulator will not be receiving enough input volts, and depending on the type of on-board regulator may get hot ! Also the internal references may be compromised by the chip not getting a full 5V.