//This code is edited by Yogesh Bawane
//for impulsetech Youtube channel https://youtu.be/RpQxJkEZ-fA
//For complete video tutorial visit https://youtu.be/RpQxJkEZ-fA
#include <WiFi.h>
#include <HTTPClient.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define ThermistorPin 35
#define LDR_PIN 34
//our sensor is DHT11 type
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const char * ssid = "impulsetech";
const char * password = "impulse567";
String server = "http://maker.ifttt.com";
String eventName = "sensor_data";
String IFTTT_Key = "drlqzriADlETJtD04KV_NfpVmzvtAVhrEhUSGNRNnN7";
String IFTTTUrl="https://maker.ifttt.com/trigger/sensor_data/with/key/drlqzriADlETJtD04KV_NfpVmzvtAVhrEhUSGNRNnN7";
int value1;
int value2;
int value3;
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Viola, Connected !!!");
}
float getLightPercentage(void)
{
int ldrRawVal;
float percentage;
ldrRawVal = analogRead(LDR_PIN);
percentage = ((float)((ldrRawVal*100)/4096));
return percentage;
}
void sendDataToSheet(void)
{
String url = server + "/trigger/" + eventName + "/with/key/" + IFTTT_Key + "?value1=" + String((int)value1) + "&value2="+String((int)value2) +"&value3=" + String((int)value3);
Serial.println(url);
//Start to send data to IFTTT
HTTPClient http;
Serial.print("[HTTP] begin...\n");
http.begin(url); //HTTP
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void loop() {
value1 = dht.readHumidity();
value2 = dht.readTemperature();
value3 = getLightPercentage();
Serial.print("Values are ");
Serial.print(value1);
Serial.print(' ');
Serial.print(value2);
Serial.print(' ');
Serial.println(value3);
Serial.print(' ');
sendDataToSheet();
delay(10000);
}