“Analog read of 4-20mA”
This example uses the Adafruit_ADS1X15.h library. and use an basic example for range process variable
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1015 ads; /* Use this for the 12-bit version */
uint16_t lectura; //stores always in uint16 for complete resolution
//if you stores in int16 or float, takes one bit for the sign, and first we need to handle the reading
void setup(void)
{
Serial.begin(9600);
Serial.println("Hello!");
Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
while (1);
}
}
void loop(void)
{
lectura = ads.readADC_SingleEnded(0);
float Process_mA=(map(lectura,0,65535,4000,20000))/1000; //for obtain the 4-20mA
//Example for variable ranging, in temperature 0 to 400°C
//Pv=[(Pv high-Pv low)/(I high-I low)]*(I-I low)+Pv low
float Temperature=(((400.000-0.000)/(20.000-4.000))*(Process_mA-4.000)+1.400);
// the last 1.400 is a gain for error in readings, you may need a temperature reference patron to adding, so the 1.400 can be deleted
}