ESP32 Cam, Python OpenCV, Yolov3, & Arduino based Car Parking Barrier/Gate Control

ESP32 Cam Car Parking Barrier Control:

An image showcasing an ESP32-CAM, Python OpenCV, YOLOv3, and Arduino-based car parking barrier gate control system.

ESP32 Cam, Python OpenCV, Yolov3, & Arduino based Car Parking Barrier/Gate Control- Last year, I created a video on a car barrier control system, in which I used an ultrasonic sensor to control the car barrier/gate. That project is suitable for beginners. However, in reality, that project is not practical at all. This is because an ultrasonic sensor can only sense the presence of objects and measure their distance, but it cannot identify those objects. Therefore, if any object comes in front of the ultrasonic sensor, it would open the car barrier/gate, which is not ideal.

So, I thought, why not take that project to a slightly advanced level? So, this time, I will be using the Arduino along with ESP32 Cam for wireless live video streaming, and for the image processing, I am going to use Python OpenCV YoloV3. Now, the barrier/gate will only open for cars. It will not open for any other objects.

This project is entirely based on my previous project, where I explained the most basic things, such as:

How to perform wireless video streaming using the ESP32 Cam module?

How to install Python, OpenCV, and YoloV3? and

How to detect and identify different objects?

An image showcasing an ESP32-CAM for object detection and identification using Python OpenCV and YOLOv3.

In my studio, I detected and identified various objects, and not only did I identify and track birds and cats, but I also displayed alert messages on the screen.

An image showcasing animals identification using ESP32 camera and Python OpenCV YOLOv3.

So, I have already explained all of these things, and I won’t repeat them today. Today, I will only explain new things. Including,

Servo motor interfacing with Arduino and its programming.

How to detect and identify a car? And

How to send car barrier/gate opening and closing commands to Arduino from Python OpenCV YoloV3. So, without any further delay, let’s get started!

Amazon Links:

ESP32 Camera Module

ESP32 CAM W-BT Board

MSI Intel Core i7 Laptop check this out.

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

An image showcasing servo interfacing with Arduino and ESP32-CAM using Python.

I am using my Arduino Nano and LoRa based development board. But you can do the same exact connections on a breadboard. Anyway, connect the signal wire to the Arduino pin9, and connect the VCC and GND wires of the Servo to the Arduino 5V and GND pins. You can follow this circuit diagram.

Servo with Arduino, Circuit Diagram:

An image showcasing a servo motor controlled by Arduino Nano through Python OpenCV.

And let me also tell you. If you are planning on using large servo motors like the ones you can see on the screen.

An image showcasing large servo motors controlled with Arduino.

Then don’t use 5V from the Arduino because it might damage your Arduino board. So, use an external 5V power supply.

A power supply unit labeled as 5V 3A for an Arduino ESP32 Cam Car Parking Barrier

On my development board, I have this 5V and 3A power supply and its more than enough for powering these all types of servos. So, you can make yourself this development board, or you can make yourself this 5V and 3A power supply and then you can use it with different microcontroller boards, servos, breakout boards, and even you can use this 5V and 3A power supply to charge your cell phone.

An image displaying a high-ampere regulated 5V power supply for the Arduino.

Now, let’s go ahead and take a look at the Arduino programming.

Car Barrier/Gate Control Arduino Programming:

I started off by adding the Servo.h header file. You can see the Servo signal wire is connected to the Arduino pin 9. The Sflag variable I am going to use as the flag, I could also define it as Boolean but, anyway, I am using it to stop the unnecessary repetition of code.

In the void loop() function, we simply check if any data is available on the Serial port, or in simple words if any data is received from the Python. In my case, I send two numbers from python. So, that’s why I have used parseInt().

So, if the received number is 1 and the Sflag == 0 then move the Servo arm to 900 and change the Sflag state to 1. So, these instructions will only execute once.

If the received number is 2 and the Sflag == 1 then move the servo arm to 00

I have already uploaded this program. And now let’s take a look at the Python OpenCV YoloV3 programming.

Altium Designer + Altium 365 + Octopart:

Arduino LoRa Free SMS

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan.

Get real-time component insights as you design with Octopart built into Altium 365. Octopart is the fastest search engine for electronic parts and gives you the most up-to-date part data like specs, datasheets, cad models, and how much the part costs at different amounts etc. Right in the design environment so you can focus on your designs. Start with Altium Designer and Activate Altium 365. Search for electronic parts on Octopart.

Python OpenCV YoloV3 programming:

This is the same exact program from my previous project. You can see I am using the same IP Address.

Through this ip address I receive high quality images from the ESP32 Camera module. I have already explained, how to setup your ESP32 camera module for the live video streaming.

This is the Arduino_port. My Arduino board is connected to the communication port11 and 9600 is the baud_rate.

This time round, I am using coco.names for the detection and identification of a car. If you open the coco.names file, you will see a long list of the objects. So, you can select any of those objects for controlling the Car barrier/Gate. In my case I am going to continue with a car.

These are the instructions used to send the commands 1 and 2. When the car crosses line1, it sends 1 to the Arduino to open the Barrier and when the Car crosses line2 then it sends 2 to the Arduino to close the Barrier.

Now, let’s go ahead and start our practical demonstration.

Car Barrier/Gate control system using ESP32 Cam and Arduino:

An image depicting an ESP32-CAM car barrier or gate control system.

In the above image, you can see the Car parking barrier/gate is closed. The parking barrier will only open, when the car will cross the line.

An image depicting an ESP32-CAM car parking barrier control system using a servo, Python OpenCV, and Arduino.

In the image above, you can see the Car Parking barrier is opened. It will stay open as long as the car doesn’t cross the line2”red line”.

An image depicting an ESP32-CAM car tracking and gate control system using Python OpenCV and Arduino.

And in this image, you can see the Car parking barrier is closed. For the practical demonstration watch the video tutorial given below.

A car parking barrier gate control system utilizing ESP32 Cam, Arduino, Python OpenCV, and YOLOv3

Watch Video Tutorial:


Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button