You are using an unsupported browser!

Please upgrade your version of IE to at least 9, or use a modern browser such as Chrome or Firefox.

Predictive Maintenance and Machine Health Monitoring Using Losant and ncd.io Current Monitor

Predictive Maintenance and Machine health monitoring is one of the most critical and important parts of the automation industry. In an automation or production factory these machines work on an average 20 hours per day.  In modern automation, all these machines work together and stay in sync, so its very important that every single machine is healthy.  In the old days, the usual ways to monitor machine health was manual inspection and occasional temperature readings.  With modern day technology, we can monitor these machines 24-7 and analyze the health. By doing this we keep an eye on every single change the machine is going through. The machine health monitoring is also known as predictive maintenance.

Whats Predictive Maintenance and Machine Health Monitoring?

Predictive maintenance and machine health monitoring go side by side.  If we know whats going on with the machine, we can predict when it needs repair or the end of it’s useful life. By knowing these two things we can work on fixing the problem on a schedule without any operational down-time. There are quite a few ways we can monitor device or machine health and a send notification to a technician when a machine needs some attention.  There are few device which are used to connect machine health data:

  1. Temperature and Humidity Data Monitoring
  2. Current and Voltage Monitoring
  3. Vibration Monitoring

In this article, we will read current and publish the data on Losant.  Losant supports graphs, UI, notifications, and emails.  These features make it ideal for predictive maintenance analysis.  In this project, we will use the following hardware:

  1. 2 Channel AC Current Monitor 
  2. ncd.io ESP8266 Module

predictive maintains and machine health

On the software side we will use Arduino IDE to program the ESP8266 and will use Losat to display the data and plot the graphs.

Configuring Losant for Current Monitoring Applications

If you haven’t checked out our last article, we recommend reading the Getting Started with Losant and a NCD Temperature Humidity Sensor

In this article you can learn how to setup Losant to read any ncd.io hardware and display the data. Once you get to know the interface, you can easily connect any ncd hardware.  Here we will go through some basic steps:

  1. Click on dashboard and create a new dash board

Electric Pump Health Monitoring

 

2. Create a new device

3. Define the attributes

4. Generate the access key and the security key

Now we can work on writing ESP8266 code. This code can be found on github as well.

/**
 * Example for sending AC current data
 * to the cloud using the ncd.io ac current monit and ESP8266
 *
 * Copyright (c) 2016 Losant IoT. All rights reserved.
 * https://www.losant.com
 * hardware 
 * https://store.ncd.io/product/esp8266-iot-communication-module-with-integrated-usb/
 * https://store.ncd.io/product/sht25-humidity-and-temperature-sensor-%C2%B11-8rh-%C2%B10-2c-i2c-mini-module/
 * https://store.ncd.io/product/i2c-shield-for-particle-electron-or-particle-photon-with-outward-facing-5v-i2c-port/
 */
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <Losant.h>
#include <Wire.h>

#define Addr 0x2A /// i2c address of Current Monit
float current_ch1;
float current_ch2;
float current1;
float current2;

const char* ssid = "XX";
const char* password = "XX";

const char* LOSANT_DEVICE_ID = "XX";
const char* LOSANT_ACCESS_KEY = "XX";
const char* LOSANT_ACCESS_SECRET = "XX";
WiFiClientSecure wifiClient;

LosantDevice device(LOSANT_DEVICE_ID);

void connect() {

  // Connect to Wifi.
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  delay(500); 
  unsigned long wifiConnectStart = millis();

  while (WiFi.status() != WL_CONNECTED) {
    // Check to see if
    if (WiFi.status() == WL_CONNECT_FAILED) {
      Serial.println("Failed to connect to WIFI. Please verify credentials: ");
      Serial.println();
      Serial.print("SSID: ");
      Serial.println(ssid);
      Serial.print("Password: ");
      Serial.println(password);
      Serial.println();
    }

    delay(500);
    Serial.println("...");
    // Only try for 5 seconds.
    if(millis() - wifiConnectStart > 5000) {
      Serial.println("Failed to connect to WiFi");
      Serial.println("Please attempt to send updated configuration parameters.");
      return;
    }
  }

  Serial.println();
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  Serial.print("Authenticating Device...");
  HTTPClient http;
  http.begin("http://api.losant.com/auth/device");
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Accept", "application/json");
StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["deviceId"] = LOSANT_DEVICE_ID;
  root["key"] = LOSANT_ACCESS_KEY;
  root["secret"] = LOSANT_ACCESS_SECRET;
  String buffer;
  root.printTo(buffer);

  int httpCode = http.POST(buffer);

  if(httpCode > 0) {
      if(httpCode == HTTP_CODE_OK) {
          Serial.println("This device is authorized!");
      } else {
        Serial.println("Failed to authorize device to Losant.");
        if(httpCode == 400) {
          Serial.println("Validation error: The device ID, access key, or access secret is not in the proper format.");
        } else if(httpCode == 401) {
          Serial.println("Invalid credentials to Losant: Please double-check the device ID, access key, and access secret.");
        } else {
           Serial.println("Unknown response from API");
        }
      }
    } else {
        Serial.println("Failed to connect to Losant API.");

   }

  http.end();

  // Connect to Losant.
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while(!device.connected()) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("Connected!");
  Serial.println();
  Serial.println("This device is now ready for use!");
}

void setup() {
  Serial.begin(9600);
  Serial.setTimeout(2000);
  Wire.begin(12, 14);
  // Wait for serial to initialize.
  while(!Serial) { }

  Serial.println("Device Started");
  Serial.println("-------------------------------------");
  Serial.println("AC PUMP HEALTH MONITOR");
  Serial.println("-------------------------------------");

  connect();
}
void report(double current_ch1, double current_ch2) {
  StaticJsonBuffer<500> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["current_ch1"] = current_ch1;
  Serial.println("     ");
  root["current_ch2"] = current_ch2;
  device.sendState(root);
  Serial.println("Reported!");
}

int timeSinceLastRead = 0;
void loop() {
   bool toReconnect = false;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Disconnected from WiFi");
    toReconnect = true;
  }

  if (!device.connected()) {
    Serial.println("Disconnected from MQTT");
    Serial.println(device.mqttClient.state());
    toReconnect = true;
  }

  if (toReconnect) {
    connect();
  }

  device.loop();

//////////////i2c starts over here /////////////////
  // Report every 2 seconds.
    // Start I2C Transmission
     // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Command header byte-1
    Wire.write(0x92);
    // Command header byte-2
    Wire.write(0x6A);
    // Command 1
    Wire.write(0x01);
    // Start Channel No.
    Wire.write(0x01);
    // End Channel No.
    Wire.write(0x01);
    // Reserved
    Wire.write(0x00);
    // Reserved
    Wire.write(0x00);
    // CheckSum
    Wire.write((0x92 + 0x6A + 0x01 + 0x01 + 0x01 + 0x00 + 0x00) & 0xFF);
    // Stop I2C Transmission
    Wire.endTransmission();
    delay(50);

    // Request 3 bytes of data
    Wire.requestFrom(Addr, 3);

    // Read 3 bytes of data
    // msb1, msb, lsb
    int msb1 = Wire.read();
    int msb = Wire.read();
    int lsb = Wire.read();
    double current_ch1 = (msb1 * 65536) + (msb * 256) + lsb;
   // Serial.print(current_ch1);
    // Convert the data to ampere
    current_ch1 = current_ch1 / 1000;
    delay(100);

     Wire.beginTransmission(Addr);
    // Command header byte-1
    Wire.write(0x92);
    // Command header byte-2
    Wire.write(0x6A);
    // Command 1
    Wire.write(0x01);
    // Start Channel No.
    Wire.write(0x02);
    // End Channel No.
    Wire.write(0x02);
    // Reserved
    Wire.write(0x00);
    // Reserved
    Wire.write(0x00);
    // CheckSum
    Wire.write((0x92 + 0x6A + 0x01 + 0x02 + 0x02 + 0x00 + 0x00) & 0xFF);
    // Stop I2C Transmission
    Wire.endTransmission();
    delay(50);

    // Request 3 bytes of data
    Wire.requestFrom(Addr, 3);

    // Read 3 bytes of data
    // msb1, msb, lsb
    int msb1_1 = Wire.read();
    int msb_1 = Wire.read();
    int lsb_1 = Wire.read();
    double current_ch2 = (msb1_1 * 65536) + (msb_1 * 256) + lsb_1;
    //Serial.print(current_ch2);
    // Convert the data to ampere
    current_ch2 = current_ch2 / 1000;
    delay(100);
//////////////i2c ends over here /////////////////

  if(timeSinceLastRead > 2000) {
    Serial.print("Current On Channel One ");
    Serial.print(current1);
    Serial.print(" %t");
    Serial.print("Current On Channel Two ");
    Serial.print(current2);
    report(current_ch1, current_ch2);

    timeSinceLastRead = 0;
  }
  delay(100);
  timeSinceLastRead += 100;
}

Arduino Output on the Serial Monitor

iot predictive maintenance

Predictive Maintenance and Machine Health Monitoring

 

AC current Data when the device is off:

machine health monitoring

 

AC Current data when the device is power on:

AC pump health Monitoring

 

Once data has reached Losant, you can trigger events, send emails, push notifications, and much more.

There are so many things which can be done by monitoring the power consumption data. When a device is having any issues, the first thing it will show is a change in the power consumption (in most cases).  Using this application, we can trigger and event or an alarm if we see any irregular changes in power consumption. The same setup can be used to trigger an alarm when a device goes offline unexpectedly. The same setup can be used to count the number of hours machines have been in operation and number of hours a machine has been in idle state.  Using these data, we can extrapolate an extended life span based past experiences with similar equipment.

 

 

 

 

ControlAnything.com and ControlEverything Site Migration Notes

©2018 National Control Devices, LLC

ncd.io

Made in the USA
5 Year Warranty
Free Shipping on orders over $100
Free Shipping on orders over $100

To learn something new, take the path that you took yesterday. ~John Burroughs

*

Log in with your credentials

or    

Forgot your details?

Create Account