Wednesday, 22 April 2020

IoT Project : Home Automation and Weather Monitor Using NodeMCU with Cayenne

PROJECT VIDEO LINK:
Pin diagram:


software app LINK:



SAMPLE SOFTWARE CODE:
----------------------

#include <Adafruit_Sensor.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
//////////////////////////////////////////////////////////////////////
char ssid[] = "svskits";
char wifiPassword[] = "123456";
//////////////////////////////////////////////////////////////////////
char username[] = "54fab1d0-749b-11ea-9915-d7baa233c";
char password[] = "1b47fcc0cacabd471e6c80d590eaa9322ce";
char clientID[] = "6736db70-749c-11ea-9179-a737487a4";
//////////////////////////////////////////////////////////////////////
unsigned long lastMillis = 0;
#include "DHT.h"
#define DHTPIN D4     
#define DHTTYPE DHT11  
DHT dht(DHTPIN, DHTTYPE);
float h,t,f,hic,hif;
////////////////////////////////////////////////////////////////////////
void setup()
{
dht.begin();
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
}
///////////////////////////////////////////////////////////////////////
void loop()
{
Cayenne.loop();
if (millis() - lastMillis > 10000)
{
lastMillis = millis();
Cayenne.virtualWrite(0, h);
Cayenne.virtualWrite(1, t);
Cayenne.virtualWrite(2, hic);
}
h = dht.readHumidity();
t = dht.readTemperature();
f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
hif = dht.computeHeatIndex(f, h);
hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}
//////////////////////////////////////////////////////////////////////
CAYENNE_IN(3)
{
int currentValue=getValue.asInt();
if(currentValue==1){digitalWrite(D0,LOW);}
else{digitalWrite(D0,HIGH);}
}
//////////////////////////////////////////////////////////////////////
CAYENNE_IN(4)
{
int currentValue=getValue.asInt();
if(currentValue==1){digitalWrite(D1,LOW);}
else{digitalWrite(D1,HIGH);}
}
//////////////////////////////////////////////////////////////////////
CAYENNE_IN(5)
{
int currentValue=getValue.asInt();
if(currentValue==1){digitalWrite(D2,LOW);}
else{digitalWrite(D2,HIGH);}
}
//////////////////////////////////////////////////////////////////////
CAYENNE_IN(6)
{
int currentValue=getValue.asInt();
if(currentValue==1){digitalWrite(D3,LOW);}
else{digitalWrite(D3,HIGH);}
}
//////////////////////////////////////////////////////////////////////





No comments:

Post a comment