# How to measure 4-20 mA current in Arduino uno

Hello everyone,
I am doing one arduino base project in which I have to read 4-20 mA signal from two different potentiometers which is power from 24 vdc supply, compare them and send a signal to 2 channels relay board. If first signal from potentiometer is greater by 0.16 mA or more than second then 1st realy will energize if second signal from potentiometer is greater than first signal by 0.16 mA or more then second relay will energize.

Now I am facing issue to read 4-20 mA on arduino without any external module. I don't know issue is in coding or circuit. Can you help me

Why no external module ?
What does that mean exactly ?

Ohmâ€™s law tells you about a relationship between current and voltage, and all you can measure with a bare Arduino is voltage.

Maybe you should describe the issue.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled â€śHow to use this Forumâ€ť.
OR

arduino 4-20ma loop

There are many tutorials and explanations on how to interpret a loop current circuit with a voltage measuring input.

Tomâ€¦

please check up this file. if i am wrong then please correct me

Hi,
Yes, that will give you the results you need.
Have you written any code?

Tomâ€¦

#include <LiquidCrystal.h>
float Vacross,Iamp = 0;
const int Resistance = 250;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
}

void loop() {

Vacross = (Vacross * 5.0) / 1023.0;
Iamp = (Vacross * 1000) / Resistance;

lcd.setCursor(0, 0);
lcd.print("Current = ");
lcd.print(Iamp);
lcd.print(â€śmAâ€ť);
delay(1000);
}

Dear Tom,

Please check up above code, i think code is correct but i am not getting correct output from the same. please help me.

You still havenâ€™t told us what the issue is.

Please edit your post that contains the code, next select the code and click < / >. Next save the post.

Some tips:

1. Do the LiquidCrystal examples give output on the LCD?
2. Use serial prints for debugging; doe you get the expected results?

Hi,
Iâ€™m not sure what your problem is but see if this helps.
From this;

``Iamp = (Vacross * 1000) / Resistance;``

To;

``Iamp = (Vacross * 1000.0) / (float)Resistance;``

Tomâ€¦

when i am selecting 1200 ohm resistance in variable resister then i am getting 16.48 mA on display but i should get 20 mA and when i am selecting 6000 ohm resistance in variable resister then i am getting 3.83 mA on display but i should get 4 mA. please check up my below code and attached circuit diagram and correct me, where i wrong

.

#include <LiquidCrystal.h>
float Vacross,Iamp = 0;
const int Shunt_Res = 250;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
}

void loop() {

Vacross = (Vacross * 5.0) / 1023.0;
Iamp = (Vacross * 1000) / Shunt_Res;

lcd.setCursor(0, 0);
lcd.print("Current = ");
lcd.print(Iamp);
lcd.print(â€śmAâ€ť);
delay(1000);
}

You have a voltage divider; so the total resistance is 250 + 1200 = 1450 Ohm. And 24V/1450 Ohm is a current of 16.55mA, not 20mA.

1 Like

Thank you so much for your correct suggestion. i am beginner in electronics, can you suggest me what i have to change in our circuit and code to read 4-20 mA.

Dear,

I hope you are not expecting the 4-20ma circuit to be exactly 4 or 20ma! Those are the maximums and you will need to calibrate your circuit to match whatever is controlling the 4-20ma signal.
Paul

This is the formula that you is used to determine the voltage over the shunt resistor; use it if the power supply and the pot are the real source (and not a simulation of a real source 4-20mA source).

``````Vshunt = 24 * Rshunt / (Rpot + Rshunt)
``````

You can shuffle it around to calculate Rpot based on Vshunt and from there calculate the current.

I think that part of the problem is that a voltage source with a resistor in series is not a current source. The amount of current that flows will depend on the load on the line.

To read a 4 to 20 mA input you need a resistor that has a voltage drop of 5V at 20 mA. I think thatâ€™s a 250 Ohm resistor.
That would read 5V at 20ma and 1V at 4mA. Unfortunately, 250 Ohms is higher that 0 Ohms so using a 24V supply and 1200 to 6000 Ohms of series resistance will give you 4.13V to 0.96V since your â€ś20 mAâ€ť wonâ€™t be 20 mA and your â€ś4 mAâ€ť wonâ€™t be 4 mA.

You have a very good chance of killing your Arduino by putting more than 5.5V on A0, put a 910â„¦ resistor between 24V+ and the pot. 910â„¦ + 250â„¦ = 1160â„¦, 24V / 1160â„¦ = 20.7mA, voltage across 250â„¦ resistor will be 5.17V.

Hi;

You should be using an ammeter in series with your circuit to make sure you have 4 - 20mA, just calculating will not necessarily be accurate enough.

Tomâ€¦

You need to subtract 250â„¦ from 1200 and 6000, 950 and 5750.