victormarinus
Published © GPL3+

Blynk garagedoor monitor/opener

My colleague crashed the roof of his car by leaving the garage to early. So I promised him red, amber, green lights in the garage.

IntermediateFull instructions provided264
Blynk garagedoor monitor/opener

Things used in this project

Hardware components

Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
×1
Resistor 1k ohm
Resistor 1k ohm
×2
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
Signal Relay, 5 VDC
Signal Relay, 5 VDC
×1
Adafruit Protoboard
×1
Adafruit Terminal block 3 pin
×2

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)
If you want to build your porpose build case

Story

Read more

Custom parts and enclosures

bottom case

The bottom of the case

Cover

The cover of the case

Schematics

Fritzing file

Code

Arduino program

Arduino
Install the adafruit huzzah and blynk library
#define TerminalPin V0
#define ClosedLedPin V1
#define OpenedLedPin V2
#define MovingLedPin V3
#define ActivateButtonPin V4
#define TriggerMessageTimePin V5
#define ActivateDoorPin 13
#define DoorUpPin 12
#define DoorDownPin 14

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>

#include <TimeLib.h>
#include <WidgetRTC.h>

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

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

byte PrevClosed = 1;
byte PrevOpened = 1;
bool ClockDisplayed = false;
long OpenedTime ;
int TriggerMessageTime;
bool TriggerMessageSend = false;

//Define the timer
BlynkTimer timer;

//Define the Realtime clock
WidgetRTC rtc;

//Define the terminal
WidgetTerminal terminal(TerminalPin);

void sendDoorstate()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.

  byte Closed = digitalRead(DoorDownPin);
  byte Opened = digitalRead(DoorUpPin);
  Blynk.syncVirtual(TriggerMessageTimePin);
  if (!(Closed == PrevClosed) || !(Opened == PrevOpened)){
    Blynk.virtualWrite(ClosedLedPin, Closed*255);
    Blynk.virtualWrite(OpenedLedPin, Opened*255);
    Blynk.virtualWrite(MovingLedPin, (!Closed && !Opened)*255);
    PrevClosed = Closed;
    PrevOpened = Opened;  
  }
  if (Closed == 1){
  }
  else
    {if (Opened ==1){
      if (!ClockDisplayed) {
        clockDisplay();  
        ClockDisplayed = true;
        TriggerMessageSend = false;
        OpenedTime = millis();
      }
      if (((millis()-OpenedTime)>TriggerMessageTime)&&(!TriggerMessageSend)){
        Blynk.notify("Door is too long opened");
        TriggerMessageSend = true;
      }
    }
    else
      {
        ClockDisplayed = false;
      }
    }
}

void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Door open: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();
  terminal.print("Door open: ");
  terminal.print(currentTime);
  terminal.print(" ");
  terminal.print(currentDate);
  terminal.println();
  terminal.flush();

}

BLYNK_WRITE(ActivateButtonPin) {
  if (param.asInt()==1) { // virtual pin V1 goes HIGH when pressed in the app, goes LOW when released.
    digitalWrite(ActivateDoorPin, HIGH);
    delay(1000);
    digitalWrite(ActivateDoorPin, LOW);
    Blynk.virtualWrite(ActivateButtonPin, LOW);
  }
}

BLYNK_WRITE(TriggerMessageTimePin) {
  TriggerMessageTime = param[0].asInt()*60000;
}

BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.println("Started serial");

  delay(10);
  pinMode(ActivateDoorPin,OUTPUT);
  pinMode(DoorUpPin,INPUT);
  pinMode(DoorDownPin,INPUT);
  digitalWrite(ActivateDoorPin, LOW);

  Blynk.begin(auth, ssid, pass);
  Serial.println("Started blynk");

  setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)

  timer.setInterval(1000L, sendDoorstate); //timerinterval in milliseconds for execution procedure sendDoorstate
  Serial.println("Started timer");

  // Clear the terminal content
  terminal.clear();

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.flush();
}

void loop()
{
  Blynk.run();
  timer.run();
}

Credits

victormarinus

victormarinus

2 projects • 1 follower

Comments

Add projectSign up / Login