4-20mA Sensor

IND.I/O demo video

Loic De Buck

A quick demo video of IND.I/O's analog features..

One of the unique features of the Industruino IND.I/O kit is that it has both inputs as well as outputs that support 4-20mA and 0-10V levels. We've made a small video to show you how you can read a PT100 temperature sensor via a 4-20mA transmitter and stream this data to the cloud for remote monitoring.
 

 

 

Contrary to other products on the market, where you need to use jumpers to select between 4-20mA and 0-10V modes, Industruino can switch these modes automatically, all under software control. By simply defining "Indio.analogReadMode(1, mA);" or "Indio.analogReadMode(1, V10);" in your Setup() routine the hardware is configured for the right mode.


Please go to our Youtube channel and subscribe!

Below is the Arduino sketch which was used for the first part of the demo (showing analog reading on LCD):

/* Indio Library for Industruino - wwww.industruino.com
This library enables communication with the Industruino IND.I/O Baseboard.
The IND.I/O Baseboard has 8CH of 24V digital I/O (6.5-32V supported), 4CH 0-10V/4-20mA ADC, 2CH 0-10V/4-20mA DAC, RS485 transceiver.

WARNING!: PLEASE BE VERY CAREFUL WHEN CONNECTING PERIPHERALS TO YOUR IND.I/O AND CONFIGURING THE DIRECTION OF THE I/O.
          THE FAILURE MODE OF A 24V SHORTED CONNECTION IS MUCH MORE SPECTACULAR THAN WHEN WORKING AT 5V. 

Please find the calibration data array inside the Indio.cpp library file, together with an explanation on how to perform the calibration. 
Library is preloaded with calibration data but characterisctics are board specific thus reading with standard cal. data might be off.

This example sketch will read analog input channel 1 in mA mode and display the result on the LCD.

*/

#include <Indio.h> //load Indio library
#include <Class_define.h> //required for Indio library
#include <Wire.h> //i2c library required for Indio
#include <UC1701.h> //load LCD library

float sensorVal1; //variable to hold analog reading
static UC1701 lcd; 

void setup()
{
  pinMode(13, OUTPUT); //Set LCD backlight pin as output
  analogWrite(13, 240); //set LCD backlight intensity, 0 is full brightness, 255 is off.
  lcd.begin(); //start LCD
  
  Indio.setADCResolution(16); // Set the ADC resolution. Choices are 12bit@240SPS, 14bit@60SPS, 16bit@15SPS and 18bit@3.75SPS.

  Indio.analogReadMode(1, mA); // Set Analog-In CH1 to mA mode (0-20mA).
  Indio.analogReadMode(2, mA); // Set Analog-In CH2 to mA mode (0-20mA).
  Indio.analogReadMode(3, mA); // Set Analog-In CH3 to mA mode (0-20mA).
  Indio.analogReadMode(4, mA); // Set Analog-In CH4 to mA mode (0-20mA).

void loop()
{

  sensorVal1=Indio.analogRead(1); //Read Analog-In CH1 (output depending on selected mode)
  lcd.setCursor(40, 3); //set LCD cursor position to middle of screen, column 40, row 3.
  lcd.print("    "); //Add some "  " space
  lcd.setCursor(40, 3);
  lcd.print(sensorVal1, 3); //Print data
  lcd.print(" mA"); //Print unit
  delay(200);
}

And finally this is the Arduino sketch which was used for the second part of the demo (graph plotting on LCD and streaming over Ethernet):

typedef uint8_t SOCKET;
#include <SPI.h>
#include <Ethernet.h>
#define W5500_ETHERNET_SHIELD

#include <Indio.h> //load Indio library
#include <Class_define.h> //required for Indio library
#include <Wire.h> //i2c library required for Indio
#include <UC1701.h> //load LCD library
static UC1701 lcd;

static const byte backLightPin = 13; //LCD backlight pin definition

// The dimensions of the LCD (in pixels)...
static const byte LCD_WIDTH = 128;
static const byte LCD_HEIGHT = 64;

// The number of lines for the temperature chart...
static const byte CHART_HEIGHT = 5;

// A custom "degrees" symbol...
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };

// A bitmap graphic (10x2) of a thermometer...
static const byte THERMO_WIDTH = 10;
static const byte THERMO_HEIGHT = 2;
static const byte thermometer[] = { 0x00, 0x00, 0x48, 0xfe, 0x01, 0xfe, 0x00, 0x02, 0x05, 0x02,
                                    0x00, 0x00, 0x62, 0xff, 0xfe, 0xff, 0x60, 0x00, 0x00, 0x00};

float temp;
float mAValue;
float sensorVal1, sensorVal2, sensorVal3, sensorVal4; //variables to hold your sensor data
  
  
  byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  
  // fill in an available IP address on your network here,
  IPAddress ip(192, 168, 1, 130);  
 char server[] = "emoncms.org"; // name address for emoncms.org
//IPAddress server(213, 138, 101, 177); // numeric IP for emoncms.org (no DNS)

String apikey = "01278441cb103fca172410a5e1061a29"; //change this to your api key (can be found on the API help page of your EmonCMS.org account).
int node = 0; //if 0, not used

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 5000; // delay between updates, in milliseconds

 
 
EthernetClient client; //Ethernet client mode

void setup()
{
  pinMode(10, OUTPUT);    
pinMode(6, OUTPUT);     
pinMode(4, OUTPUT);     
digitalWrite(10, LOW);
digitalWrite(6, HIGH);
digitalWrite(4, HIGH);

  pinMode(backLightPin, OUTPUT); //Set LCD backlight pin as output
  analogWrite(backLightPin, 240); //set LCD backlight intensity, 0 is full brightness, 255 is off.
  lcd.begin(); //start LCD
  lcd.createChar(DEGREES_CHAR, degrees_glyph); //create thermometer glyph
  Indio.setADCResolution(16); // Set the ADC resolution. Choices are 12bit@240SPS, 14bit@60SPS, 16bit@15SPS and 18bit@3.75SPS.
  Indio.analogReadMode(1, mA); // Set Analog-In CH1 to mA mode (0-20mA).
  Indio.analogReadMode(2, mA); // Set Analog-In CH2 to mA mode (0-20mA).
  Indio.analogReadMode(3, mA); // Set Analog-In CH3 to mA mode (0-20mA).
  Indio.analogReadMode(4, mA); // Set Analog-In CH4 to mA mode (0-20mA).
  
delay(5000); //wait 5 seconds to make sure Ethernet is running.
 // Open serial communications
Serial.begin(9600);

  // start the Ethernet connection:
 if (Ethernet.begin(mac) == 0) {

    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac);

  }
  // give the Ethernet module a second to initialize:
  delay(1000);
  Serial.println("starting..");

  
 }

void loop()
{
   // Start beyond the edge of the screen...
  static byte xChart = LCD_WIDTH;

  // Read the temperature (in celsius)...
  mAValue = Indio.analogRead(2);
  temp = (mAValue*2); // convert mA to a temperature value (in celsius)...
  // Print the temperature (using the custom "degrees" symbol)...
  lcd.setCursor(0, 0); //set LCD cursor position to top right corner
  lcd.print("Temp: "); //print "Temp"
  lcd.print(temp, 1); //print the current temperature
  lcd.print(" \001C "); //print °C character

  // Draw the thermometer bitmap at the bottom left corner...
  lcd.setCursor(0, LCD_HEIGHT/8 - THERMO_HEIGHT);
  lcd.drawBitmap(thermometer, THERMO_WIDTH, THERMO_HEIGHT);

  // Wrap the chart's current position...
  if (xChart >= LCD_WIDTH) {
    xChart = THERMO_WIDTH + 2;
  }

  // Update the temperature chart...  
  lcd.setCursor(xChart, 1);
  lcd.drawColumn(CHART_HEIGHT, map(temp, 0, 45, 0, CHART_HEIGHT*8));  // ...clipped to the 0-45C range.
  lcd.drawColumn(CHART_HEIGHT, 0);         // ...with a clear marker to see the current chart position.
  
  xChart++;
 
  delay(500);
  
  
  
  //stream data to the internet every 5 seconds
    if ((millis() - lastConnectionTime > postingInterval)) { 
      sendData();
    }

lastConnected = client.connected();
}


//routine to post data to EmonCMS platform
void sendData() {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Connecting...");
    // send the HTTP GET request:
   client.print("GET /api/post?apikey=");
    client.print(apikey);
    if (node > 0) {
      client.print("&node=");
      client.print(node);
    }
    client.print("&json={temp"); //send first variable identifier
    client.print(":");
    client.print(temp); //send first variable content
    client.print(",mAValue:"); //send second variable identifier
    client.print(mAValue); //send second variable content
    client.println("} HTTP/1.1");
    client.println("Host:emoncms.org");
    client.println("User-Agent: Arduino-ethernet");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis(); 
    Serial.println("Disconnecting...");
    client.stop();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("Connection failed");
  }
}