Lithium battery

Hello, I want to use a lithium battery with an atmega (without arduino board) but I don't know how I can read the voltage of the battery because it's the same who power the board. I've read that I can set the analog ref to 1.1v but can I do after The atmega powers a gps who works with a max of 3.6v and the battery can deliver 4.2v to 3v. I've seen that I can use an LM3641 (http://www.ti.com/lit/ds/symlink/lm3641.pdf) but I don't know if it's the best way. I don't know how I can limit the battery discharge anf if I can use the battery when it's charging or if I muss deconnect it. I'm not lock on a lithium battery but I don't have a lot of space and I want a waterproof case and that we don't have to open the case to charge the batteries. Thanks Guillaume

google "arduino measuring battery voltage"

We are here to help, but really, let's try not to be lazy ok ? You know Google is available. Please restrict your forum questions to ones that are not so easily resolved with a google search. If after trying that , you still have questions, feel free to ask. We would prefer not get questions like 'What time is it ?"

Please take a moment to Google your topic with the word "arduino" at the beginning of the search string before posting. Most questions can be answered quickly this way. If after trying this you still have questions, then ask.

ie:

Google Search: arduino measuring battery voltage

The atmega powers a gps who works with a max of 3.6v and the battery can deliver 4.2v to 3v. I've seen that I can use an LM3641 (http://www.ti.com/lit/ds/symlink/lm3641.pdf) but I don't know if it's the best way. I don't know how I can limit the battery discharge anf if I can use the battery when it's charging or if I muss deconnect it. I'm not lock on a lithium battery but I don't have a lot of space and I want a waterproof case and that we don't have to open the case to charge the batteries.

I don't know how I can limit the battery discharge anf if I can use the battery when it's charging or if I muss deconnect it.

The first concern when measuring battery voltage of the battery powering the ATmega328 is whether or not it is less than 5V. Obviously you cannot use a battery less than 5V to measure the battery because the default analog reference is Vcc so the measurement would be inaccurate. You would need to change the analog reference to INTERNAL and use a voltage divider to reduce the measured voltage to the midpoint between 0 V and 1.1 volts or at most to 75% of that range.

Also, as far as can you measure it while your charging it , no. You can't because you have a source in parallel with a load. You have to disconnect the source (charger) to measure the load (battery). (normally a battery is a source but when it is being charged it is a load)

You can disconnect the battery from the charger using a SPST switch.

The atmega powers a gps who works with a max of 3.6v and the battery can deliver 4.2v to 3v. I've seen that I can use an LM3641 (http://www.ti.com/lit/ds/symlink/lm3641.pdf) but I don't know if it's the best way

Only you can decide whether you need to use that chip. If you are capable of understanding the datasheet and have the chip I would say try to use it. Is it the best way ? The best way is to have two batteries and charge one while using the other and switch from bat-A to bat-B using an SPDT relay. Then you can measure the battery being used because it is not being charged and use a flag to keep track of which battery is being charged. Your code would have to account for the possibility of the arduino resetting at the moment the relay switches. The boolean flags would need to be stored i EEPROM to avoid loosing them on reset. If you add a large enough electrolytic capacitor (>= 330 uF), it should power the arduino during the 50 mS it takes for the relay to switch, eliminating the need for the EEPROM .

raschemmel: Also, as far as can you measure it while your charging it, no. You can't because you have a source in parallel with a load. You have to disconnect the source (charger) to measure the load (battery). (normally a battery is a source but when it is being charged it is a load)

Eh?

The volage measured across a battery will not be the battery voltage if it is connected to a charger. It will be the chzrger voltage. ( regardless of battety type). You hsve to disvonnect charger to measure the battery.

Thank you for your replies
raschemmel : I’ve already search on google, I have found what you means but I want to test the voltage of the power supply and it’s repply 1023 at an analogRead().
I have forgotten, I will use an atmega32u4 without arduino board and at 8MHz
If I use the internal ref and I connect the battery to A0, could the battery stay wired to A0 or I muss disconnect it?

Don't connect anything, do anything or connect the vattey until you understand what you need to do. You haven't mentioned your interface circuit so something is wrong

Post your schematic.

raschemmel: The voltage measured across a battery will not be the battery voltage if it is connected to a charger. It will be the charger voltage. ( regardless of battery type). You have to disconnect charger to measure the battery.

The OP mentioned whether it was appropriate to operate the Arduino whilst the battery was charging.

Given that he is using a single lithium cell, with a voltage on charge not exceeding 4.2 V, directly powering the Arduino via the Vcc terminal, it is perfectly safe to do so but this may exceed the specification of other connected devices rated for 3.3 V only.

Similarly, it is quite fine to measure the battery voltage during charging - indeed, quite desirable to assess the charging process - but obviously not using the Vcc supplied by the battery itself as the reference.

And yes, the OP has not properly explained what he is attempting to do.

Similarly, it is quite fine to measure the battery voltage during charging - indeed, quite desirable to assess the charging process - but obviously not using the Vcc supplied by the battery itself as the reference.

You can read whatever you want be it won't be the battery voltage you'll see when you disconnect the charger, for obvious reasons. Reading the charging voltage is not reading the battery. He asked about reading the battery. If you want to know what the battery voltage is you need to disconnect everything from the battery. That should be obvious.

My schematic is incomplete I will build a gps who is controlled by an atmega without board powered by a LI-ion bat but the gps work only with 3v-3.3v When I plug the board on the computer it will transmit data and charge the bat Could the TP4056 (bat charger) give power to the atmega and recharge the battery at the same time?

http://www.ti.com/lit/ds/symlink/ucc3954.pdf

Here a little drawing :

https://onedrive.live.com/redir?resid=D51A642F2BE5A217!125438&authkey=!AIQmVcJyMpq3sTw&v=3&ithint=photo%2Cjpg

and
https://onedrive.live.com/redir?resid=D51A642F2BE5A217!125439&authkey=!AL4cbvBLuHMnXhU&v=3&ithint=photo%2Cjpg

Sorry for the double post and tanks for your help

Dude, that's unnecessary. Just use the "Attachments and other options" link below to attach the photo.

Then click SAVE to save your changes

then right click over the attached filename and select "Copy link address"

then click MODIFY (AGAIN) and click on the attach image toolbutton (computer monitor icon to the left of the chain links icon) and paste the copied link address into the bar

then click SAVE (AGAIN)

You might need to use Microsoft Paint to resize your file or save it as a jpeg.

No, you don't HAVE to disconnect the battery but the voltage you measure will not be accurate while it is connected to the charger.

Thanks
I can supply the atmega directly by the charger during charging process or it can disturb the charge?
also I can wire like this

Does a 3.3v (or 3.3v) regulator exist with an input of 4.2v to 3v? and if the curent <3v what happend? can it stops the discharge?
I’ve found a componement UC3954 (http://www.ti.com/lit/ds/symlink/ucc3954.pdf) but it doesn’t stop the discharge.
Can a LDO makes what I want?

Sans titre.png

I can supply the atmega directly by the charger during charging process or it can disturb the charge?

Like I said, you can power the arduino during charging. No problem
You just can’t expect the voltage measured to be the same as the battery voltage with nothing at all connected to it.

Does a 3.3v (or 3.3v) regulator exist with an input of 4.2v to 3v?

Low Dropout Regulators have a smaller overhead and thus can operate on a voltage that is only slightly higher than the output voltage.

and if the curent <3v what happend? can it stops the discharge?

current isn’t measured in volts.

the atmega resets at 2.6 V (brownout theshold)

I’ve found a componement UC3954 (http://www.ti.com/lit/ds/symlink/ucc3954.pdf) but it doesn’t stop the discharge.
No idea what your are talking about.

Can a LDO makes what I want?

I don’t know what you are asking here.

Redo your drawing with inputs on the left and outputs on the right.
What country are you from ?

I'm from France (and this is why I have issues with (few) words like current etc...)

"but it doesn't stop the discharge" the componement do not stop the discharge of the battery at 3v but when it's dead at 2.5v

Maybe it is easier to use a NiMH and increase the voltage to 3.3v It takes nearly the same space I will think about these two ways, I don't forgot the idea of the lithium battery Thanks a lot for your help, now I have many informations about these battery

guillaume55:
Thanks
I can supply the atmega directly by the charger during charging process or it can disturb the charge?
also I can wire like this

Does a 3.3v (or 3.3v) regulator exist with an input of 4.2v to 3v? and if the curent <3v what happend? can it stops the discharge?
I’ve found a componement UC3954 (http://www.ti.com/lit/ds/symlink/ucc3954.pdf) but it doesn’t stop the discharge.
Can a LDO makes what I want?

The LTC3335 is a buck-boost regulator for these types of applications → http://cds.linear.com/docs/en/datasheet/3335f.pdf

I am using it for something similar: A Lithium (not Li-Ion) battery powering an Arduino with a radio (mine is GSM). The LTC3335 is low current so I need a lot of output capacitance for when I use the radio, but the LTC3335 replenishes the charge on this capacitance in between transmissions.

Another feature of the LTC3335 is that it includes a coulomb counter. Since your battery voltage won’t change much over time, the coulomb counter gives you an estimate of how much charge is left in your battery.

If you wanted the LTC3335 to turn off automatically when the battery is lower than 3V you could need a comparator circuit connected to the EN pin. When EN is low the LTC3335 will go into a low power state that draws 680nA (about the same as battery self discharge). The LTC1540 shows a circuit to detect 2.9V on page 1 → http://cds.linear.com/docs/en/datasheet/1540fas.pdf

At this point, however, you won’t have 3.3V to run your Linduino. From the block diagram you posted, I’m not sure how the TP4056 will get turned back on to recharge your dead battery.

Edited to show the OP’s block diagram:
f3a7e5d25757e50ec2a59bb364a7c409e4d08f9f.png

"but it doesn't stop the discharge" the componement do not stop the discharge of the battery at 3v but when it's dead at 2.5v

As mentioned, the atmega will reset at 2.6V due to the default brownout threshold. The 3.0 V comparator is a good idea. As I said earlier, the "best way" (as you put it) , is to have two sets of batteries and a DPDT relay that switches batteries when the one in use gets low and has a 680 uF cap to maintain the processor voltage during the 50 mS the relay is switching. That way you are always charging one while the other is in use. One half of the relay is to switch the arduino battery and the other half is to switch the battery charger from one battery to the other.

raschemmel: As mentioned, the atmega will reset at 2.6V due to the default brownout threshold. The 3.0 V comparator is a good idea. As I said earlier, the "best way" (as you put it) , is to have two sets of batteries and a DPDT relay that switches batteries when the one in use gets low and has a 680 uF cap to maintain the processor voltage during the 50 mS the relay is switching. That way you are always charging one while the other is in use. One half of the relay is to switch the arduino battery and the other half is to switch the battery charger from one battery to the other.

I have not enouth space for 2 batteries (and I prefer to use popular battery if I muss to replace the battery it will be easier) I didn't say the relay was not a good solution but if think the comparator and the LTC3335 use less space Can I replace LTC3335 by NCP1402 ? I don't need more than 100 mA

"At this point, however, you won't have 3.3V to run your Linduino. From the block diagram you posted, I'm not sure how the TP4056 will get turned back on to recharge your dead battery." Yes, CE can stay enabled? Thank you

Read the datasheets.

thanks
I’ve already read the datasheets
Could anyone check my shematic? I not sure if I had to add as far as capacitors or if I can divid the number of capacitor znd if I can ground all the shematic at the same ground
(made with KiCad, so I attach a screenshot too)
Thank you

guillaume55: Can I replace LTC3335 by NCP1402?

The NCP1402 is a step-up regulator only. It can only make output voltages that are higher than the battery voltage input.

You said you need to convert a battery between 3V-4.2V to a constant 3.3V output? In that case you need to step down most of the time, and only step up when the battery is betwwen 3V-3.3V.