How to make a DIY motion protection system with Nodemcu ESP8266 board | WhatsApp alerts

How to make a DIY motion protection system with Nodemcu ESP8266 board | WhatsApp alerts

Hello and welcome back. In this project, we will learn how to make a DIY motion protection system with the Nodemcu ESP8266 board. This DIY project is perfect for those looking to enhance home security or monitor sensitive areas. For that, I have mainly used the PIR motion sensor and Nodemcu board, which allows for easy integration with Wi-Fi networks. Additionally, I have included a buzzer and LED indicator to provide real-time alerts for detected motion. Also, we can get security alerts to our Whatsapp account. This feature is particularly useful for keeping an eye on your home or office while you’re away.

Also, I have used the PCB(Printed Circuit Board) for this project. Therefore we can assemble it easily and don’t need wires. 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.

If you want to do this project with an ESP32 board, please use this link.

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, let’s order PCBs for this project. You can do it with a few steps. For that, follow the instructions below.

  • First, go to the JLCPCB official website and log in to your account. If you are a new member of this, please use this link. Then, you can get a 60$ coupon for orders to PCBs.
  • JLCPCB $2 for 1-8 layer PCBs — Click on me
  • Now, click the instant quote button and upload the Gerber file. You can download it using the link below.
  • Gerber file — Download
  • I have ordered 5 PCBs with Red color. Also, you can remove the order number on PCBs.
  • Then, select the build time and shipping. Finally, click the save to cart button.
  • Next, open the cart and click the secure checkout button.
  • In this step, you can enter your shipping details and shipping method. Then, submit your order.
  • Finally, pay for this order using Paypal, Debit Card, Credit Card, or Coupon. Then, it will be received soon.

Step 3

Thirdly, unbox your JLCPCB box and check your PCBs.

Step 4

Next, solder the LED, Buzzer, resistor, two-pin terminal, and Female headers on the PCB.

Step 5

Now, connect the Nodemcu board and PIR sensor to the PCB.

Step 6

Next, connect the Nodemcu board to the computer. Then, follow the instructions below.

  • First, copy and paste the following program to the Arduino IDE.
  • Program and Gerber file — Download
  • ESP8266 WIFI library — Download
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <UrlEncode.h>

#define Sensor D0
#define LED D1
#define Buzzer D2

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

String phoneNumber = "**********"; //country_code + phone number
String apiKey = "**********";

void setup() {
  Serial.begin(115200);
  pinMode(Buzzer, OUTPUT);
  pinMode(LED, 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);
    digitalWrite(LED, HIGH);
    sendAlert("Warning!");
    delay(1500);
  } else {
    digitalWrite(Buzzer, LOW);
    digitalWrite(LED, LOW);
  }
}


void sendAlert(String message) {

  // Data to send with HTTP POST
  String url = "http://api.callmebot.com/whatsapp.php?phone=" + phoneNumber + "&text=" + urlEncode(message) + "&apikey=" + apiKey;
  WiFiClient client;
  HTTPClient http;
  http.begin(client, 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(); // Data to send with HTTP POST
}
  • Then, download and install the ESP8266 WIFI library file. After that, install the UrlEncode library. For that, go to the library manager and download it.
  • Next, enter your WIFI SSID and password.

Step 7

Now let’s set up the WhatsApp bot. For that, follow the instructions below.

  • First, save this number on your phone as you like. I have named it as “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 8

Ok, let’s go back to the program. Now, enter your WhatsApp phone number and Api key.

Step 9

Now, select the board and port. After, click the upload button.

Step 10

After that, remove the USB cable and connect the 5VDC external power supply to this circuit. But, you can also power it using a USB cable.

Now, you can check this system with motions. The full video guide is below. So, we will meet in the next project. have a good day.

Troubleshooting tips

  • Check component status.
  • Include ESP8266 and UrlEncode library files.
  • Check the phone number and API key.
  • Check the WIFI SSID and password.
  • Select the correct board and port.

How to make a DIY motion protection system with Nodemcu ESP8266 board | WhatsApp alerts

Similar Posts

Leave a Reply

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