How to make a security system with the ESP32 board | ESP32 with WhatsApp

 How to make a security system with the ESP32 board | ESP32 with WhatsApp

Hello and welcome back. In this project, we will learn How to make a security system with the ESP32 board. For that, I mainly used the PIR motion sensor, which will help us detect any movement within its range. Using this project, you can receive security alerts on your WhatsApp account. This means you’ll be instantly notified if any unusual activity is detected, adding an extra layer of protection to your home or workspace. That’s a good feature of this project. Additionally, we’ve included a 5V buzzer to provide a simple beep alarm. That’s a very simple project. You can try it easily.

For this project, I have used the free API service it’s called CallMeBot. If you want to get more info about this API, please use this CallMeBot website.

OK, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the ESP32 board to the adapter. If you don’t have an adapter, please use two breadboards together.

Step 3

Thirdly, place the buzzer on the breadboard. And then, connect it to the ESP32 board. For that, use the circuit diagram below.

 How to make a security system with the ESP32 board | ESP32 with WhatsApp

Step 4

Now, connect the PIR sensor to the ESP32 board.

Step 5

Next, connect the ESP32 board to the computer. And then, copy and paste the following program into the Arduino IDE.

 How to make a security system with the ESP32 board | ESP32 with WhatsApp
#include <WiFi.h>
#include <HTTPClient.h>
#include <UrlEncode.h>

#define Buzzer 2
#define Sensor 4

const char* ssid = "SSID";//Enter your SSID
const char* password = "PASSWORD";//Enter your password

String phoneNumber = "PHONE_NUMBER"; //country_code + phone number
String apiKey = "API_KEY";

void setup() {
  Serial.begin(115200);
  pinMode(Buzzer, OUTPUT);
  pinMode(Sensor, INPUT);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  // Send Message to WhatsAPP
  sendAlert("Your system is ready!");
}

void loop() {
  bool sensorValue = digitalRead(Sensor);
  if (sensorValue == 1) {
    digitalWrite(Buzzer, HIGH);
    sendAlert("Warning!");
  } else {
    digitalWrite(Buzzer, LOW);
  }
}


void sendAlert(String message) {

  // Data to send with HTTP POST
  String url = "https://api.callmebot.com/whatsapp.php?phone=" + phoneNumber + "&apikey=" + apiKey + "&text=" + urlEncode(message);
  HTTPClient http;
  http.begin(url);

  // Specify content-type header
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");

  // Send HTTP POST request
  int httpResponseCode = http.POST(url);
  if (httpResponseCode == 200) {
    Serial.print("Message sent successfully");
  }
  else {
    Serial.println("Error sending the message");
    Serial.print("HTTP response code: ");
    Serial.println(httpResponseCode);
  }

  // Free resources
  http.end();
}
  • Next, install the UrlEncode library file. For that, go to the library manager and type the “UrlEncode” on the search bar. Now, you can install it.

Step 6

OK, now let’s set up the CallMeBot API. For that, follow the instructions below.

  • First, save this number on your phone as you like. I have named it “WhatsApp Bot”.
  • +34 644 51 95 23
  • Then, open your WhatsApp account and send the following message to this number.
  • I allow callmebot to send me messages
  • Now, you can get a reply message. It includes the API key.

Step 7

Then, enter your WIFI SSID, Password, WhatsApp number(Your number with country code), and API key.

  • Now, select the board and port. finally, click the upload button.

Step 8

Finally, you can power this project using an external 5v power supply or USB power supply. Now, you can get security alerts to your WhatsApp account when movements are detected. The full video guide is below. We hope to see you in the next project or tutorial.

 How to make a security system with the ESP32 board | ESP32 with Whatsapp

Similar Posts

Leave a Reply

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