Detecting Charging

Hello,

I have a simple question about detecting the voltage on the charging line.

Attached a drawing shows my setup. In case it is not visible let me describe.
Arduino board is powered from a power bank which supplies 5v 2A.
What I'm trying to do is detecting charging to the power bank.
Power bank is charged from the wall plug adapter standart 5v 1A phone chargers.

I split the cable and directly plugged in red voltage cable to A0(analog input) and black to (GND). And rest of the cable goes to the power bank input.

When I read the voltage using:

int val = analogRead(A0);

without this connection it prints 4-5 etc low values and after connecting the cables it read it as 1024 which I believe the highest value.

What I want to know is if this splitting is safe or normal? Do I need to add a resistor between A0 and the power source? How much energy is being used while measuring the analog input? Is there a explanatory article describing similar scenario?

Thanks in advance for your help.

You are not measuring charging. All you are doing is checking that a voltage is available for the powerbank to use for charging if it needs it.

Have you checked the voltage on A0 with a DMM/multimeter? If it is indeed 5V then you'd expect it to read the maximum (though I bet you it's not actually reading 1024!). If it's actually more than 5V then you're in danger of damaging the Arduino.

Steve

slipstick:
You are not measuring charging. All you are doing is checking that a voltage is available for the powerbank to use for charging if it needs it.

Have you checked the voltage on A0 with a DMM/multimeter? If it is indeed 5V then you'd expect it to read the maximum (though I bet you it's not actually reading 1024!). If it's actually more than 5V then you're in danger of damaging the Arduino.

Steve

slipstick thank you for your answer.
When I connect the cables its printing analogRead(A0) as 1024
I measured the voltage on the cable from the phone charger adapter with a multimeter and it shows as 5.08v

Indeed what I want to achieve is to detect if power bank is being charged so that on the display I can show a message Charging... or turn on some LEDs while 'pb' is charged.

In this scenario, is this a good idea to check if the voltage is available to understand that its actually being charged? Or how else can I detect if the power bank is charging? I really appreciate any comments.

1/ The highest reading you can get from an analogRead is 1023.

2/ a common way to detect charging is to add a small resistor ( eg 1/2 ohm) between the -ve end of the battery and ground, and measure the voltage developed across that.

Allan

The max voltage for an analog input should be less than the power supply. I would suggest you divided the voltage into your arduino analog in by 2. This would require a resistor in series and a resistor to ground.

I would suggest 10K for both (but they could be anything between 5k and 50k). In addition it would help reduce any "noise" if you added a 0.01µF ceramic cap across the resistor going from A0 to gnd.

The reasons I suggest divide by 2 is:

  • You will have plenty of "head room" if the voltage goes much above 5V. Here head room means the voltage increase the circuit can accommodate before hitting some limit.
  • It requires two of the same resistors making the parts selection easy.

allanhurst:
1/ The highest reading you can get from an analogRead is 1023.

2/ a common way to detect charging is to add a small resistor ( eg 1/2 ohm) between the -ve end of the battery and ground, and measure the voltage developed across that.

Allan

Hey allanhurst,

First of all thank you for your comment.

1- There might be a rounding going on while printing the value but its printing as val: 1024 in the serial monitor while plugged in to the power adapter.
int val = analogRead(A0);
Serial.println("val: " + String(val));

2- So I'm charging power bank from normal usb wall adapter. I divided its cables and directly connected red to the A0 and black to GND pins on arduino board. So are you suggesting that I should add extra resistor between red cable and A0 pin? Or do you mean I should connect red and black wires with a resistor in the middle then connect that to the A0 to measure the end result?

JohnRob:
The max voltage for an analog input should be less than the power supply. I would suggest you divided the voltage into your arduino analog in by 2. This would require a resistor in series and a resistor to ground.

I would suggest 10K for both (but they could be anything between 5k and 50k). In addition it would help reduce any "noise" if you added a 0.01µF ceramic cap across the resistor going from A0 to gnd.

The reasons I suggest divide by 2 is:

  • You will have plenty of "head room" if the voltage goes much above 5V. Here head room means the voltage increase the circuit can accommodate before hitting some limit.
  • It requires two of the same resistors making the parts selection easy.

JohnRob really appreciated your comment thank you.

To clarify my understanding of your comment I should add a resistor serial to the red wire from the adapter, and another resistor serial to the black wire from the adapter, and then they will be connected to the A0 and GND of arduino board accordingly?

If the noise or false positive detection is not a requirement for me can I ignore adding a cap?

gunhan:
If the noise or false positive detection is not a requirement for me can I ignore adding a cap?

the capacitor is not so much for 'noise' but a good habit for smoothing power-rails.

you can look-up decoupling

gunhan:
To clarify my understanding of your comment I should add a resistor serial to the red wire from the adapter, and another resistor serial to the black wire from the adapter, and then they will be connected to the A0 and GND of arduino board accordingly?

No. One resistor from red wire to pin A0, second resistor from pin A0 to ground. The black wire goes straight to ground.

Steve

So voltage measuring is working fine by using the first diagram as you all suggested.

However in the second diagram I tried to use the same power source to feed the 'power bank' then the voltage measure could not read the voltage anymore whenever I connect the cables by using the second diagram (what I mean is it behaves like nothing connected).

I feel like I'm doing something wrong very basic here.
My only goal is to detect if the power bank is being charged or not. So that I can show it on the arduino through a display.

I wonder if I need to get an external voltage sensor module like below?
https://www.ebay.co.uk/itm/Arduino-Voltage-Sensor-0-25V/273062576090

Measuring the battery voltage does not tell you if it's being charged.

See my suggestion in post 3 , which does.

Allan

allanhurst:
Measuring the battery voltage does not tell you if it's being charged.

See my suggestion in post 3 , which does.

Allan

Hi allanhurst,

I believe that in my first diagram I did as you suggested and correctly measured the voltage.

But just to clarify myself since I believe there is a misunderstanding or most probably I drew the circuit wrong, that I don't have a battery. So the 5V voltage source that I have is a normal phone charger adapter not a battery. That charges the 'power bank' and 'power bank' powers the arduino. Since the 'power bank' has a voltage regulator, it always outputs the same voltage. And 'power bank' is not always connected to the 'adapter'. Once adapter is used to charge the 'power bank' I want to detect that and show it on the arduino. That is why I'm trying to measure the voltage because adapter may or may not be connected so I just want to measure the voltage to understand if it is connected to charge the 'power bank'. But as you can see on my second diagram it seems that with my very limited knowledge the electric flow doesn't go through to the A0 of the arduino.