David K
Published © GPL3+

ESP8266 Blynk Garage door & climate sensor, wifi, phone app

A garage door and a climate sensor, which is connected to wifi. It sends phone notifications when the door opens or closes.

BeginnerFull instructions provided2 hours2,989
ESP8266 Blynk Garage door & climate sensor, wifi, phone app

Things used in this project

Hardware components

Adafruit HUZZAH ESP8266 Breakout
Adafruit HUZZAH ESP8266 Breakout
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Reed Switch, SPST-NO
Reed Switch, SPST-NO
×1
Cable, USB to TTL Level
Cable, USB to TTL Level
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic with annotations

This is how you can replicate the schematic

Code

Adafruit_ESP8266_Reed_DHT22_Blynk_Notify

Arduino
/**************************************************************
 * *
 *   Magnetic switch & DHT 22 output to blynk by David K
 *   
 *   Reed switch is connected to pin 12 via input pullup
 *   DHT sensor is connected to pin 13
 *   
 *   Blynk App project setup:
 *   LED widged attched to V4
 *   Value Display widget attached to V5
 *   Value Display widget attached to V6
 *   
 *   
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "**********";
char pass[] = "*********";

int StatMagSwitch = 0; // switch status setting to 0 or LOW initially, door closed
int PreviousStatus = 0; // this variable holds previous door status, 0: closed, 1: open

#define MAGPIN 12          // pin for magnetic switch
#define DHTPIN 13          // pin DHT sensor
#define DHTTYPE DHT22      // DHT 22, AM2302, AM2321

BlynkTimer timer;          // Initializing blynk
DHT dht(DHTPIN, DHTTYPE);  // Initializing DHT sensor

WidgetLED ledDoor(V4);     //Setting led widget as virtual pin 4 first
// This function sends Arduino's up time every second to Virtual Pins (4,5,6).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App

void sendReadings()
{ int DoorChanged = 0; // this variable will check whether door has changed, 1 if changed 
 
  StatMagSwitch = digitalRead(MAGPIN);  // Reading Magnetic switch status 

  if (StatMagSwitch != PreviousStatus)
  {
   DoorChanged = 1; 
  }
  
  if (StatMagSwitch==1 && DoorChanged==1)
  {
    ledDoor.off(); //turning off if magnet is far away, i.e. Switch is HIGH
    Blynk.notify("Garage door just closed");
  }
  
  if (StatMagSwitch==0 && DoorChanged==1)
  {
    ledDoor.on(); //turning on if magnet is close, i.e. Switch is LOW
    Blynk.notify("Garage door just opened");
  }
  PreviousStatus = StatMagSwitch;

  //Reading DHT sensor readings
  float h = dht.readHumidity(); //Reading Humidity
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V5, h);  //V5 is for Humidity
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  pinMode(MAGPIN, INPUT_PULLUP); // Defining magnetic switch pin as input_pullup
  dht.begin();
  Blynk.begin(auth, ssid, pass);

  // Setup a function to be called every second
  timer.setInterval(1000L, sendReadings);
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

Credits

David K

David K

2 projects • 2 followers
I was born in 2007, I was in middle school when I posted my first project.

Comments

Add projectSign up / Login