Introduction: Interfacing 4-20mA Current Loop Sensors With Arduino

About: Hardware design engineer

Reading 4-20mA current loop sensors using Arduino is much easier than you might think. Follow this simple guide and we will show you a few tips to make it fast and easy.

4-20mA current loop is most common and widely used communication method in an industrial environment. This 4-20mA current loop interface is also known as 2 wire interface technology. Despite being one of the oldest industry standards a lot of users have difficulty understanding the working of this technology. This 4-20mA current loop technology is used in temperature sensors, pressure sensors, current sensors, distance sensors, magnetic field sensors and much more. A typical 4-20mA current loop setup contains 3 things power supply — Most of the devices work at 24V DC but there are other voltage standards available as well4-20mA current loop sensor — this is the device which works as 4-20mA standard. for example, it could be a temperature sensor which gives the temperature value in the form of 4-20mA4-20mA current loop receiver — this is the device which will be used for readings 4-20mA current loop signal and will convert into digital or real-world valuesHow two wire or 4-20mA current loop worksThe 4-20mA current loop output devices give data output in the form of current consumption, to measure the change in the current we will need to put the correct receiver circuit in the series. so, for example, let’s say you have a pressure sensor which works at 4-20mA current loop principle and it is capable of measuring 0-50psi. so when you connect the 4-20mA current receiver circuit in the series and read the sensor it will read 4ma when the pressure is 0 psi and it will read 20mA when the pressure is 50 psi. This conversion will be a linear conversion, so you will be able to calculate the real pressure value at any given point. This 4-20mA current loop method is really popular in automation and sensing industry due to high reliability, easy installation, fewer components, and wires can be long. 4-20mA receiver devices could be really expensive but it can be done at a much lower cost using ncd.io 4-20mA current loop receiver boards.

Step 1: Hardware

1. ncd.io 4-20mA current receiver Board

2. Arduino i2c shield

The 4-20mA current loop receiver board has a 16 bit ADC, whit this high-resolution ADC you can get the best possible readings from your sensor. this board works over i2c communication, so using this board is really easy. it has one address bit, so you can connect up to two of these boards with one i2c master. The board has a voltage boost circuit and usages INA196 to monitor the current values. If you are looking for a high accuracy low-cost 4-20mA current loop receiver boards, this is your board.

To set up the hardware you will need to connect the Arduino to the i2c shield and use an i2c cable to connect 4-20mA current loop receiver board with Arduino i2c shield.

Step 2: Arduino 4-20mA Current Loop Code

The complete code can be found here

Interfacing 4-20mA current loop with Arduino

When the loop simulator is not connected to the receiver board, the Arduino will read 0mA, this is also used to detect is the sensor wiring is broken. This is one of most important thing you will need to understand while reading 4-20mA current loop sensors.
Step 2. The loop simulator has two probes, the black probe is named as Ext.PS+ and the red probe is named as PLC input. In our setup, we will connect the black probe to in IN1 terminal on the 4-20mA receiver board and the red probe to gnd. This is very important if you make the wrong connection it could damage your 4-20mA current loop receiver board. Once you have the correct connection the 4-20mA current loop board will start readings 4-20mA current loop signal. By default, the loop simulator will be set at 4mA and when you connect to Arduino, it will read 4mA

Step 3: Arduino Sample Code

/*       This code can be used to read 4-20mA signal using ncd 4-20mA current loop board and arduino.     

  this 4-20mA current loop board comes with 1,2,3,4 channels and 16 bit resolution

        Distributed with a free-will license.  

      Use it any way you want, profit or free, provided it fits in the licenses of its associated works. 

       ADS1115        This code is designed to work with the ADS1115_I2CADC I2C Mini Module available from ControlEverything.com.

         https://www.controleverything.com/content/Analog-... 

#include 

#include  

ADS1115 ads; 

void setup(void) {   

 Serial.begin(9600);     // The address can be changed making the option of connecting multiple devices    

ads.getAddr_ADS1115(ADS1115_DEFAULT_ADDRESS);   

// 0x48, 1001 000 (ADDR = GND)    

// ads.getAddr_ADS1115(ADS1115_VDD_ADDRESS);    // 0x49, 1001 001 (ADDR = VDD)    

// ads.getAddr_ADS1115(ADS1115_SDA_ADDRESS);    // 0x4A, 1001 010 (ADDR = SDA)    

// ads.getAddr_ADS1115(ADS1115_SCL_ADDRESS);    // 0x4B, 1001 011 (ADDR = SCL)     

// The ADC gain (PGA), Device operating mode, Data rate    

// can be changed via the following functions     ads.setGain(GAIN_TWO);          

// 2x gain   +/- 2.048V  1 bit = 0.0625mV (default)    

//ads.setGain(GAIN_TWOTHIRDS);  

// 2/3x gain +/- 6.144V  1 bit = 0.1875mV    

// ads.setGain(GAIN_ONE);       

// 1x gain   +/- 4.096V  1 bit = 0.125mV    

// ads.setGain(GAIN_FOUR);      

// 4x gain   +/- 1.024V  1 bit = 0.03125mV    

// ads.setGain(GAIN_EIGHT);     

// 8x gain   +/- 0.512V  1 bit = 0.015625mV    

// ads.setGain(GAIN_SIXTEEN);   

// 16x gain  +/- 0.256V  1 bit = 0.0078125mV     

ads.setMode(MODE_CONTIN);       // Continuous conversion mode  

  // ads.setMode(MODE_SINGLE);    

// Power-down single-shot mode (default)     

ads.setRate(RATE_128);          

// 128SPS (default)   

 // ads.setRate(RATE_8);       

  // 8SPS    // ads.setRate(RATE_16);        // 16SPS   

 // ads.setRate(RATE_32);        // 32SPS    // ads.setRate(RATE_64);        // 64SPS    // ads.setRate(RATE_250);       // 250SPS    // ads.setRate(RATE_475);       // 475SPS    // ads.setRate(RATE_860);       // 860SPS     ads.setOSMode(OSMODE_SINGLE);   // Set to start a single-conversion     ads.begin();} void loop(void) {    byte error;    int8_t address;     address = ads.ads_i2cAddress;    // The i2c_scanner uses the return value of    // the Write.endTransmisstion to see if    // a device did acknowledge to the address.    Wire.beginTransmission(address);    error = Wire.endTransmission();    if (error == 0)    {        int16_t adc0, adc1, adc2, adc3;         Serial.println("Getting Single-Ended Readings from AIN0..3");        Serial.println(" ");        adc0 = ads.Measure_SingleEnded(0);        Serial.print("Digital Value of Analog Input at Channel 1: ");        Serial.println(adc0);        float mACurrent = adc0 * 0.000628;        Serial.print("Current Loop Input at Channel 1: ");        Serial.println(mACurrent,3);//        adc1 = ads.Measure_SingleEnded(1);//        Serial.print("Digital Value of Analog Input at Channel 2: ");//        Serial.println(adc1);//        adc2 = ads.Measure_SingleEnded(2);//        Serial.print("Digital Value of Analog Input at Channel 3: ");//        Serial.println(adc2);//        adc3 = ads.Measure_SingleEnded(3);//        Serial.print("Digital Value of Analog Input at Channel 4: ");//        Serial.println(adc3);//        Serial.println(" ");//        Serial.println("        ***************************        ");//        Serial.println(" ");    }    else    {        Serial.println("ADS1115 Disconnected!");        Serial.println(" ");        Serial.println("        ************        ");        Serial.println(" ");    }     delay(1000);

}