Smart Home Security System With ESP32

by shir_raban in Circuits > Electronics

431 Views, 1 Favorites, 0 Comments

Smart Home Security System With ESP32

WhatsApp Image 2024-08-06 at 18.28.05 (1).jpeg

In this tutorial, we will guide you through the development of a sophisticated Smart Home Security System utilizing an ESP32 microcontroller. This project aims to enhance home security through advanced sensing technology and real-time monitoring.

Project Overview:

Our security system integrates several key components to monitor and respond to potential security threats. By combining an ultrasonic sensor, a piezoelectric vibration sensor, and a programmable LED strip with modern software tools, we will create a comprehensive security solution. The system is designed to detect intrusions, monitor vibrations, and provide timely notifications.

Here is the link to a video fully describing the system functionality:

LINK

Supplies

  • ESP32 microcontroller
  • Ultrasonic distance sensor
  • Piezo vibration sensor
  • 12-LED strip
  • Jumper wires and breadboard

Set Up Blynk App

Download the Blynk app to your smartphone.

If you don't have a Blynk account, create one.

Else, log in to your Blynk account.

Create a New Blynk Project

Open the Blynk app and create a new project.

Select ESP32 as the device and choose Wi-Fi as the connection type.

Copy the Auth Token sent to your email, this will be used in your code.

Create a Datastream

WhatsApp Image 2024-08-06 at 18.08.08.jpeg
WhatsApp Image 2024-08-06 at 18.07.52.jpeg

Go to the Datastreams section.

Create new datastreams for distance and vibration.

Generate Events on the Datastreams

WhatsApp Image 2024-08-06 at 18.12.55.jpeg
WhatsApp Image 2024-08-06 at 18.14.03.jpeg
WhatsApp Image 2024-08-06 at 18.13.42.jpeg

Create a New Event:

  • Navigate to the Events section in Blynk.
  • Click Add New Event to start creating a new event.

Configure Event Details:

  • Event Name: Choose descriptive names for your events, such as "Intrusion Detected" and "Vibration Detected."
  • Event Code: Assign a unique code to each event.
  • Description: Write a brief description for each event.

Set Up Notifications:

  • Configure how and when you want to be notified about each event.

Create Widgets on the Datastreams

WhatsApp Image 2024-08-06 at 18.10.27.jpeg
WhatsApp Image 2024-08-06 at 18.09.45 (1).jpeg
WhatsApp Image 2024-08-06 at 18.11.34.jpeg

Add widgets to your Blynk project to display data from your datastreams:

  • Distance Widget: Add a Value Display widget to show the distance measurement. Set it to Virtual Pin V1.
  • Vibration Widget: Add another Value Display widget to show vibration levels. Set it to Virtual Pin V2.

For visualization, use a Chart widget and set chart settings.


Create a Make.com Account

If you don't have a make.com account, create one.

Else, log in to your make.com account.

Create Scenarios

Screenshot 2024-08-06 192703.png
  • Click + Create a new scenario.
  • Select Webhooks and choose Custom Webhook.
  • Create Webhook:
  • Intrusion Event: Handle incoming webhook requests for intrusion detection.
  • Knock Event: Manage webhook requests for vibration detection (knocks).
  •  Copy the provided URL. You'll use these URLs in your ESP32 code.

Define Scenario Flow

WhatsApp Image 2024-08-06 at 18.02.43.jpeg
WhatsApp Image 2024-08-06 at 18.02.29.jpeg

Add HTTP Module: Configure it for handling incoming data or performing additional HTTP requests.

Add Google Spreadsheet Module: Set it up to log data or manage records.

Define Flow: Ensure the flow is Webhook → HTTP → Google Spreadsheet.

Add a Telegram Bot

Follow this guide to set up a Telegram bot.

Add the bot as an admin to your Telegram channel to enable it to send messages.

Set the HTTP and Google Sheets Scenario

WhatsApp Image 2024-08-06 at 18.04.28.jpeg
WhatsApp Image 2024-08-06 at 18.04.28 (1).jpeg
WhatsApp Image 2024-08-06 at 18.05.06.jpeg

HTTP:

  • Put the bot URL link.
  • Content Type: Set to application/json.
  • Request Content: Include the Telegram chat ID and message text in JSON format.

Google Sheets:

  • Create Spreadsheet: Set up a new spreadsheet with columns for Timestamp, Scenario ID, Status Code, etc.

Save and Activate

Save, test with Run Once, and activate the scenario.

Verify the data is correctly logged and the notifications are sent properly.


Wire the Components

Ultrasonic Sensor:

  • Trig Pin to GPIO 16
  • Echo Pin to GPIO 17
  • VCC to 5V
  • GND to GND

Vibration Sensor:

  • Signal Pin to GPIO 34
  • VCC to 5V
  • GND to GND

LED Strip:

  • Data Pin to GPIO 13
  • VCC to 5V
  • GND to GND

Download PlatformIO in Visual Studio Code

Instead of the Arduino IDE, we used PlatformIO, a powerful extension for Visual Studio Code, to program the ESP32. 

Install Visual Studio Code:

Install PlatformIO Extension:

  • Use this step-by-step guide to install PlatformIO Extension


Write the Code

Screenshot 2024-08-07 194705.png
  • Define your Blynk credentials, WiFi credentials, and include necessary libraries.
  • Define pin numbers for the ultrasonic sensor, vibration sensor, and LED strip.
  • Set the webhook URLs and port for make.com.
  • implement the necessary functions: 
  • sendWebhook function
  • flashLEDs function
  • setup function
  • loop function

Downloads

Upload the Code

Screenshot 2024-08-07 174112.png

Connect your ESP32 to your computer.

Click the PlatformIO icon and select Upload to compile and upload your code to the ESP32.

Test the System

Screenshot 2024-08-07 194426.png
WhatsApp Image 2024-08-07 at 19.54.35.jpeg

To ensure your Smart Home Security System is working correctly, follow these steps:

  • Monitor Serial Output: Open the Serial Monitor in your IDE to observe system outputs and debug information.
  • Connect to WiFi and Blynk: Ensure the ESP32 successfully connects to your WiFi network and Blynk dashboard.
  • Test Event Triggers:
  • Intrusion Detection: Move an object within 20 cm of the ultrasonic sensor. Verify that the LEDs flash red and a webhook is sent to make.com, which should trigger the Intrusion Event scenario.
  • Vibration Detection: Tap near the vibration sensor hard enough to exceed the threshold (25). Confirm that the vibration alert is logged, and a webhook is sent to make.com, which should trigger the Knock Event scenario.
  • Check Notifications: Ensure that the notifications set up in Blynk and make.com are received as expected (e.g., Telegram notifications).
  • Review Google Spreadsheet: Open the Google Spreadsheet connected to make.com and verify that the data from the webhooks is logged correctly.

Here is the link for our Google Spreadsheet

Summry

In this project, you created a Smart Home Security System using an ESP32 microcontroller, Blynk, make.com, and various sensors. This system is capable of detecting intrusions and vibrations, providing real-time notifications, and logging data for further analysis. The step-by-step guide covered setting up hardware, writing and uploading code, configuring Blynk for data visualization, and integrating with make.com for handling webhooks and notifications. Testing the system ensured everything worked as expected, resulting in a comprehensive security solution for your home.

By following this tutorial, you have built a functional and scalable security system, gaining hands-on experience with IoT technologies and enhancing your skills in integrating hardware and software platforms.