IFTTT notification with Temperature and humidity value_DTH11

Switch works as a trigger to send data. it could be motion sensor, vibration sensor, moisture sensor, etc. we can send three values using IFTTT trigger, name as Value1, Value2, Value3.



Ingredient you need during this tutorial,
1) NodeMCU integration with Arduino IDE
2) Basic hardware
a.    NodeMCU
b.    Breadboard
c.    Switch
d.    10K resistor x2
e.    Jumper wires.
f.     DTH 11 sensor (Or module)
g.     Internet connection 😉
3) Thinger.io – open source IOT platform  
4) IFTTT 
IFTTT is free platform that helps you do more interaction with all your apps and devices. To accomplish multiple task, please sign up in a free service called IFTTT, which stands for “If This Then That”
You can cross connect your IOT device with notification, Email, tweet, Facebook, etc…

To start with IFTTT,
Create a free IFTTT account.
Go the official site: https://ifttt.com/ and click the “Sign Up” button in top of the page.



Once you "Sign-up", you see…



In the top raw, select the "My applets" or create one.

Click on "this" to make trigger activity.
In our case we want to use a NodeMCU with button to make a trigger.

Select "Maker webhooks" It will allow you to make the IOT hardware integration.



I created an event name "Temp_sensor" (you need in Arduino code) written in the box. Do remember this name you will need this in future for the testing.


So It will show you if button pressed (On NodeMCU)  then what…!!!



It has multiple action services, which will allow you to connect through possible services with simple selection. In our-case we are sending notification in this tutorial. (You need to download an app for notification service)

In this Notification dialog, please add the message you want to see. Also please add ingredient call "value1", "value2",
"Value 1" stands for the temperature, and "Value 2" stands for the Humidity in our case.



Compete with the action by a click "create action".



So once it is finished, Check by clicking a "check now" button, It should not give you any error during this.

Now, Go back to search on the top, write "Maker Webhooks", It will show you below options.

Now go in to "setting", and copy a "URL" and past in the internet browser. It will show you your active key with event box.



Write an "event name" in the box Temp_sensor in our case and click on the test button at bottom.
This will work as a trigger in absents of a trigger hardware and gives you an indication of system working. (you should receive a notification by doing this)

Now IFTTT will not get the value directly from the Hardware, So we required one more interface call thinger.io, which will support us to transfer DTH value to IFTTT. (It works as inter-mediator)

To configure thinger.io interface. Go to https://thinger.io/ and register yourself.



Once you sign in, you see.


You need to add device and endpoints to make this work with nodeMCU.
click on the Device and add Device ID (Required in Arduino Code) and Device Credentials could be any name (Required in Arduino Code).

Once you click “Add device” it will add this device in the thinger.io platform. Now go to endpoints and add required details as below.



Select IFTTT maker channel trigger and add IFTTT details like event name and IFTTT key.



So Internet configuration over, Now let finish hardware connection and Arduino Coding.

Hardware design:




Connect NodeMCU to the breadboard with switch and resistor as shown above.
Switch: Pin number -D2
DTH11 sensor : Pin number D1

Breadboard connection:



Software:

Before you start, make sure your Arduino IDE has installed ESP8266 board with thinger.io library.

You can download thinger.io library from:
https://github.com/thinger-io/Arduino-Library

Arduino Code 1:
It will send you a notification with Temperature and Humidity data when you press a button.
------------------------------------------------------------------------------------------------------------------------------------------------------
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#include "DHT.h"

#define USERNAME "User name" // Your login name from thiner.io
#define DEVICE_ID "NodeMCU_DTH11" // Your device ID from thinger.io
#define DEVICE_CREDENTIAL "lorem_ipsum" // your crefential from thinger.io

#define SSID "WIFI network"
#define SSID_PASSWORD "WIFI password"

int pin = 4;

#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void PINStatus() {
  digitalWrite(BUILTIN_LED, LOW);
  pson DTH_value;
  DTH_value["value1"] = dht.readTemperature();
  DTH_value["value2"] = dht.readHumidity();
  thing.call_endpoint("DTH_post", DTH_value);
  digitalWrite(BUILTIN_LED, HIGH); /// it will be on untill data gets on the thinger.io site
            
}


void setup() {
   
 dht.begin();
 pinMode(pin, OUTPUT);
 attachInterrupt(digitalPinToInterrupt(pin), PINStatus, FALLING);

 pinMode(BUILTIN_LED, OUTPUT);
 digitalWrite(BUILTIN_LED, HIGH);
 
 thing.add_wifi(SSID, SSID_PASSWORD);

  // resource for reading sensor temperature from API
 thing["dht11"] >> [](pson& out){
 out["humidity"] = dht.readHumidity();
 out["celsius"] = dht.readTemperature();
 out["fahrenheit"] = dht.readTemperature(true);
 };
}

void loop() { 
  thing.handle();
}

------------------------------------------------------------------------------------------------------------------------------------------------------ 

Arduino Code 2:

It will give you a notification at every hour with temperature and humidity data, also works when you press a button.

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#include "DHT.h"

#define USERNAME "User name" // Your login name from thiner.io
#define DEVICE_ID "NodeMCU_DTH11" // Your device ID from thinger.io
#define DEVICE_CREDENTIAL "lorem_ipsum" // your crefential from thinger.io

#define SSID "WIFI network"
#define SSID_PASSWORD "WIFI password"

int pin = 4;

#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

unsigned long previousMillis = 0;      // to know when to post the temperature
unsigned int minutes_interval = 60;              // variable in minutes for posting the temperature

void PINStatus() { 
  digitalWrite(BUILTIN_LED, LOW);
  pson DTH_value;
  DTH_value["value1"] = dht.readTemperature();
  DTH_value["value2"] = dht.readHumidity();
  thing.call_endpoint("DTH_post", DTH_value);
  digitalWrite(BUILTIN_LED, HIGH);
             
}


void setup() {
    
 dht.begin();
 pinMode(pin, OUTPUT);
 attachInterrupt(digitalPinToInterrupt(pin), PINStatus, FALLING);

 pinMode(BUILTIN_LED, OUTPUT);
 digitalWrite(BUILTIN_LED, HIGH);
  
 thing.add_wifi(SSID, SSID_PASSWORD);

  // resource for reading sensor temperature from API
 thing["dht11"] >> [](pson& out){
 out["humidity"] = dht.readHumidity();
 out["celsius"] = dht.readTemperature();
 out["fahrenheit"] = dht.readTemperature(true);
 }; 
}

void loop() {  
  thing.handle();
  unsigned long currentMillis = millis();
  if(minutes_interval>0 && currentMillis - previousMillis >= minutes_interval * 60000) 
  {
    previousMillis = currentMillis;   
    PINStatus();
  }
  
}

-----------------------------------------------------------------------------------------------------------------------------------------------------


Please make sure you customize the highlighted area in CODE

So when ever you press a button, it will send an notification with temperature and humidity value or every hour

Execution video:






Comments

Popular Posts