Project Description:
SaferWork 4.0 intends on providing real-time environmental data of industrial areas. Currently available regulation such as OHSAS 18001 (Occupational Health and Safety Assessment Series) or Brazilian NR-15 (unhealthy activities) considers periodical inspections to classify the areas and propose mitigations. Intermittent conditions are not captures by these periodical inspections and can harm the workers due to lack of mitigation actions.
In a concept of distributed devices and a main gateway, sensors are distributed in an industrial plant to measure environmental conditions and these data are presented in a dashboard available to safety specialists, physicians, upper management, human resources, and many others, supporting key insights leading to risk assessments and mitigation actions aiming to reduce or preventing injuries and accidents.
The current prototype measures:
- Temperature
- Humidity
- Gases (Air Quality, Flammable, Combustible and Smoke)
To be implemented:
- Noise
How It Works
The device send a JSON package containing sensors data to gateway that will process and send it to cloud (dweet.io) and also provide it on a dashboard (freeboard.io).
Parts List - Hardware
Gateway
- Qualcomm Dragonboard 410c (Debian Linux)
- HC-12 Wireless Transceiver (Datasheet)
- Level Shifter to convert Dragonboard 1.8V to 5V (Datasheet)
Device
- Arduino Uno
- HC-12 Wireless Transceiver (Datasheet)
- DHT-11 Temperature and Humidity Sensor (Datasheet)
- MQ-2 - Sensitive for flamable and combustible gasses (Methane, Butane, LPG, smoke) (Datasheet)
- MQ-9 - Sensitive for Carbon Monoxide, flammable gasses (Datasheet)
- MQ-135 - For Air Quality (sensitive for Benzene, Alcohol, smoke) (Datasheet)
The device represents a sensors bed to be located in many areas in an industrial site for real time environment sensing.
In this project was used the Arduino Uno Platform with 3 gas sensors (MQ-2, MQ-9 and MQ-135), 1 temperature/humidity sensor (DHT-11) and a RF transceiver (HC-12).
The Arduino to Sensors Pinout:
Analog
- A1 to DHT11 analog pin
- A3 to MQ135 analog pin
- A4 to MQ9 analog pin
- A5 to MQ2 analog pin
Digital
- D7 to HC-12 SET pin
- D10 to HC-12 TX pin (configured as RX on Arduino)
- D11 to HC-12 RX pin (configured as TX on Arduino)
Code Implemented
Visit: GitHub source code
// SaferWork - Device Code
//
// References:
// https://github.com/adafruit/DHT-sensor-library
// https://quadmeup.com/hc-12-433mhz-wireless-serial-communication-module-configuration/
// https://www.elecrow.com/download/HC-12.pdf
// https://playground.arduino.cc/Main/MQGasSensors
// https://github.com/bblanchon/ArduinoJson
//
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#include <DHT.h>
#define DHTPIN A1 // Analog PIN A1 for DHT11
#define DHTTYPE DHT11 // DHT 11
//Device Configuration
#define DEVID "Device01"
#define MSG_PUSH_TIME 5000 //in miliseconds
DHT dht(DHTPIN, DHTTYPE);
//Pins for Serial connection to HC-12
SoftwareSerial HC12_Device(10, 11); // RX, TX
int HC12_SET = 7; // Pin to setup HC-12 Wireless module
// GAS Sensors Pinout no Arduino
int MQ2_gasPin = 5; //sensitive for flamable and combustible gasses (Methane, Butane, LPG, smoke)
int MQ9_gasPin = 4; //sensitive for Carbon Monoxide, flammable gasses
int MQ135_gasPin = 3; //For Air Quality (sensitive for Benzene, Alcohol, smoke)
void setup(){
pinMode(HC12_SET, OUTPUT);
HC12_Device.begin(9600);
Serial.begin(9600);
digitalWrite(7, LOW); // enter AT command mode
HC12_Device.print("AT+DEFAULT"); // 9600, CH1, FU3, (F) to bypass flash memory
delay(100);
digitalWrite(7, HIGH); // enter transparent mode
dht.begin();
}
void loop(){
// Reserve memory space
StaticJsonBuffer<256> jsonBuffer;
char buffer[256];
JsonObject& root = jsonBuffer.createObject();
delay(MSG_PUSH_TIME);
//Sensors Readings
float h = dht.readHumidity();
float t = dht.readTemperature();
int MQ2 = analogRead(MQ2_gasPin);
int MQ9 = analogRead(MQ9_gasPin);
int MQ135 = analogRead(MQ135_gasPin);
// JSON Construct
// Example: {"DeviceID":"Device01","key":0x00,"data":[TEMPERATURE,HUMIDITY,MQ2_LEVEL,MQ9_LEVEL,MQ135_LEVEL]}
root["DeviceID"] = DEVID;
root["key"] = "0x00";
JsonArray& data = root.createNestedArray("data");
data.add(h);
data.add(t);
data.add(MQ2);
data.add(MQ9);
data.add(MQ135);
root.printTo(buffer, sizeof(buffer));
HC12_Device.println(buffer);
}
Step 2: Gateway ImplementationAs stated by Wikipedia:
"An Internet of Things (IoT) Gateway provides the means to bridge the gap between devices in the field (factory floor, home, etc.), the Cloud, where data is collected, stored and manipulated by enterprise applications, and the user equipment"
To implement this functionality we are using the Qualcomm Dragonboard 410c. In conjunction with the Dragonboard we uses a bi-directional level shifter, to convert the Dragonboard operational voltage of 1.8V to HC-12 RF Transceiver Operational Voltage of 5V.
The Dragonboard 410c was also configured with the Debian/Linaro Linux.
Dragonboard 410c Pinout as Gateway:
- Low Speed Connector Pin 5 (TxD) -> Level Shifter -> HC-12 RX Pin
- Low Speed Connector Pin 7 (RxD) <- Level Shifter <- HC-12 TX Pin
- Low Speed Connector Pin 29 (GPIO) -> Level Shifter -> HC-12 SET Pin
The code implemented in Python to set up the Gateway Service can be obtained in project GitHub repository:
https://github.com/gubertoli/SaferWork/blob/master/SaferWork_Gateway.py
#
# Dragonboard 410c - SaferWork 4.0 Gateway
#
# Receives JSON packages through UART using a HC-12 chip
#
# Required python-serial and requests:
# sudo apt-get install python-pip
# sudo pip install pyserial
# sudo pip install requests
#
import serial
import time
import requests
import json
from GPIOProcessor import GPIOProcessor
ser = serial.Serial('/dev/tty96B0',baudrate=9600)
# dweet.io configuration
thingname = "SaferWork_Prototype"
dweet_url = "https://dweet.io:443/dweet/for/"
def config():
# HC-12 Configuration
# Using UART port from Low Speed Connector (PINs 5 and 7)
time.sleep(2)
GP = GPIOProcessor()
SETPin = GP.getPin29() # HC-12 SET Pin connected to DB410C LS pin 29
SETPin.out() # Defined as output
print ">> SET PIN ---> " + SETPin.getDirection()
print ">> SET PIN ---> LOW (AT Command)"
SETPin.low() # Enter to AT Command
print ">> HC-12 Set to Default (FU3 / 9600bps / CH1 433.4MHz)"
ser.write("AT+DEFAULT") # SET HC-12 Default Configuration
time.sleep(1)
SETPin.high() # Enter Transparent Mode
print ">> SET PIN ---> HIGH (Transparent Mode)"
time.sleep(2)
print ">> HC-12 Setup OK!"
# Usage
ser.write("[rf_msg] Dragonboard (Gateway) to Device")
GP.cleanup()
time.sleep(2)
# procedure to send data to dweet.io
def send_data(thingname, data):
rqsString = dweet_url+thingname+'?'+str(data)
print rqsString
try:
rqs = requests.get(rqsString, timeout=10)
print rqs.status_code
except requests.exceptions.RequestException as e:
print e
except KeyboardInterrupt:
raise
def main():
config()
# Infinite Loop for Data Receiver (Gateway)
while True:
jsonPackage = ser.readline()
data = json.loads(jsonPackage)
deviceId = data['DeviceID']
temp = data['data'][1]
humidity = data['data'][0]
mq2 = data['data'][2]
mq9 = data['data'][3]
mq135 = data['data'][4]
jsonPackage = "deviceId="+str(deviceId)+"&temp="+str(temp)+"&humidity="+str(humidity)+"&mq2="+str(mq2)+"&mq9="+str(mq9)+"&mq135="+str(mq135)
send_data(thingname,jsonPackage)
ser.close()
if __name__ == "__main__":
main()
It is important to mention that this project uses dweet.io to send the device info and this info is consumed on the freeboard.io service as illustrated in this step.
The dweet.io setup is very simple and can be understand by the commented source code. The freeboard.io is an intuitive dashboard creator that interacts directly with dweet.io.
Comments
Please log in or sign up to comment.