Skip to main content

Environmental sensor Kit - Real-world application in an Industrial environment

This project scope is to monitor environmental data including Motor Data, Air Quality Data and transmit it to a local view screen as well as to the cloud where it can be used for machine learning and alarms.

Industrial Control Cabinet

Materials Used

Programs Used

The Project

In the world of IoT (Internet of Things), Smart Cities, Smart Homes, and Smart Buildings in General there are some limitations, design problems and Information visualization issues. We will look at some of these in this project.

I work in the electrical field at present as a controls electrician which allows me to actually use the knowledge of this trade to overcome and identify some interesting monitoring and control scenarios. There is a big hype and a large movement for smart cities and I figured that maybe we could start a little bit smaller and deal with a simple building, in general, to ensure that it is running efficiently and safely.

My project is a non-intrusive design which means that at present it will control nothing but will monitor everything. My plan is to monitor a 2 Boiler system in a boiler room. with air handling systems, HOVs, Pumps and an air quality monitor.

The basic system is when a boiler is running there is a basic control setup that calls for the boiler to run and it is supposed to run for a period of 4-5 hours then the other boiler runs for 4-5 hours. Which in theory is great until a boiler actually fails. which becomes a major problem when it is -40 degrees outside and it takes little time for the cold to enter a building and start causing havoc. Here are 4 main reasons why a boiler would fail,

  1. Soot blocking the blocked vent sensor
  2. Fuel Problems (water in the fuel), (Air in the Fuel Lines), (No fuel)
  3. Low Glycol In the system
  4. High Temperature

When the boiler fails there are no alarms, No callouts, No one would even notice until the second boiler fails. This is the Achilles heel of the system. I have done the controls of around 20 of these residential systems in the last 2 years and this system works great until the problems with the boilers come up. There are external alarms outside for the fire alarm system. Indication Lights on the outside of the building for the sewage pump outs and water fills but nothing for the condition of the building itself.

This is about to change.

I decided on a junction box that was in hindsight probably too big for a basic project but wanted some extra room for a future power monitoring Setup and now I can use the space for some extra power plugs to run the Raspberry Pi and the monitor.

As some people figured out, working with Python is an acquired taste and I am not so good at it so I went another route. I decided to Just use the Raw board and not the fancy LCD screen they provided and used C++ and Arduino code to accomplish the same tasks but with my own GUI using XCode and Node Red.

The First thing I did was to figure out what the pinouts were on the board. And ran an I2C Scanner program to make sure I was seeing all the necessary components:

9:38:56.691 ->
09:38:57.510 -> Scanning...
09:38:57.510 -> I2C device found at address 0x44 !
09:38:57.582 -> I2C device found at address 0x59 !
09:38:57.620 -> I2C device found at address 0x62 !
09:38:57.653 -> done
09:38:57.653 ->
09:39:02.597 -> Scanning...
09:39:02.597 -> I2C device found at address 0x44 !
09:39:02.632 -> I2C device found at address 0x59 !
09:39:02.669 -> I2C device found at address 0x62 !
09:39:02.737 -> done
09:39:02.737 ->

This was My output so everything is OK.

  • Arduino Program
    //Arduino Program Here​
    //I2C scanner 
    // --------------------------------------
    // i2c_scanner
    //
    // Version 1
    //    This program (or code that looks like it)
    //    can be found in many places.
    //    For example on the Arduino.cc forum.
    //    The original author is not know.
    // Version 2, Juni 2012, Using Arduino 1.0.1
    //     Adapted to be as simple as possible by Arduino.cc user Krodal
    // Version 3, Feb 26  2013
    //    V3 by louarnold
    // Version 4, March 3, 2013, Using Arduino 1.0.3
    //    by Arduino.cc user Krodal.
    //    Changes by louarnold removed.
    //    Scanning addresses changed from 0...127 to 1...119,
    //    according to the i2c scanner by Nick Gammon
    //    https://www.gammon.com.au/forum/?id=10896
    // Version 5, March 28, 2013
    //    As version 4, but address scans now to 127.
    //    A sensor seems to use address 120.
    // Version 6, November 27, 2015.
    //    Added waiting for the Leonardo serial communication.
    //
    //
    // This sketch tests the standard 7-bit addresses
    // Devices with higher bit address might not be seen properly.
    //
    #include <Wire.h>
    void setup() {
      Wire.begin();
      Serial.begin(9600);
      while (!Serial); // Leonardo: wait for serial monitor
      Serial.println("\nI2C Scanner");
    }
    void loop() {
      int nDevices = 0;
      Serial.println("Scanning...");
      for (byte address = 1; address < 127; ++address) {
        // The i2c_scanner uses the return value of
        // the Write.endTransmisstion to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        byte error = Wire.endTransmission();
        if (error == 0) {
          Serial.print("I2C device found at address 0x");
          if (address < 16) {
            Serial.print("0");
          }
          Serial.print(address, HEX);
          Serial.println("  !");
          ++nDevices;
        } else if (error == 4) {
          Serial.print("Unknown error at address 0x");
          if (address < 16) {
            Serial.print("0");
          }
          Serial.println(address, HEX);
        }
      }
      if (nDevices == 0) {
        Serial.println("No I2C devices found\n");
      } else {
        Serial.println("done\n");
      }
      delay(5000); // Wait 5 seconds for next scan
    }

Next, I imported the Code necessary for the I2C to work properly.

https://github.com/adafruit/Adafruit_SGP40

https://www.arduino.cc/reference/en/libraries/sht31/

Final Output To Raspberry PI

12:37:57.603 -> CO 797,C 27.6,%RH 21.1,VOC 30906
12:37:57.640 ->
12:37:58.647 ->
12:37:58.647 -> CO 797,C 27.6,%RH 21.1,VOC 30883
12:37:58.680 ->
12:37:59.693 ->
12:37:59.693 -> CO 797,C 27.4,%RH 21.3,VOC 30887
12:37:59.693 ->
12:38:00.740 ->
12:38:00.740 -> CO 797,C 27.4,%RH 21.3,VOC 30878
12:38:00.740 ->
12:38:01.776 ->
12:38:01.776 -> CO 797,C 27.4,%RH 21.3,VOC 30871
12:38:01.776 ->
12:38:02.832 ->
12:38:02.832 -> CO 797,C 27.4,%RH 21.3,VOC 30874
12:38:02.832 ->


#include "SHT31.h"
#include <Arduino.h>
#include <SensirionI2CSgp40.h>
#include <Wire.h>
#include "SparkFun_SCD4x_Arduino_Library.h"
SensirionI2CSgp40 sgp40;
#define SHT31_ADDRESS   0x44
uint32_t start;
uint32_t stop;
uint32_t cnt;
SHT31 sht;
SCD4x mySensor;
void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);
  Serial.print("SHT31_LIB_VERSION: \t");
  Serial.println(SHT31_LIB_VERSION);
  Wire.begin();
  sht.begin(SHT31_ADDRESS);
  Wire.setClock(100000);
  uint16_t stat = sht.readStatus();
  Serial.print(stat, HEX);
  Serial.println();
  sht.requestData();
  cnt = 0;
  //---------------------
  if (mySensor.begin() == false)
  {
    Serial.println(F("Sensor not detected. Please check wiring. Freezing..."));
    while (1)
      ;
  }
  //----------------------
  uint16_t error;
  char errorMessage[256];
  sgp40.begin(Wire);
  uint16_t serialNumber[3];
  uint8_t serialNumberSize = 3;
  error = sgp40.getSerialNumber(serialNumber, serialNumberSize);
  uint16_t testResult;
  error = sgp40.executeSelfTest(testResult);
  if (error) {
  //  Serial.print("Error trying to execute executeSelfTest(): ");
  //  errorToString(error, errorMessage, 256);
 //   Serial.println(errorMessage);
  } else if (testResult != 0xD400) {
 //   Serial.print("executeSelfTest failed with error: ");
  //  Serial.println(testResult);
  }
}
//----------------------
void loop() {
  char message[256];
  uint16_t error;
  char errorMessage[256];
  uint16_t defaultRh = 0x8000;
  uint16_t defaultT = 0x6666;
  uint16_t srawVoc = 0;
  delay(1000);
  error = sgp40.measureRawSignal(defaultRh, defaultT, srawVoc);
  if (error) {
 //   Serial.print("Error trying to execute measureRawSignal(): ");
    errorToString(error, errorMessage, 256);
//    Serial.println(errorMessage);
  } else {
  }
  //----------------------------
  uint16_t rawTemperature;
  uint16_t rawHumidity;
  sht.dataReady() ;
  start = micros();
  bool success  = sht.readData();   // default = true = fast
  stop = micros();
  sht.requestData();                // request for next sample
 // Serial.print("\t");
 // Serial.print(stop - start);
//  Serial.print("\t");
  if (success == false)
//    Serial.println("Failed read");
  rawTemperature = sht.getRawTemperature();
  rawHumidity = sht.getRawHumidity();
  //  Serial.print(rawTemperature, HEX);
  //  Serial.print(" = ");
  //  Serial.print(rawTemperature * (175.0 / 65535) - 45, 1); // This formula comes from page 14 of the SHT31 datasheet
  //  Serial.print("°C\t");
  //  Serial.print(sht.getRawHumidity(), HEX);
  //  Serial.print(" = ");
  //  Serial.print(rawHumidity * (100.0 / 65535), 1); // This formula comes from page 14 of the SHT31 datasheet
  //  Serial.print("%\t");
  //  Serial.println(cnt);
  cnt = 0;
  cnt++; // simulate other activity
  mySensor.readMeasurement(); // readMeasurement will return true when fresh data is available
  Serial.println();
  Serial.print("CO ");
  Serial.print(mySensor.getCO2());
  Serial.print(",");
  Serial.print("C ");
  Serial.print(mySensor.getTemperature(), 1);
  Serial.print(",");
  Serial.print("%RH ");
  Serial.print(mySensor.getHumidity(), 1);
  Serial.print(",");
  Serial.print("VOC ");
  Serial.println(srawVoc);
  Serial.println();
  // delay(1000);
  //  sprintf(message,"VOC:%d,Temp:%s,Humid:%f,CO2:%f",(srawVoc),(mySensor.getTemperature()),(mySensor.getHumidity())),(mySensor.getCO2()) ;
  //  Serial.println(message);
}Text Code Here 
I am a ticketed Electrician In Canada , I work designing shields for IOT and sensing equipment for Penteon Corporation, I also dabble in Linux programming, C++ and electronics https://www.hackster.io/Jade7272 https://www.linkedin.com/in/jade-perreault-0a396722/
DesignSpark Electrical Logolinkedin