AI Security System w/ OpenCV & Raspberry Pi

Deon | April 13, 2024, 5:59 a.m.

In this blog post, I will detail how I leveraged OpenCV, a Raspberry Pi, and a simple buzzer to create a powerful yet compact home/vehicle security system. This setup not only demonstrates the capability of machine learning to enhance security but also highlights the impressive performance of these algorithms on the small yet mighty Raspberry Pi 4 B. Join me as I walk you through the step-by-step process of how I built this lightweight, AI-powered security system, from setting up the hardware to implementing the software, and see firsthand how machine learning can revolutionize your home/vehicle security. You can view a live demonstration of what exactly this system does at this link https://www.youtube.com/watch?v=IwMjOxbi540

My Hardware Setup:

The image above shows all the hardware I used to build what is essentially a smart, AI-powered motion sensor using Python, a Raspberry Pi, and any compatible Raspberry Pi camera. By harnessing the power of opencv and machine learning, this hardware setup will enable the raspi to identify specific objects. I will guide you through the process of creating a circuit that will activate a buzzer when the Raspberry Pi positively identifies the object it has been programmed to recognize. For example, my raspberry pi is programmed to only beep when it detects a person or humanoid figure. This project not only demonstrates the potential of AI in enhancing security systems but also showcases the versatility and capabilities of the little ol' Raspberry Pi in running advanced machine learning algorithms.

Where To Get The Hardware:

Almost everything in my hardware setup can be attained in from the freenove LCD 1602 Raspberry Pi kit which is available on amazon for around 20 bucks. The only things that are not included in that kit are the actual Raspberry Pi and the IR camera that I used. Those both must be purchased separately from the freenove kit. For this project I recommend using either the Raspberry 4 or 5. You can use any camera that is compatible with the Raspberry pi's camera terminal connection.

Preconfiguring The Pi:

If you don't have an operating system installed on your Raspberry Pi or you're not familiar with Linux commands, I highly recommend following the tutorial provided by Tim at Core Electronics. This tutorial will guide you through the process of setting up your Raspberry Pi from scratch and includes all the necessary links for the pre-trained machine learning model. It’s a comprehensive resource to get your project up and running smoothly.

The Buzzer Circuit:

I implemented a simple circuit that includes an active buzzer, which is powered by the 3.3V output from GPIO17 and grounded via the 6th GPIO pin on the Raspberry Pi. The camera module isn't part of this circuit but requires careful installation of the ribbon cable. Ensure the blue tape on the terminal side connecting to the Raspberry Pi is facing the USB and Ethernet ports. Similarly, the blue tape on the camera module side should face the same direction as the camera lens. This setup ensures proper connectivity and functionality for your AI-powered alarm system.

Results:

I customized the 'object-ident-3.py' file located in the 'Object_Detection_Files' folder from the Core Electronics tutorial to only identify a 'person' and to activate a buzzer upon positive identification. You can download my script from my GitHub repository at https://github.com/Starblastr/OpenCVraspberrypi. After downloading and unzipping the file, place the 'object-ident-3-buzzer.py' file in the 'Object_Detection_Files' folder. Ensure your hardware is set up correctly, then run the script. The still images above were captured from my Raspberry Pi's video feed and demonstrate the model's accuracy in identifying a person. Even when the person is partially out of view, the model reliably detects them. When the confidence level exceeds 0.50, the program draws a bounding box around the identified person and activates the buzzer, which beeps continuously as long as the person remains in the frame.