Maker Pro
Maker Pro

Current sensing using Arduino

Karthik rajagopal

May 9, 2016
257
Joined
May 9, 2016
Messages
257
Hi all,
I recently completed making my lab bench power supply. I have used Arduino to detect and display the voltage and current on an LCD display. I have used a current sense IC from Texas Instruments (part no. INA250A4PW) which has an integrated current shunt resistor with an output of 2 V/A. Since my supply can deliver a maximum of 4A (sensor output of 8V ), I thought of reducing the output of sensor to half its voltage so as to bring the voltage within the limits of Arduino. The problem that I am facing is that the current reading displayed is not stable and fluctuates a lot from the actual value. A direct reading from the sensor is accurate and has no issues. So,I tried reducing the sampling rate to one sample per second but in vain. Please help me resolve this issue . I have attached both the circuit diagram and the arduino code.
I have included only the part of code that senses current in order to make it more clear.(remaining part of the code does not contain any 'delay' functions.)
Code:
[Mod edit: changed from raw text into codebox]
Code:
#include <elapsedMillis.h>
elapsedMillis samplingRate;
float current=0;
void setup()
{}

void loop() {
if(samplingRate>=1000)
{
current=((analogRead(A5)*0.0049*2.2)/2.0);//2.2 is multiplied to compensate the accuracy error in resistor divider
samplingRate=0;

}
//lcd commands to print the value.

}
 

Attachments

  • IMG_20200401_235839.JPG
    IMG_20200401_235839.JPG
    66.8 KB · Views: 12
Last edited by a moderator:

Bluejets

Oct 5, 2014
6,924
Joined
Oct 5, 2014
Messages
6,924
Power supply rock solid..??

You may need to average the readings over some range perhaps 10 as this often happens with analog.

I have found the INA219 on I2c to be more suitable.
 

Karthik rajagopal

May 9, 2016
257
Joined
May 9, 2016
Messages
257
Power supply rock solid..??

You may need to average the readings over some range perhaps 10 as this often happens with analog.

I have found the INA219 on I2c to be more suitable.
Thanks for the reply. I will try out that change in my code and update you with the results.
Is there anything like minimum current needed for an analog pin of arduino for it to function properly ?
 

Bluejets

Oct 5, 2014
6,924
Joined
Oct 5, 2014
Messages
6,924
Is there anything like minimum current needed for an analog pin of arduino for it to function properly ?

Could be but I'm not familiar with minimum levels.
I know digital inputs are a bit quirky with any levels of resistance over 10K I believe.
Mob over at Arduino forum might be your best bet.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,722
Joined
Nov 17, 2011
Messages
13,722
Some issues to consider when using the arduino's analog input pins. A 2.2 kΩ voltage divider as in your circuit should be of low enough an impedance, I see no problem here.
So,I tried reducing the sampling rate to one sample per second but in vain.
That is likely to increase noise, not decrease. Use multiples samples and average them as @Bluejets suggested.
Ensure a good common ground system and proper decoupling of your circuit elements.
 

Karthik rajagopal

May 9, 2016
257
Joined
May 9, 2016
Messages
257
Power supply rock solid..??

You may need to average the readings over some range perhaps 10 as this often happens with analog.

I have found the INA219 on I2c to be more suitable.
Changed my code as you said and it works well. There are very little fluctuations and the readings now are pretty much stable . Thank you for the help .
 

Karthik rajagopal

May 9, 2016
257
Joined
May 9, 2016
Messages
257
Some issues to consider when using the arduino's analog input pins. A 2.2 kΩ voltage divider as in your circuit should be of low enough an impedance, I see no problem here.

That is likely to increase noise, not decrease. Use multiples samples and average them as @Bluejets suggested.
Ensure a good common ground system and proper decoupling of your circuit elements.
Thanks for the reply .
Ensured proper decoupling in the circuit and also changed the code as suggested .
Now the readings are far better than before and have very little fluctuations.
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481

Bluejets

Oct 5, 2014
6,924
Joined
Oct 5, 2014
Messages
6,924
@Karthik rajagopal

You might consider adding a capacitor from the middle of the 2.2k Voltage divider to ground ... at the very least that should help sort out if the problem is on the digital side or the analog side. You might also consider one of these: https://www.ebay.com/itm/ACS712-Cur...hash=item5b389588e9:m:mqD8YxBMi-lItuxrZwWvv-A .... they are pretty cool for current sensing .... (the modules typically cost the same or less than the ICs by themselves, LoL).

Cheers!

Fish

Still has the analog problem requiring averaging.

Whereas the INA219 module is digital I2c.
 

Attachments

  • INA219.jpg
    INA219.jpg
    33.6 KB · Views: 2
Top