I have built a updated version of this project! Please check it out here:
https://www.hackster.io/k-gray/automated-driveway-gates-version-2
StoryProblem: My driveway is a public turn-around. Solution: gates. So we bought some gates, but getting out of the car to open two gates twice a day is really monotonous. I looked at automated gate kits, but they range from $400 - $900; in short, way too much. I decided to make my own, seeing that it would be more cost effective and much more fun!
Connecting the Motor Driver and Linear ActuatorsThe motor driver board I use has 10 pins; 2 gnd, 2 +5v, 2 pwm, and 4 io.
Driver - Arduino
5V - 5V
GND - GND
IN1 - D4
IN2 - D3
IN3 - D2
IN4 - D1
PWM does not have to be connected. Connect the linear actuator(s) to the black screw terminal(s). It does not matter which way you connect the linear actuator(s), but if you have two, you need to make sure that they are both connected the same way.
I am in the process of installing this and ran into a problem. The 3.3v logic output of the ESP8266's pins won't turn on the actuators. So I decided to connect the ESP8266 to the Arduino because the Arduino's logic level is 5v. I didn't have any logic level converters so I connected them in such a way that you don't need a logic level converter.
Arduino - ESP
A2 - D4
A3 - D3
A4 - D2
A5 - D1
optional:
A0 - 5V
A1 - GND
Powering the MicrocontrollerTo power this setup, I had a couple ideas. Most Arduinos have a VIN pin and a builtin voltage regulator so the VIN pin of the motor driver would be connected to the VIN pin of the Arduino. Some Arduinos though, like the Pro Mini do not have a builtin voltage regulator. This means we need an external voltage regulator, and the simplest idea, is to just use a 5v regulator connected to the VIN pin of the motor driver.
This setup needs a lot of Blynk parts. Here's what it's suppose to look like when done.
Start by downloading the Blynk app on your iPhone. Sign up and make a new project named "Driveway Gate".
Then add a new esp8266 device with wifi.
Next, tap your project page and select "Button" on the popout page.
Click the button and change the "Output" pin to "V0". Change the mode to "PUSH".
All the rest of the settings for each module are shown below.
Drill a hole in the side of the waterproof enclosure for a power cable and the linear actuator cables. Once everything is connected with jumper wires, place the motor driver, Arduino and ESP8266 inside the waterproof enclosure and screw the cover on. Install the box to your gate post, run the power cable to your house and run the linear actuator cables to the linear actuator(s).
For installing the linear actuator(s), use this website.
Setting Up Arduino IDEIf you need help installing or using the Arduino IDE, go to https://www.arduino.cc/en/Guide/HomePage
In the Arduino IDE, open a new sketch and paste the code "Automated-Driveway-Gates.ino". Or, go to the Github directory and download the code. If you paste the code, you will need to add a tab named settings.h as shown below.
Paste the "settings.h" code into this new tab, and you're ready to go. Upload the code and open the serial monitor on baud rate 9600.
Code Explanation(Updating as of July 23rd, 2021)
The code is made in such a way that you can change all the settings in a separate settings.h file instead of going through and changing the code.
//settings
boolean notifications = true;
boolean houseAlarm = true;
Set notifications
to true if you would like to be notified overtime the gates open or close (you can also delete the Blynk notifications widget on the app to disable notifications). Set houseAlarm
to true if you have set up your indoor alarm and would like I to buzz when the gates are opened. If you haven't set up the indoor alarm, just set this boolean to false
.
//magnet lock
#define MagnetRelay D7
This is the electromagnetic lock pin on the ESP8266.
//lights
boolean ledStrip = true;
#define red D1
#define green D8
#define blue D2
This is the settings for the LED strips. If you haven't set up your led strips, just set the boolean ledStrip
to false
. red
, green
, and blue
is the pins of the red, green, and blue on the LED strips.
//blynk
#define BLYNK_AUTH_TOKEN "your_auth_#1"
#define BLYNK_AUTH_TOKEN_2 "your_auth_#2"
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
#define BLYNK_YELLOW "#ED9D00"
#define BLYNK_BLUE "#04C0F8"
#define YOUR_LAT 80.472058
#define YOUR_LONG -20.495021
This the Blynk settings. Replace the top two tokens with your Blynk auth tokens to your devices. BLYNK_AUTH_TOKEN
is for the driveway gates ESP, and BLYNK_AUTH_TOKEN_2
is for the indoor house alarm (leave blank if you haven't done this).
//WiFi
char WIFI_SSID[] = "your_ssid";
char WIFI_PASS[] = "your_pass";
const char passWord[] = "maker"; //password of this device for OTA
WiFi settings. Replace the WiFi SSID with your own and the WiFi PASS with your own. passWord[]
is for your OTA password.
//GATE
#define gateNumber 2 //how many gates; 1 or 2
#define gateDirection 1 //1 or 2
int gateOpenAmount = 10; //only for automatic mode, seconds; only for on boot
String Mode = "button"; //automatic or button; only for on boot
Gate settings. gateNumber
is just the number of gates you are using (either 1 or 2). gateDirection
really doesn't need to be changed unless your gates are opening and closing opposite from the Blynk app. The last two settings don't need to be changed. They are only the settings that the ESP starts up with, but can be changed in the app.
#define BLYNK_PRINT Serial
#include "settings.h"
#include <math.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Including libraries and setting Blynk debugging to true.
int flag1 = 0;
int flag2 = 0;
int button;
int emergency;
int setting;
int delayAMOUNT;
int gpsSelect;
int distanceSelect;
int comingHome;
int openTest;
int closeTest;
int privacyMode;
int lightsIn;
float GPSLat;
float GPSLong;
float dist_calc=0;
float dist_calc2=0;
float diflat=0;
float diflon=0;
Defining variables to store information.
WidgetBridge alarm(V14);
BLYNK_CONNECTED() {
alarm.setAuthToken(auth2);
Blynk.syncAll();
Serial.println("Syncing...");
delay(1000);
}
BLYNK_WRITE(V0){
button = param.asInt();
}
BLYNK_WRITE(V1){
emergency = param.asInt();
}
BLYNK_WRITE(V2){
setting = param.asInt();
if (setting == 1) {
Mode = "automatic";
}
else if (setting == 0) {
Mode = "button";
}
}
BLYNK_WRITE(V3){
gateOpenAmount = param.asInt();
}
BLYNK_WRITE(V4){
delayAMOUNT = param.asInt();
}
BLYNK_WRITE(V5){
GpsParam gps(param);
GPSLat = gps.getLat();
GPSLong = gps.getLon();
}
WidgetLED led(V6);
BLYNK_WRITE(V8){
gpsSelect = param.asInt();
}
BLYNK_WRITE(V9){
distanceSelect = param.asInt();
}
BLYNK_WRITE(V10){
comingHome = param.asInt();
}
BLYNK_WRITE(V12){
openTest = param.asInt();
}
BLYNK_WRITE(V13){
closeTest = param.asInt();
}
BLYNK_WRITE(V15){
privacyMode = param.asInt();
}
BLYNK_WRITE(V16){
lightsIn = param.asInt();
}
Lots of Blynk inputs.
void setup()
{
Serial.begin(9600);
if (ledStrip == true){
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
if (gateNumber == 1){
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);
}
else if (gateNumber == 2){
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);
pinMode(b1, OUTPUT);
pinMode(b2, OUTPUT);
}
pinMode(MagnetRelay, OUTPUT);
In setup()
, the serial monitor is started at 9600 (this can be changed to anything you want and is really only for debugging) and setup the pin modes for the actuators, LEDs, and magnet lock.
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID,WIFI_PASS);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
OTAStart();
Blynk.config(BLYNK_AUTH_TOKEN);
Also in setup()
, WiFi is started, OTA is started and Blynk is connected. Here, I used WiFi.begin()
and Blynk.config()
instead of the previous Blynk.begin()
because of OTA.
led.on();
led.setColor(BLYNK_RED);
alarm.virtualWrite(V1, LOW);
Still in setup()
, the Blynk LED is started and the indoor alarm is set to off (LOW
).
void loop() {
ArduinoOTA.handle();
Blynk.virtualWrite(V11, WiFi.RSSI());
if (flag1 == 0){
ledtrip();
}
if (privacyMode == 2 || privacyMode == 3){
ledstrip(0,0,0);
}
if (openTest == 1){
Serial.println("open test");
openGate();
delay(500);
}
else {
allStop();
}
if (closeTest == 1){
Serial.println("close test");
closeGate();
}
else {
allStop();
}
if (button == 1){
Serial.println("Button pressed.");
gates();
}
if (gpsSelect != 1){
Blynk.virtualWrite(V7,calcDist(GPSLat, GPSLong, YOUR_LAT, YOUR_LONG));
if (comingHome == 1){
Serial.println(calcDist(GPSLat, GPSLong, YOUR_LAT, YOUR_LONG));
if (calcDist(GPSLat, GPSLong, YOUR_LAT, YOUR_LONG) < distanceSelect){
Serial.println("GPS triggered!");
opengates();
}
}
}
Blynk.run();
}
In the loop, everything important is accomplished with the use of functions to make it simpler and less clogged up. First, signal strength is written to virtual pin 11. Then, the LEDs are turned on or off according to the settings. Next, we handle the main gate button on Blynk. Lastly, we handle GPS and put Blynk.run();
to stay connected to the Blynk server.
void gates(){
if (Mode == "automatic"){
Serial.println("Mode = Automatic");
if (notifications == true){
Blynk.notify("Driveway Gates were opened!");
}
Serial.println("Opening gate...");
led.setColor(BLYNK_BLUE);
if (privacyMode == 1 || privacyMode == 2){
ledstrip(0,0,255);//blue
}
if (houseAlarm == true){
alarm.virtualWrite(V1, HIGH);
}
magnetOff();
openGate();
waitForGate();
allStop();
led.setColor(BLYNK_GREEN);
if (privacyMode == 1 || privacyMode == 2){
ledstrip(0,255,0);//green
}
Serial.println("Open.");
Serial.println("Waiting...");
delay(gateOpenAmount*1000);
if (notifications == true){
Blynk.notify("Driveway Gates were closed!");
}
Serial.println("Closing gate...");
led.setColor(BLYNK_BLUE);
if (privacyMode == 2){
ledstrip(0,0,255);//blue
}
closeGate();
waitForGate();
allStop();
magnetOn();
led.setColor(BLYNK_RED);
if (privacyMode == 1 || privacyMode == 2){
//turn leds on red for 4 seconds after shutting
ledstrip(255,0,0);//red
delay(4000);
ledstrip(0,0,0);//off
}
Serial.println("Closed.");
}
else if(Mode == "button"){
Serial.println("Mode = Button");
if (flag1 == 0){
if (notifications == true){
Blynk.notify("Driveway Gates were opened!");
}
Serial.println("Opening gate...");
led.setColor(BLYNK_BLUE);
if (privacyMode == 1 || privacyMode == 2){
ledstrip(0,0,255);//blue
}
if (houseAlarm == true){
alarm.virtualWrite(V1, HIGH);
}
magnetOff();
openGate();
waitForGate();
allStop();
led.setColor(BLYNK_GREEN);
if (privacyMode == 1 || privacyMode == 2){
ledstrip(0,255,0);//green
}
Serial.println("Open.");
flag1 = 1;
}
else if(flag1 == 1){
if (notifications == true){
Blynk.notify("Driveway Gates were closed!");
}
Serial.println("Closing gate...");
led.setColor(BLYNK_BLUE);
if (privacyMode == 1 || privacyMode == 2){
ledstrip(0,0,255);//blue
}
closeGate();
waitForGate();
allStop();
magnetOn();
led.setColor(BLYNK_RED);
if (privacyMode == 1 || privacyMode == 2){
ledstrip(255,0,0);//red
delay(4000);
ledstrip(255,0,0);//off
}
Serial.println("Closed.");
flag1 = 0;
}
}
}
This is the main function to open the gates. Basically, for preparation, it notifies you, then changes the Blynk LED to blue, then changes the gate LEDs to blue, then turns off the magnet lock. Next it opens the gates, and waits till they're open. Then it waits either the amount of time you set in the Blynk app if its on automatic, or until you press the gate button again on button. Then the gates are closed, the magnet locks, the Blynk LED is changed to red, and the gate LEDs are changed to red for 4 seconds.
void openGate(){
if (gateDirection == 1){
if (gateNumber == 1){
digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
}
else if (gateNumber == 2){
digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
digitalWrite(b1, HIGH);
digitalWrite(b2, LOW);
}
}
else if (gateDirection == 2){
if (gateNumber == 1){
digitalWrite(a1, LOW);
digitalWrite(a2, HIGH);
}
else if (gateNumber == 2){
digitalWrite(a1, LOW);
digitalWrite(a2, HIGH);
digitalWrite(b1, LOW);
digitalWrite(b2, HIGH);
}
}
}
void closeGate(){
if (gateDirection == 1){
if (gateNumber == 1){
digitalWrite(a1, LOW);
digitalWrite(a2, HIGH);
}
else if (gateNumber == 2){
digitalWrite(a1, LOW);
digitalWrite(a2, HIGH);
digitalWrite(b1, LOW);
digitalWrite(b2, HIGH);
}
}
else if (gateDirection == 2){
if (gateNumber == 1){
digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
}
else if (gateNumber == 2){
digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
digitalWrite(b1, HIGH);
digitalWrite(b2, LOW);
}
}
}
void allStop() {
if (gateNumber == 1){
digitalWrite(a1, LOW);
digitalWrite(a2, LOW);
}
else if (gateNumber == 2){
digitalWrite(a1, LOW);
digitalWrite(a2, LOW);
digitalWrite(b1, LOW);
digitalWrite(b2, LOW);
}
}
void waitForGate() {
int tim = 5500;
Begin:
flag2++;
while(flag2 < tim){
Blynk.run();
delay(2);
Serial.println(flag2);
goto Begin;
}
flag2 = 0;
/* coming soon
delay((inchesPerSec*(maxActuatorStroke/percentOfMaxStroke))*1400);
*/
}
void opengates(){
Serial.println("Mode = Button");
Serial.println("Openning gate...");
led.setColor(BLYNK_BLUE);
openGate();
waitForGate();
allStop();
led.setColor(BLYNK_GREEN);
Serial.println("Open.");
timer = 1;
}
These are all functions for opening and closing the gates.
float calcDist(float CurrentLatitude, float CurrentLongitude, float SavedLatitude, float SavedLongitude)
{
// HaverSine version
const float Deg2Rad = 0.01745329252; // (PI/180) 0.017453293, 0.0174532925
//const double EarthRadius = 6372.795; //6372.7976 In Kilo meters, will scale to other values
const float EarthRadius = 20908120.1; // In feet 20908128.6
float DeltaLatitude, DeltaLongitude, a, Distance;
// degrees to radians
CurrentLatitude = (CurrentLatitude + 180) * Deg2Rad; // Remove negative offset (0-360), convert to RADS
CurrentLongitude = (CurrentLongitude + 180) * Deg2Rad;
SavedLatitude = (SavedLatitude + 180) * Deg2Rad;
SavedLongitude = (SavedLongitude + 180) * Deg2Rad;
DeltaLatitude = SavedLatitude - CurrentLatitude;
DeltaLongitude = SavedLongitude - CurrentLongitude;
a =(sin(DeltaLatitude/2) * sin(DeltaLatitude/2)) + cos(CurrentLatitude) * cos(SavedLatitude) * (sin(DeltaLongitude/2) * sin(DeltaLongitude/2));
Distance = EarthRadius * (2 * atan2(sqrt(a),sqrt(1-a)));
Blynk.virtualWrite(V7, Distance);
return(Distance);
}
Here I used the Haversine formula to find the distance from our phone to the gate.
void OTAStart(){
// Port defaults to 8266
ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname("DrivewayESP");
// No authentication by default
ArduinoOTA.setPassword(passWord);//(const char
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
This function is for starting the OTA.
void ledtrip(){
if (privacyMode == 1){ //normal
if (lightsIn == 1){
ledstrip(255,0,0); //red
}
if (lightsIn == 2){
ledstrip(255,145,0); //orange
}
if (lightsIn == 3){
ledstrip(255,255,0); //yellow
}
if (lightsIn == 4){
ledstrip(0,255,0); //green
}
if (lightsIn == 5){
ledstrip(0,0,255); //Blue
}
if (lightsIn == 6){
ledstrip(145,0,255); //Purple
}
if (lightsIn == 7){
ledstrip(255,255,255); //white
}
}
}
void ledstrip(int r, int g, int b){
analogWrite(red, r);
analogWrite(green, g);
analogWrite(blue, b);
}
These are two functions for lighting the gate LEDs. You can change the RGB values in the first function for any colors you want.
Blocking Underneath(Updated as of June 9th 2021)
We are going on vacation soon for a day! But we have some cats and a dog. They seem to love to get out by going under the gates and I DO NOT want that to happen when we are gone all day. We also have an electric fence for keeping our goats in, so I thought of an idea. Use the same fence! I ran an electrical wire to the gate post, then got a little stuck. How would I electrify under the gates? And then I had another question; how would both gates be electrified when they open? I decided to wrap the electrical wire around a PVC pipe (non-conductive) and hang the pipe beneath each gate with some string. At the middle of the gates where they meet, I wrapped each pipe with the electrical wire over and over, creating a bundle. So when the gates close, the pipes touch in the center and the whole thing is electrified! The only downfall is that when the gates are open, one side is not electrified.
(Updated as of July 23rd 2021)
This is an update for adding ALPR and text messages to your gates! The Raspberry Pi takes a photo and checks to see if there is a car in it. If there is, it sends it to Sighthound, which then returns the results. It tells you the make, model, color, type, region, and plate number! Once it has this info, it texts your phone with all of it! And if the License plate matches stored favorites, it opens the gates!!
Parts:
- Raspberry Pi (I'm using a 3b+)
- Raspberry Pi Camera (I'm using a aftermarket with IR lamps)
Services:
Code:
- All of the code can be found in the same Github repository.
Requisites:
- Basic knowledge of Python
- Basic knowledge of the Raspberry Pi
- Use of terminal
- Raspberry Pi (3b or 4b) with Raspberry Pi OS installed
How to Start:
First, open /Python-RPiCam/config/config.json. Fill in all of the twillio information.
Next, open terminal and type sudo
apt-get
update
and then sudo
apt-get
upgrade
. These two commands can take a long time because this is updating your RPi, so be patient. While your'e waiting, feel free to read through the rest of this tutorial, click the thumbs up, or post a comment :) .
When updating and upgrading is finished, type cd
and then the directory name for this python code (example: cd /home/pi/Downloads/Python-RPiCam). Next, type python lpr-recognition.py
into the terminal and hit enter. There might be some invalid path returns. Just recheck them for the correct ones or ask a question in the comments.
Starting on Boot:
To have it start automatically on boot up, follow this tutorial:
https://www.pyimagesearch.com/2016/05/16/running-a-python-opencv-script-on-reboot/
How it Works:
What this code does is first takes a picture and saves it as "image.jpg" in the python code folder. Next, this image is checked for cars, and if there is one, it is forwarded to Sighthound's ALPR API service, which returns all the useful info. Next, this info is organized and texted to you, and, if the plate number matches with either of the ones on lines #276 and #284, then you are texted again, and the Blynk gate button is pressed from the RPi. Voila! There you have ALPR based automated gates!
House Alarm(Updated as of July 15th 2021)
Lots of times, I want to know when someone gets home. So I made a indoor notifier! It is really simple, just using a ESP8266 and a 90dcB buzzer (really, REALLY, loud). Just connect the negative pin of the buzzer to the ESP's GND, and the positive pin of the buzzer, to ESP's D2 (GPIO4). I put the two components inside a little plastic case and used the ESP's USB port for the power cable.
Code:
Because this is another WiFi board, it needs its own code also. You will need to setup another ESP8266 module in Blynk. The code utilizes "bridge" in Blynk. I changed the code of the driveway gates ESP so that every time the gate is opened, it sends a value of 1 to the indoor ESP. When the indoor ESP reads that value, it buzzes! I also changed the Blynk app to include buzzer on delay time, buzzer off delay time, and amount of time it buzzes; essentially, you can create your own unique buzzer sequence whenever from the app! I tried it out with my mom, and she said she liked it off more than on (300ms on, 700ms off).
NOTE: The input delay times for the buzzer are in milliseconds, not seconds. (1 second = 1000 milliseconds)
Driveway_Gates_House_Alarm.ino (also found in Github repository):
/*************************************************************
File Name: Driveway_Gates_House_Alarm.ino
Processor/Platform: ESP8266 (D1-Mini tested)
Development Environment: Arduino 1.8.15
Download latest code here:
https://github.com/Kgray44/Automated--Driveway-Gate
Driveway Gates code meant to be used alongside the tutorial found here:
https://www.hackster.io/k-gray/new-automated-driveway-gates-ef5c75
Copyright 2021 K Gray
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Liscense found here:
https://opensource.org/licenses/MIT
*************************************************************/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define bridgePin D2
int times=0; //amount of times alarm repeats set in app
int delay1=0; //the duration of the first delay in milliseconds set in app
int delay2=0; //the duration of the second delay in milliseconds set in app
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "nGIhBbKBYHv9wGH2umEIvGOkwDwJ24ay";
char WIFI_SSID[] = "Apple Network 85064d";
char WIFI_PASS[] = "12344321";
WidgetBridge gates(V14);
BLYNK_CONNECTED() {
gates.setAuthToken("xRH8NnsHrOGi9utKIbLg0pp5Q5gaHtE9"); // Place the AuthToken of the second hardware here
}
BLYNK_WRITE(V1){
int input = param.asInt();
Serial.println(input);
if (input == 1){
for (int i=0;i<times+1;i++){
digitalWrite(bridgePin, HIGH);
delay(delay1);
digitalWrite(bridgePin, LOW);
delay(delay2);
}
}
}
BLYNK_WRITE(V2){
delay1 = param.asInt();
}
BLYNK_WRITE(V3){
delay2 = param.asInt();
}
BLYNK_WRITE(V4){
times = param.asInt();
}
void setup(){
Serial.begin(9600);
pinMode(bridgePin, OUTPUT);
Blynk.begin(auth, WIFI_SSID, WIFI_PASS);
}
void loop(){Blynk.run();}
Before you upload your code, make sure to change both auth tokens, your WiFi network, and your WiFi password.
LED Lights(Updated as of July 16th 2021)
After a while of using these gates, I decided to add some lights, so I don't hit them in the dark. Because the main road is close to the gates I have to pull up very close to them to prevent from being hit by a car. I used two 12V waterproof RGB LED strips (one for each gate). I also updated Blynk, so that you can now select privacy mode and led colors. Privacy mode menu is 3 different levels of privacy. There is "Normal", "Privacy 1", and "Privacy 2". On "Normal", the gates light up whatever color you selected on the app, and when you open the gates, they turn blue, when the gates are open, they are green, and when the gates are closing, they are blue again. "Privacy 1" just eliminates the gates lighting up all the time, so they only light up when opening and closing, and "Privacy 2" eliminates the lights altogether.
Connecting the LED Strip to the ESP8266:
The LED strip is controlled by the ESP8266 through transistors. I used STP90NF03L N-Channel MOSFETs because that is the only TO-220 transistor I have three of for the moment. When you choose your transistors, make sure that they can handle the amperage of your LED strips. I have 8-foot gates, so I bought 2x 9-foot LED strips (60 LEDs per meter). That would equal 0.006 (60mA) * 180 (9-foot = 3 meters) = 1.08A * 2 led strips = 2.16A. The STP90NF03L can handle 90A; way more than I need. You can also use this website if you would like to learn more https://learn.adafruit.com/rgb-led-strips/usage.
(Updated as of July 21st 2021)
I had a situation a couple of days ago that made me very nervous. A box truck stopped on the side of the road a little ways down from my house, and a woman got out with an empty black duffel bag. She walked along the road and then down my driveway and pushed open my gates! Luckily, she saw my dog, so ran back out and across the road. Before I was finished witnessing this, I was thinking of ways to prevent such an easy access. I settled on a electromagnetic lock; they are very strong and can be controlled electrically. I got one off of amazon with brackets that is rated for outdoors and 1300lbs! It is controlled with a AS2304 n-channel MOSFET that is capable of 40V, 2.5A (the electromagnetic lock uses 12V, 0.5A). I changed the code to have it unlock right before opening, and lock right after closing.
(Updated as of April 8th 2021)
This is an update on this project. I have now been working on perfecting a PCB for this project since I wrote it. I have tried 5 different designs, and through much trial and error, have finally got a working design, that needed no troubleshooting at all! It utilizes the high Iout of the RZ7886 at 13A! Each driver is only capable of driving one motor though, so I used two of them. Here is the parts list for the PCB:
- Buzzer (optional)
- 470µf Electrolytic Capacitor
- 4x 10µf Ceramic/Electrolytic Capitors
- Diode (I used DS34W)
- NPN Transistor (I used AS2304)
- 4x 10kΩ Resistors (Optional)
- L7805CV
- AMS1117-3.3 (Optional)
- Wemos D1-Mini
- ESP-12F (Optional)
- 2x RZ7886
The schematic/PCB can be found here. I used LCSC.com for parts, JLCPCB.com for PCBs, and EasyEDA.com for PCB designing.
Here is a picture of the completed setup with everything labelled:
Here is a video of it working:
Wrapping UpIf you have any questions, please post in the comments! And check out my other tutorials!
and my website
Comments