#define BLYNK_TEMPLATE_ID "TMPL2GhziJrUf"
#define BLYNK_TEMPLATE_NAME "GATE APP"
#define BLYNK_AUTH_TOKEN "D_jRAtSEUuFGrDKHsEOuPwniSPsrq0sb"
// This #include statement was automatically added by the Particle IDE.
#include <SparkTime.h>
// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
#define BLYNK_PRINT Serial
#define DHTPIN 5
#define DHTTYPE DHT11
UDP UDPClient;
SparkTime rtc;
char auth[] = "d345081bd6b44583a8bb5ef73f865e51";
int temperature;
int humidity;
int light;
int GasSensor = A1;
// Pins
int light_sensor_pin = A0;
int smoke;
// DHT sensor
int motionsr = A3;
DHT dht(DHTPIN, DHTTYPE);
WidgetLED light1(V4);
int overwrite=0;
int reedsr= D1;
int reed;
int switchon= D3;
int buzzer=D6;
int motiondata;
void setup()
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
dht.begin();
pinMode(GasSensor, INPUT);
pinMode(D4, OUTPUT);
pinMode(reedsr,INPUT);
pinMode(D6, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D0, INPUT);
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(+2); // gmt offset
BLYNK_CONNECTED()
//Blynk.syncAll();
}
32
void loop() {
Blynk.run();
int currentTime = rtc.now();
int min = rtc.minute(currentTime);
int hour = rtc.hour(currentTime);
temperature = dht.getTempCelcius();
int temp=temperature;//temperature measurement
humidity = dht.getHumidity();//humidity measurement
float smoke_measurement = analogRead(GasSensor);
smoke = (int)(smoke_measurement);
Blynk.virtualWrite(V5, smoke);
float light_measurement = analogRead(light_sensor_pin); // Light level measurement
light = (int)(light_measurement);
delay(500);
Blynk.virtualWrite(V2, humidity);
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V3, light);
if (light < 750)
light1.off();
if (light >750)
light1.on();
motiondata=analogRead(motionsr);
33
if (digitalRead(D0 == HIGH) )
if (motiondata > 2048)
digitalWrite(D6,HIGH);
delay(200);
digitalWrite(D6,LOW);
if (reed==1)
digitalWrite(D6,HIGH);
delay(200);
digitalWrite(D6,LOW);
if (smoke > 500)
digitalWrite(D6,HIGH);
delay(200);
digitalWrite(D6,LOW);
Blynk.virtualWrite(V6, motiondata);
float reed_measurement= digitalRead(reedsr);
reed = (int)(reed_measurement);
Blynk.virtualWrite(V7, reed);
if (hour==22 && min==30)
34
{
if (reed==1 && light > 750 )
Blynk.email("Status","door is open and light is on");
else if (reed==1 && light < 750)
Blynk.email("Status","door is open and light is off");
else if (reed==0 && light > 750)
Blynk.email("Status","door is closed and light is on");
else
Blynk.email("Status","door is closed and light is off");
}
// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
char auth[] = "";
// door 1 sensor and control
const int magSwitch1 = D0;
const int relaySwitch1 = D3;
// door 2 sensor and control
const int magSwitch2 = D1;
const int relaySwitch2 = D4;
// door 1 status
int magStatus1 = 0;
int ledStatus1 = 0;
// door 2 status
int magStatus2 = 0;
int ledStatus2 = 0;
// timeout in milliseconds
SparkCorePolledTimer updateTimer(1000);
void OnTimer(void) {
sendDoorStatus();
void setup() {
Serial.begin(9600);
Blynk.begin(auth);
while (Blynk.connect() == false) {
// Wait until connected
pinMode(relaySwitch1, OUTPUT);
pinMode(relaySwitch2, OUTPUT);
pinMode(magSwitch1, INPUT_PULLDOWN);
pinMode(magSwitch2, INPUT_PULLDOWN);
updateTimer.SetCallback(OnTimer);
void sendDoorStatus() {
Blynk.virtualWrite(V5, ledStatus1);
Blynk.virtualWrite(V6, ledStatus2);
void loop() {
Blynk.run();
//constantly monitor the door magnetic switch status (garage door open or closed)
magStatus1 = digitalRead(magSwitch1);
magStatus2 = digitalRead(magSwitch2);
if (magStatus1 == HIGH) {
ledStatus1 = 1023; // 100% brightness
//Serial.println("LED1: high");
} else {
ledStatus1 = 0;
//Serial.println("LED1: low");
if (magStatus2 == HIGH) {
ledStatus2 = 1023;
} else {
ledStatus2 = 0;
updateTimer.Update();