Connect with us

Current sensing using Arduino

Discussion in 'Microcontrollers, Programming and IoT' started by Karthik rajagopal, Apr 1, 2020.

Scroll to continue with content
  1. Karthik rajagopal

    Karthik rajagopal

    227
    7
    May 9, 2016
    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.
    
    }
     

    Attached Files:

    Last edited by a moderator: Apr 2, 2020
  2. Bluejets

    Bluejets

    4,257
    907
    Oct 5, 2014
    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 likes this.
  3. Karthik rajagopal

    Karthik rajagopal

    227
    7
    May 9, 2016
    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 ?
     
  4. Bluejets

    Bluejets

    4,257
    907
    Oct 5, 2014
    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.
     
  5. Harald Kapp

    Harald Kapp Moderator Moderator

    10,551
    2,350
    Nov 17, 2011
    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.
     
  6. Karthik rajagopal

    Karthik rajagopal

    227
    7
    May 9, 2016
    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 .
     
  7. Karthik rajagopal

    Karthik rajagopal

    227
    7
    May 9, 2016
    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.
     
  8. bertus

    bertus Moderator

    1,145
    433
    Nov 8, 2019
  9. Fish4Fun

    Fish4Fun So long, and Thanks for all the Fish!

    464
    105
    Aug 27, 2013
  10. Bluejets

    Bluejets

    4,257
    907
    Oct 5, 2014
    Still has the analog problem requiring averaging.

    Whereas the INA219 module is digital I2c.
     

    Attached Files:

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-