Hornbill Industrial Data Logger
In this tutorial we will see how to build a simple IOT Industrial Data Logger(IDL) to log the device temperature and current to AWS IOT and display it on Hornbill IO. The IDL connects to Wi-Fi and then to the clould.
We will be using the MAX6675 for measuring the temperature and Non-invasive YHDC SCT-013-050 AC current sensor to measure electric energy consumed. The measured temperature and current along with power is logged to server using Hornbill AWS IOT library. This data could later be used to determine device specific events like operating duration, total power consumption etc., Combing this with the device temperature can be useful in understanding operating health of the machine. We have attached Hornbill Industrial Data Logger to a bench top drill machine, you may add it any machine where power and temperature measurements can result in useful insights.
Check the earlier tutorials for enabling AWS IOT services to your user account and Hornbill AWS IOT library usage guide.
Contents
[hide]Schematic
The IDL can be powered either through a LiPo battery or using the on-board USB connector.
Assembly
The Hornbill IDL kit comes with all the parts required. The steps show assembling a DIY version of the kit, however the IDL Kit we will ship will come with pre-assembled single PCB with ESP32 Module, Sensors and other circuitry built-in. To build this you'll need:
- Hornbill ESP32 Dev board
- Hornbill ESP32 Proto board
- Thermocouple
- Current Sensor
- Hornbill Case
- USB Power Adapter or LiPo Battery
- Start with soldering all the parts on the Proto Sheild
- Once all the parts are soldered on Proto Sheild, solder the Hornbill ESP32 Dev board
- The board assembly looks as shown below:
- Screw the board to the Hornbill Case.
- You may then either power it up with a USB Charger or connect a LiPo battery. The sensor should be clipped to the phase wire of the equipment power and the thermocouple should be tagged to the device.
Code
Temperature and current will be continuously monitored and logged to amazon server every 5sec. To compile the code add the following libraries.
- Adafruit Max6675 Library to measure the temperature
- Open Energy Monitor's Library to measure current and power.
/* | |
* Tutorial : Hornbill Industrial Data logger (Temp and Current ) | |
* Sensor: Max6675 Temp Sensor, non-invasive Current Sensor sensor | |
* Reference links: | |
https://exploreembedded.com/wiki/Hornbill_Industrial_Data_Logger | |
https://exploreembedded.com/wiki/Secure_IOT_with_AWS_and_Hornbill_ESP32 | |
https://exploreembedded.com/wiki/AWS_IOT_with_Arduino_ESP32 | |
* Library Links: | |
https://github.com/ExploreEmbedded/Hornbill-Examples/tree/master/arduino-esp32/AWS_IOT/examples | |
https://github.com/openenergymonitor/EmonLib | |
https://github.com/adafruit/MAX6675-library | |
*/ | |
#include <AWS_IOT.h> | |
#include <WiFi.h> | |
#include <max6675.h> | |
#include <EmonLib.h> | |
/************************************************************************ | |
AWS Configuration | |
/************************************************************************/ | |
char WIFI_SSID[]="your Wifi SSID"; | |
char WIFI_PASSWORD[]="Wifi Password"; | |
char HOST_ADDRESS[]="AWS host address"; | |
char CLIENT_ID[]= "client id"; | |
char TOPIC_NAME[]= "your thing/topic name"; | |
/***********************************************************************/ | |
/********************************************************** | |
Pin Mapping | |
**********************************************************/ | |
int thermoDO = 27; | |
int thermoCS = 14; | |
int thermoCLK = 12; | |
int currentPin = 36; | |
/*********************************************************/ | |
/********************************************************* | |
Create instances | |
/*********************************************************/ | |
AWS_IOT AWS_CLIENT; | |
MAX6675 thermoCouple(thermoCLK, thermoCS, thermoDO); | |
EnergyMonitor emon; | |
/*********************************************************/ | |
int status = WL_IDLE_STATUS; | |
int tick=0, publishMsg=0; | |
char payload[512]; | |
void setup() { | |
Serial.begin(115200); | |
delay(2000); | |
while (status != WL_CONNECTED) | |
{ | |
Serial.print("Attempting to connect to SSID: "); | |
Serial.println(WIFI_SSID); | |
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | |
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |
// wait 5 seconds for connection: | |
delay(5000); | |
} | |
Serial.println("Connected to wifi"); | |
if(AWS_CLIENT.connect(HOST_ADDRESS,CLIENT_ID)== 0) | |
{ | |
Serial.println("Connected to AWS"); | |
delay(1000); | |
} | |
else | |
{ | |
Serial.println("AWS connection failed, Check the HOST Address"); | |
while(1); | |
} | |
delay(2000); | |
emon.current(currentPin, 111.1); // Current: input pin, calibration. | |
} | |
void loop() { | |
double Irms,power,tempCelcius; | |
if(tick >= 5) // Publish every 5secs | |
{ | |
tempCelcius = thermoCouple.readCelsius(); | |
Irms = emon.calcIrms(1480); // Calculate Irms only | |
power = 230 * Irms; | |
sprintf(payload,"Temperature:%f'C, Irms Current:%fA, Power:%fW",tempCelcius,Irms,power); | |
if(AWS_CLIENT.publish(TOPIC_NAME,payload) == 0) | |
{ | |
Serial.println(payload); | |
tick = 0; // Publish successfull, wait for 5more seconds | |
} | |
else | |
{ | |
Serial.println("Publish failed, Will try again after 1sec"); | |
} | |
} | |
else | |
{ | |
tick++; | |
} | |
vTaskDelay(1000 / portTICK_RATE_MS); | |
} |
Data
The data is logged to AWS, however there is no way to visualize it. So we have built a data visualization and device control tool at Hornbill IO. Hornbill IO is still work in progress and we will release a beta version soon. However, here is how the plot looks on the dashboard.
Video
Download
Download the Arduino ESP32 AWS IOT lib and examples form this link.
Have an opinion, suggestion , question or feedback about the article let it out here!