The 4-20 mA Current Loop Board is one of the most robust sensor signaling standard. Current loops are ideal for data transmission because of their inherent insensitivity to electrical noise. In a 4-20 mA current loop, all the signaling current flows through all components; the same current flows even if the wire terminations are less than perfect. All the components in the loop drop voltage due to the signaling current flowing through them. The signaling current is not affected by these voltage drops as long as the power supply voltage is greater than the sum of the voltage drops around the loop at the maximum signaling current of 20 mA.
Transmitting sensor information via a current loop is particularly useful when the information has to be sent to a remote location over long distances (500 meters, or more). The loop operation is straightforward: a sensor output voltage is first converted to a proportional current, with 4 mA normally representing the sensor zero-level output, and 20 mA representing the sensor full-scale output. Then, a receiver at the remote end converts the 4-20 mA current back into a voltage which in turn can be further processed by a computer or display module.
4-20 mA Current Loop | ||||||||
Type | Analog | |||||||
Media | Twisted pair | |||||||
No. of channels | 4 | |||||||
Distance | 900 m | |||||||
Supply | 5-24V |
This list includes some of the more common uses of the standard:
The 4-20 mA Board has 4 input channels which allow converting signals that come with this industrial standard. This shield works with type 2, 3 and 4 current transmitters. Each channel can be configured for working with these types of connections. If the jumper is retired, the receptor will be configured as float (type 4 connection).
The 4-20 mA Board includes a 24 V output that can be used to supply sensors. The majority of 4-20 mA sensors work in the 9-24 V range. Before connecting a sensor to the 4-20 mA Board, you must be sure that the sensor is in this range of power supply. If you are going to use all channels, the consumption of the board will increase. Is important to know, that 4-20 mA Board is not designed to supply industrial devices such as PLC's and thermostats.
Get the Raspberry Pi to Arduino shields connection bridge
Warnings:
The 4-20 mA Board counts with a C++ library that lets you manage it in a simple way. This library offers an simple-to-use open source system.
In order to ensure the same code is compatible in all the platforms (Arduino, Raspberry Pi and Intel Galileo) we use the ArduPi libraries which allows developers to use the same code. Detailed info can be found here:
The 4-20 mA Board includes a high level library functions for an easy manage. Before start using this functions you should download the library. This zip includes all the files needed in several folders.
Download the 4-20 mA library for Arduino
Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be the .cpp files, .h files and often a keywords.txt file, examples folder, and other files required by the library.
To install the library, first quit the Arduino application. Then uncompress the ZIP file containing the library. For installing libraries , uncompress zip file. It should contain three folder called _4_20mA. Drag these folders into this folder (your libraries folder). Under Windows, it will likely be called "My Documents\Arduino\libraries". For Mac users, it will likely be called "Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook.
The library won't work if you put the .cpp and .h files directly into the libraries folder or if they're nested in an extra folder. Restart the Arduino application. Make sure the new library appears in the Sketch->Import Library menu item of the software.
The 4-20 mA library for Raspberry Pi requires the ArduPi library and both libraries should be in the same path.
Download the 4-20 mA library for Raspberry Pi
Creating a program that uses the library is as simple as putting your code in this template where it says "your Arduino code here"
//Include 4-20 mA library (it includes arduPi) /******************************************************** * IF YOUR ARDUINO CODE HAS OTHER FUNCTIONS APART FROM * * setup() AND loop() YOU MUST DECLARE THEM HERE * * ******************************************************/ /************************* * YOUR ARDUINO CODE HERE * *************************/ int main (){ setup(); while(1) { loop(); } return(0); }
Compilation of the program can be done in two ways:
g++ -c arduPi.cpp -o arduPi.o g++ -c currentLoop.cpp -o currentLoop.o g++ -lpthread -lrt user-currentLoop-app.cpp arduPi.o currentLoop.o -o user-currentLoop-app
g++ -lpthread -lrt user-currentLoop-app.cpp arduPi.cpp currentLoop.cpp -o user-currentLoop-app
Executing your program is as simple as doing:
sudo ./user-currentLoop-app
The 4-20 mA Board includes a high level library functions for an easy manage. Before start using this functions you should download the library. This zip includes all the files needed in several folders.
Download the 4-20 mA library for Intel Galileo
Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be the .cpp files, .h files and often a keywords.txt file, examples folder, and other files required by the library.
To install the library, first quit the Arduino application. Then uncompress the ZIP file containing the library. For installing libraries , uncompress zip file. It should contain three folder called _4_20mA. Drag these folders into this folder (your libraries folder). Under Windows, it will likely be called "My Documents\Arduino\libraries". For Mac users, it will likely be called "Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook.
The library won't work if you put the .cpp and .h files directly into the libraries folder or if they're nested in an extra folder. Restart the Arduino application. Make sure the new library appears in the Sketch->Import Library menu item of the software.
General functions
// The constructor of the class currentLoop(); // Powers ON the 4-20 mA 24V Supply void ON(void); // Powers OFF the 4-20 mA 24V Supply void OFF(void); // Get the sensor value in integer format int readChannel(uint8_t channel); // Get the sensor value as a voltage float readVoltage(uint8_t channel); // Get the sensor value as a current in mA float readCurrent(uint8_t channel); // Get the sensor value as a current in mA and introduce // a correction offSet factor float readCurrent(uint8_t channel ,float offSet); // It checks if the current loop is well connected uint8_t isConnected(uint8_t channel);
The majority of 4-20 mA sensors work in the 9-24 V range. Before connecting a sensor to the 4-20 mA Board, you must be sure that the sensor is in this range of power supply. If you are going to use all channels, the consumption of the board will increase. Arduino board can be supplied with an external power supply. The recommended input voltage is 7-12 V. If you need more voltage, you can use the DC-DC converter integrated in the 4-20 mA Board. This converter provides a 24 V out, and can be used to supply 4-20 mA sensors. Is important to know, that the 4-20 mA board is not designed to supply industrial devices such as PLC's and thermostats.
To get this 24 V, is necessary to supply the Arduino board with a minimum voltage of 9 volts.
You can use the functions ON()/OFF() to enable/disable the 24 V output.
It is advisable to check that the DC-DC converter is working properly. You can measure the output voltage using a multimeter.
In this part of the tutorial we are going to connect a 4-20 mA sensor and supply it with 24 V output. This sensor is type 2 transmitter. Type 2 transmitters are energized by the current loop, where the supply voltage is included in the receptor. The transmitter is floating and the ground is in the receptor, so is necessary to put the connect the corresponding jumper.
Upload the example code included with the library
Arduino / Intel Galileo
/* * 4-20 mA Sensor Board * * Copyright (C) Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * a * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * * Version: 1.0 * Design: David Gascón * Implementation: Ahmad Saad */ // Include this library for using current loop functions. #include <currentLoop.h > #define CHANNEL CHANNEL4 void setup() { // Switch ON the 24V DC-DC converter sensorBoard.ON(); // Inits the Serial for viewing data in the serial monitor Serial.begin(115200); delay(100); Serial.println("Arduino 4-20mA board switched ON..."); } void loop() { // Get the sensor value in int format (0-1023) int value = sensorBoard.readChannel(CHANNEL); Serial.print("Int value read from channel 1 : "); Serial.println(value); // Get the sensor value as a voltage in Volts float voltage = sensorBoard.readVoltage(CHANNEL); Serial.print("Voltage value rad from channel 1 : "); Serial.print(voltage); Serial.println("V"); // Get the sensor value as a curren in mA float current = sensorBoard.readCurrent(CHANNEL); Serial.print("Current value read from channel 1 : "); Serial.print(current); Serial.println("mA"); Serial.println("***************************************"); Serial.print("\n"); delay(2000); }
Raspberry Pi
/* * 4-20 mA Sensor Board * * Copyright (C) Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * a * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * * Version: 1.0 * Design: David Gascón * Implementation: Ahmad Saad */ //Include this library for using current loop functions. #include "currentLoop.h" #define CHANNEL CHANNEL4 void setup() { //Inits the Serial for viewing data in the serial monitor. //Switch ON the 24V DC-DC converter sensorBoard.ON(); delay(100); printf("Arduino 4-20 mA board switched ON..."); printf("\n"); } void loop() { if (sensorBoard.isConnected(CHANNEL)) { // Get the sensor value in int format (0-1023). int value = sensorBoard.readChannel(CHANNEL); printf("Int value read from channel 1 : %d",value); printf("\n"); // Get the sensor value as a voltage in Volts. float voltage = sensorBoard.readVoltage(CHANNEL); printf("Voltage value rad from channel 1 : %f",voltage); printf(" V"); printf("\n"); // Get the sensor value as a curren in mA. float current = sensorBoard.readCurrent(CHANNEL); printf("Current value read from channel 1 : %f",current); printf(" mA"); printf("\n"); printf("***************************************"); printf("\n"); } else { printf("The sensor is not connected..."); printf("\n"); } //Delay after reading. delay(2500); } int main (){ setup(); while(1){ loop(); } return (0); }
In the serial monitor you should be that the sensor is transmitting 4mA. The 4mA "bottom of span" signal allows the receiver to detect a broken wire or failed instrument. The constant-current feature of a current loop cancels out voltage drop errors due to long wiring runs (of course this would also be true if you selected different current values for zero and span).
If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.
Know more at:
Get the Starter Kits at: