How to code a phone app to know the battery level of a phone

Hi, I'm new, this question is not quite an arduino question but I figure it might be useful to ask it here as I will need the app to send the data to an arduino

My plan for my project

  1. Place arduino inside an extention box ( the box where you can Connect plags and turn the switch on and off) and have it automatically turn the current on and off using a relay.

2.i want the arduino to turn off the current when it gets data sent from the app saying that the phone have been charged fully or charged to a specific battery level ( for example I want my phone to charge till its at 80% , so after my phone reach 80% , I want the app to send a signal to the arduino to turn off the current)

  1. If possible, maybe I can let it reconnect the current if it gets data that the phone went down a few percent ( for example , I charged it to full, the arduino cut the current, after 30 minute's, my phone went down to 95% , the app know that the battery level went down to 95 so it sent another signal to the arduino to tell it reconnect the circuit.

I'm sorry if this got not much to do with an arduino but I felt that maybe someone could help me with this.

  1. I want to know how phone apps know that your phone battery percentage is full or not, or at a certain level. I found a few apps that's like ' Full charge alarm ' and such.

  2. I bought a relay and a hc 05 Bluetooth module, hoping to use Bluetooth to connect and control the arduino. I found some tutorials about connecting the arduino with your phone using Bluetooth but I would like to know if my idea would work / is it possible.

Thanks

Welcome,

Maybe this will help : java - Get battery level and state in Android - Stack Overflow

It's an interesting field of research. I read recently an article about using artificial intelligence to decide how to best charge your batteries.

(one issue you'll have is your app needs to run in background, use bluetooth etc --> so is draining the battery while charging. Not sure you'll be more efficient than the built in circuitry and intelligence, I would trust better the OS than a personal hack to do this)

Am I doing something wrong? My Android phone is plugged in to the regular charger all the time I'm at home - most of the time it is at 100%. I have not noticed any problems.

...R

Robin2:
Am I doing something wrong? My Android phone is plugged in to the regular charger all the time I'm at home - most of the time it is at 100%. I have not noticed any problems.

...R

Battery capacity inevitably declines with age and research has shown that small but regular top-ups are much better for Li-ion batteries than long full charge cycles

you can read more there

Here’s a TL;DR summary of the battery tips above:

What’s the best way to charge your smartphone?

Avoid full cycle (zero-

  • 100 percent) and overnight charging. Instead, top-up your phone more regularly with partial charges.
  • Ending a charge at 80 percent is better for the battery than topping all the way up to 100 percent.
  • Use fast charging technologies sparingly and never overnight.
  • Heat is the battery killer. Don’t cover your phone when charging and keep it out of hot places.
  • Turn your phone off when charging, or at least don’t play games or watch videos to avoid mini-cycles.

I'm afraid the validity of the advice in your link dropped out of view when I read this bit "It’s a leftover myth from lead-acid cells " when what they probably meant was NiCd cells. You should not fully discharge a lead-acid battery.

What else might be wrong with the article that I don't know is wrong?

In my limited experience (just with lead-acid cells) what wears a battery out is usage (how surprising). In other words the number of amp-hours it provides (which, inevitably, includes the amp-hours that have to be put back to re-charge it). I suspect this is likely to be generally true for most battery types. It would be very unusual to find a physical system that improves with usage.

If a battery is not used much it will last a long time. If it is used regularly it will wear out quicker. As far as I can see if you don't discharge or charge it at a too-high rate or discharge it to a damagingly low level or over-charge it then it makes little difference whether you discharge it a lot between re-charges or only a little. Discharging it a lot generally implies using it more. It is bad for lead acid batteries if you leave them discharged for a long period but I don't know if that is true of LiPo cells. On the other hand LiPo cells seems to have an almost zero self-discharge rate.

...R

fair enough - I picked the first article google would give me

I've bumped into some research that shows that running always full or toping up constantly is a bad idea over time and that it's best to limit this (Tesla's 90%).

-> Hence the idea to charge at 80% and complete the charging cycle only once, just before you pick up the phone (thus the AI part to predict when you'll wake up)

J-M-L:
I've bumped into some research that shows that running always full or toping up constantly is a bad idea over time and that it's best to limit this (Tesla's 90%).

But when my phone shows 100% maybe it's really only 90% of the battery's theoretical capacity - if the Samsung engineers designed the charging system properly.

The problem with batteries is that it would be difficult to do a meaningful laboratory test even if you had unlimited time and money. And it is impossible for any individual user, or a group of friends, to do any meaningful testing.

...R

Agreed - we don’t know what we don’t know

J-M-L:
Agreed - we don’t know what we don’t know

Yeah. We need Donald Rumsfeld :slight_smile:

...R

:grin:

Robin2:
if the Samsung engineers designed the charging system properly.

And quite likely they did....
My wife's Sammy flipphone is ten years old and is on its original battery. It never goes flat either. It spends most of its time at home sitting on the charger, just like you say.

I'm sure the OP will eventually find a better use for Arduino and Bluetooth than this pointless, and likely futile, exercise.

Why would it go flat if you don’t use it :). Some Smartphone are emptied almost every day and fully recharged - that’s a very different scenario

The point that Robin was making is that you’ll always see 100% because the battery will be at full capacity of what you have - but you might be at half the original capacity

J-M-L:
The point that Robin was making is that you’ll always see 100% because the battery will be at full capacity of what you have - but you might be at half the original capacity

While what I have highlighted is true it is not the point I was trying to make - I was just making the point that the Samsung engineers may have designed the battery charging system for maximum good battery life.

Thinking more about this issue, it occurs to me that anyone who is conscious that their phone battery is not lasting as long as it used to is almost certainly a person who is using their battery a lot. And, as I suggested earlier, things that get used a lot tend to wear out. My phone only goes below 50% on the odd occasion when I forget to plug it in so I have no idea how long it would run for. What I do know is that I have never been unable to use it because the battery was too low, and that is sufficient for me.

What I do know is that the sticker capacity of batteries is not a number that should be trusted. I have never seen a battery manufacturer's datasheet that describes how to verify that their battery has the capacity they claim it has, and over how many charge cycles it will continue to have that capacity. Almost everything else you can buy can be easily verified to contain what the pack says it contains.

...R

I was just making the point that the Samsung engineers may have designed the battery charging system for maximum good battery life.

OK - may be if they are not the same engineers who designed and signed off on the Galaxy Note 7 battery system :sweat_smile: :smiling_imp:

Measuring battery capacity of something you use a lot is complicated. One battery engineer once described to me that it's close to be trying to measure the depth a body of water. When everything is calm, no wind standard pressure and T° - it's easy but try to do this in the middle of hurricane, earthquake and tsunami and it becomes a "bit harder". What she meant is the minute you start using your battery strongly, it's a chemical storm in there and as people tend to use their phone more and more frequently and many background processes (4G and Wi-Fi, location, step counting, notifications, cloud services, background syncs, apps updates, ...) demand battery life, offering a meaningful level is quite a humbling task especially in a system that wears out.

Nick_Pyner:
...I'm sure the OP will eventually find a better use for Arduino and Bluetooth than this pointless, and likely futile, exercise.

With respect, and conscious that this discussion will have enlightened some, this has not answered the OP's questions. OP has said he/she is new to Arduino and will use Arduino in a part of his project. However futile it might appear, it IS his project, and in building it he will learn and develop his skills...and isn't that the purpose of this very helpful forum.

Now from my very limited knowledge I suggest that the state of charge of a mobile phone battery is a piece of data that can be accessed by the Arduino over a Bluetooth link, though I have little idea how to get it there, nor what to do with it once it's there! Perhaps more knowledgeable types will interject now and help the OP along.

GM

Glorymill:
However futile it might appear, it IS his project, and in building it he will learn and develop his skills...and isn't that the purpose of this very helpful forum.

The OP has not said that he is approaching this merely as a learning exercise and my comments (for what they are worth) have based on the assumption that the OP sees this a real improvement over the built-in charging system on his/her phone.

And these diversionary discussions usually only develop in Threads where the OP does not respond.

...R

Glorymill:
With respect, and conscious that this discussion will have enlightened some, this has not answered the OP's questions. OP has said he/she is new to Arduino and will use Arduino in a part of his project. However futile it might appear, it IS his project, and in building it he will learn and develop his skills...and isn't that the purpose of this very helpful forum.

well @Rainfury is MIA, did not answer once...

Her/His question was "I would like to know if my idea would work / is it possible."

--> The answer is Yes (to some degree) and we provided perspective.

Given OP does not seem much of a programmer though, I don't think that's within reach

Glorymill:
However futile it might appear, it IS his project,

The OP knew from the start that this had not much to do with Arduino, and the deafening silence from same may be a signal of his/her realisation of just how futile an exercise it really is.
It's a phone exercise. If it can be done at all, the information conveyed has no value, and you are quite right to wonder what the hell you do with it once you've got it.

I imagine apps like the abovementioned "full charge alarm" are just useless ad vehicles.

OK - in the spirit of the forum.... here is my go at if for a constructive answer, probably matching the level of the OP:

It's pretty easy on Android to write an app with MIT App Inventor even if you are a beginner.

App Inventor supports extensions and one of those lets you capture the battery info

MIT inventor lets you also easily use the bluetooth stack and you can connect that to your arduino using an HC-05 for example (SPP protocole) which is what OP has bought. Here is a tutorial for that: Sending and Receiving Data with HC-05 – MIT App Inventor.

On the Arduino side, I would suggest to study Serial Input Basics to handle the serial communication and there are countless tutorials on how to drive a relay from your arduino (here is the first one google gave me)

Combine everything and you are good to go*

(*just remember to launch the Android app when you plug your phone in)