Automated Driveway Gates Version 2 - Hackster.io

2022-11-03 14:21:18 By : Ms. min chen

Add the following snippet to your HTML:

This is a second tutorial for making DIY automated driveway gates for relatively cheap using Arduino, ESP32, Raspberry Pi, and Blynk!

Read up about this project on

This is a second tutorial for making DIY automated driveway gates for relatively cheap using Arduino, ESP32, Raspberry Pi, and Blynk!

This tutorial is a second version of my previous award winning Automated Driveway Gates project. It includes new upgraded linear actuators that have built-in hall sensors, a new mainboard consisting of an ESP32, a new double motor driver module capable of 15A @ 13.8V per channel, and a new waterproof ultrasonic sensor!

As I just explained, there are many new and better components in this build.

Dfrobot is an awesome electronics company! They kindly sponsored their parts to me for this project. They have anything you could need for any project of every type! You can check my other projects for more awesome things you can build with their parts. Check them out here! https://www.dfrobot.com

The wiring may look complicated, but is pretty straightforward once you dive in ?.

If this description doesn't make sense (I would totally agree), you can follow the schematic that I drew:

Blynk has been updated ?! Personally, I don't like the new version; it is harder to use, has less features than the previous one, and is pricey.

This is how the desktop template should look when completed:

Here is the mobile app Template:

If you need help setting up Blynk, refer to the documentation found here:

https://docs.blynk.io/en/

The code is quite long for this project! Keep in mind that you will probably have to change some things to get it to work how you would like for your setup. For example, my left actuator seemed to open slower than it closed, so I had to adjust the opening and closing functions to account for that.

First, we have to setup the Blynk credentials. Enter your template id, device name, and auth token on the indicated lines.

Next, all of the libraries are included that we need; WiFi, Blynk, OTA, and software serial.

Here, we define what pins go to which parts. Any numbers not beginning in "D" are "IO" pins on the FireBeetle.

Here are the current sensor readings and variables, but this part isn't working at the time of this writing. I hope to update it soon!

All of these variables have to be changed! First is the ppi variable, which stands for "Pulses Per Inch". This value is dependent on the linear actuator you use, but is the amount of pulses from the hall sensor per inch. Next, is the usedAct variable. This variable is the amount of inches on the linear actuator that are used. You may need to adjust this number several times to get the desired effect. Lastly, are the WiFi credentials. Enter you WiFi network name and password that you would like your module connected to.

These are all of the rest of the variables used. The only one that might need altering, is the carDist variable. This is the amount of inches before a car is defined as being there.

Here, we define an instance of software serial for the ultrasonic sensor.

These are all of the Blynk functions for receiving values.

This is a Boolean variable to indicate if the gates are open or closed.

PWM on an ESP32 is a little more complicated but more customizable, than on an Arduino. Here, we set the frequency, resolution, and then channels for what needs PWM.

In voidsetup(), we first start the serial for debugging (keep in mind this only works if the device is connected to your PC with a wire; not OTA), start the serial for the ultrasonic sensor, and check to make sure the sensor has started.

Next, we set the pinmodes for everything; they are all outputs except for the hall sensor, which is an input pull-up.

Here, the PWM is setup! First, we attach the pins to the correct channels, then we setup the channel frequency and resolution for each one.

These three parts get our wireless up and running. First, we connect to the WiFi, then we configure Blynk, and finally, we start the OTA. The OTA default password is "maker"; this can be changed in the OTAStart(); function.

The gate setting up finishes the voidsetup(); function. First, the gates are opened all of the way without using the hall sensor. This serves like a form of calibration, because when the gates are fully opened to their limit, we then know where the hall sensor is at! Next, we attach the hall sensor, because if we attach the hall sensor interrupt before the beginning opening function, the hall sensor will start counting, and we do not want to do that for the calibration. Now we can close to the correct place counting the hall pulses as we go, to make sure they shut correctly. Now that they are shut, we set the gate status boolean to false, to indicate that the gates are successfully closed.

In voidloop(), we first check our WiFi connection, and handle OTA.

Here, we read the ultrasonic sensor several times to make sure we get a good reading. Then we send the value to Blynk, and check to see if there is a car and update the LED on Blynk accordingly.

If the Gates button is pressed on Blynk, switch the flag. If the flag is true, and the gates are closed, shut off the magnet, open the gates, and set the status to open! If the flag is false and the gates are open, close them, turn the magnet on, and set the status to closed.

In the last part in the voidloop(), the Blynk values are written to the LED strips, Blynk is ran, and we make sure to yield();. If we don't add the yield, the ESP32 will restart unexpectedly, and can cause problems.

These are all of the functions I made to simplify the code. Notice how the last function is different? That is the interrupt function. For more about interrupts on ESP32, check out this link:

https://lastminuteengineers.com/handling-esp32-gpio-interrupts-tutorial/

Here is the finished box:

That was all for this tutorial! If you liked it, give it a thumbs up! Please feel free to post in the comments for any questions, ideas, advice, suggestions, and so on!

Check out this link for more awesome projects:

https://www.hackster.io/k-gray

Hackster.io, an Avnet Community © 2022