Line 3: Line 3:
 
We will be using the '''Max6675''' for measuring the temperature and Non-invasive '''yhdc sct-013-000''' AC current sensor to measure electric energy consumed. The measure temperature and Current along with Power is logged to server using Hornbill AWS IOT library.
 
We will be using the '''Max6675''' for measuring the temperature and Non-invasive '''yhdc sct-013-000''' AC current sensor to measure electric energy consumed. The measure temperature and Current along with Power is logged to server using Hornbill AWS IOT library.
  
Please check the earlier tutorials for setting up [[Secure_IOT_with_AWS_and_Hornbill_ESP32|AWS IOT]] for your user account and [[AWS_IOT_with_Arduino_ESP32|Hornbill AWS IOT]] library usage guide.
+
Please check the earlier tutorials for enabling [[Secure_IOT_with_AWS_and_Hornbill_ESP32|AWS IOT services]] to your user account and [[AWS_IOT_with_Arduino_ESP32|Hornbill AWS IOT]] library usage guide.
  
  

Revision as of 18:13, 14 April 2017

In this tutorial we will see how to build a simple IOT Industrial Data logger to log the temperature and Current. We will be using the Max6675 for measuring the temperature and Non-invasive yhdc sct-013-000 AC current sensor to measure electric energy consumed. The measure temperature and Current along with Power is logged to server using Hornbill AWS IOT library.

Please check the earlier tutorials for enabling AWS IOT services to your user account and Hornbill AWS IOT library usage guide.


Schematic

Connection

Code

/*
* 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);
}

Download