Hello everyone.
Here is my Garage Door Opener project. Yeap! Another Garage Door project. What the heck! I am attaching a manual sketch that I drew very quick so anyone can have an idea what I am talking about, plus some pics, and of course, my code. The sketch looks simple and so does the code, what is time consuming is the debugging process, testing, etc.
So here it’s more or less how it works:
GPIO 4 is the input(configure using the INPUT_PULLUP, so no external resistor needed. The internal resistor of the ESP8266 works very well) for a magnetic switch attached to garage door, when the door is open or close, Blynk notifies me, basically that is the only purpose of this switch, but very important to know if the door is open or close. More than once I’ve left the door open for so long, once was the whole night. No good.
GPIO 5 is the input(Same concept here, INPUTL_PULLUP is in action) of the magnetic switch that monitor but also commands to turn ON and OFF the lights in the attic. Blynk notifies me by email is this door has been opened. In my case, this is important .
GPIO 12 is the output that opens and closes the garage door. This pin is connected to a Fairchild MOSFET part number: FQP30N06L, when the Widget Button is pressed using virtual pin # 7, the MOSFET closes the circuit, so the door is open or close. Basically the MOSFET simulate the manual switch, actually the MOSFET Gate and Ground is connected in parallel with the manual sw. What is nice about this is that I can open the garage door two blocks away before I reach home, I love it! The 10K ohms resistor pulls the MOSFET gate to ground, so no false opening or closing if the main power goes off.
GPIO 15 is the output that turns ON and OFF the Attic’s lights when the door is open or close. This pin is connected to an OMRON TRIAC part # G3MB-202P. This TRIAC is 3.2V friendly. Pay attention to the HOT IN and HOT OUT, the load is connected between the HOT OUT and the Neutral wire of the 120V AC. This TRIAC don’t handle too much power, in my case is just about right.
An LED connected to +3.2V using a 100 ohms resistor tells me if the power is up.
Finally, I used the Adafruit Feather HUZZAH with ESP8266 plus FeatherWing Prototyping Add-on .
/* ********************************************************************************************
Garage Door Opener & Artic Light Control
Author: Alex Rodriguez / Los Angeles, CA - USA
Reviewed: Feb. 21, 2016
* ********************************************************************************************
*/
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
WidgetLED led1(V6);
WidgetLED led2(V9);
WidgetLCD lcd(V10);
int inPinVal ; // Virtual Pin Input
char auth[] = "blink token here";
void setup()
{
pinMode(4, INPUT_PULLUP); // Garage Door Magnetic Sensor
pinMode(5, INPUT_PULLUP); // Attic Lights Magnetic Sensor
pinMode(12, OUTPUT); // Pin Connected to the MOSFET's Gate, and a 10K pulldown(gate to ground) Resistor
pinMode(15, OUTPUT); // Pin connected to the TRIAC
Serial.begin(115200);
Blynk.begin(auth, "SSID", "password");
}
// ---------[ Widget Button using virtual pin # 7 ]--------------------
BLYNK_WRITE(V7)
{
if (param.asInt() == 0)
{
digitalWrite(12, LOW); //GPIO12
}
else
{
digitalWrite(12, HIGH); // GPIO12
}
}
// =================={ Virtual LEDs Garage Magnetic SW Monitoring }=========
void checkPin()
{
if (digitalRead(4)) // GPIO4
{
led1.off();
led2.off();
} else {
led1.on();
led2.on();
}
}
// ========{ Garage Magnetic SW Monitoring Input }==================
void garageMagSensor ()
{
int garageSensorSW = digitalRead(4); // GPIO4
if (garageSensorSW == LOW)
{
Blynk.virtualWrite(0, "CLOSE");
Blynk.virtualWrite(1, "CLOSE");
lcd.print(1, 0, "GARAGE IS CLOSED"); // LCD print, column 1, row 0.
}
else
{
Blynk.virtualWrite(0, "OPEN");
Blynk.virtualWrite(1, "OPEN");
lcd.print(1, 0, "GARAGE IS OPEN"); // LCD print, column 1, row 0
}
}
// ====================={ Attic Light Magnetic } =================================
void atticMagSensor()
{
int lightSensor = digitalRead(5); // Attic Magnetic Switch connected to GPIO5
if (lightSensor == LOW)
{
digitalWrite(15, LOW); // GPIO15
Blynk.virtualWrite(2, "CLOSE");
Blynk.virtualWrite(3, "CLOSE");
lcd.print(1, 1, "ATTIC IS CLOSED"); // LCD print, column 1, row 1
}
else
{
digitalWrite(15, HIGH); // GPIO15
Blynk.virtualWrite(2, "OPEN");
Blynk.virtualWrite(3, "OPEN");
lcd.print(1, 1, "ATTIC IS OPEN"); // LCD print, column 1, row 1
Blynk.email("myname@yahoo.com", "ATTIC DOOR OPEN!", "Attic door has been opened.");
}
}
// ==============( Void Loop ) ====================================
void loop()
{
garageMagSensor();
checkPin();
atticMagSensor();
Blynk.run();
yield();
}
The Adafruit Feather HUZZAH with ESP8266 is not shown here. Basically, all the wiring is done using the Prototyping Add-on, so if the ESP8266 needs to be reprogrammed, just pull it out very easy.
There you have it. All wires routed through the wall for a clean installation.