Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include "Arduino.

h"
#include <ESP8266WiFi.h>
const char* ssid = "AkashDidharia";
const char* password = "88888800";
float h = 11;
float t = 22;
#include "DHT.h"
#include "PIR.h"
#include "FSR.h"
#define DHTPIN 0
#define DHTTYPE DHT11 // DHT 11
#define FSRPIN A3
#define PIRPIN D3
#define WIFI_PIN_TX 11
#define WIFI_PIN_RX 10

DHT dht(DHTPIN, DHTTYPE);


FSR fsrSquare(FSRPIN);
PIR pir(PIRPIN)
void setup()
{
Serial.begin(9600);

while(!Serial) { }
WiFi.begin(ssid, password);
Serial.println("Sensor test!");
dht.begin();
delay(2000);
h = dht.readHumidity();
t = dht.readTemperature();
delay(1000);

if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from temp Sensor");
} else {
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" %\t");
Serial.print("Humidity: ");
Serial.print(h);
}
float pressure = fsrSquare.getForce();
bool motion = pir.read();
const char host[ ] = "maker.ifttt.com";
const char trigger[ ] = "suffocation";
const char APIKey[ ] = "d5lp9wTjlJOOq2PWUjuOVBNi8P6GDNH_SchUzER0vR_";
Serial.print("Connect to: ");
Serial.println(host);
// WiFiClient to make HTTP connection
WiFiClient client;
if (!client.connect(host, 80)) {
Serial.println("connection failed");
return;
}

// Build URL
String url = String("/trigger/") + trigger + String("/with/key/") + APIKey +
String("?Temp=") + t + String("Motion=") + motion + String("Pressure=") + pressure;
Serial.print("Requesting URL: ");
Serial.println(url);

// Send request to IFTTT


client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(20);

Serial.println("Respond:");
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
Serial.println();
client.stop();
Serial.println("Report on Car Data");
Serial.print("temp ");
Serial.println(t);
Serial.print("motion ");
Serial.println(motion);
Serial.print("pressure ");
Serial.println(pressure);
Serial.println("Deep sleep mode entered");
ESP.deepSleep(7200);
}
void loop() //Nothing happens because ciruit entered deep sleep mode
{
}

You might also like