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

Have you googled: :goggles:
arduino 4-20ma loop

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

Tom… :grinning: :+1: :coffee: :australia:

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… :grinning: :+1: :coffee: :australia:

#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 = analogRead(A0);

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… :grinning: :+1: :coffee: :australia:

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 = analogRead(A0);

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.

Thanks in advance.

Dear,

I am waiting for your reply

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… :grinning: :+1: :coffee: :australia:

You need to subtract 250Ω from 1200 and 6000, 950 and 5750.