Want to protect your home with a DIY solution? Create your own smart motion detector that works as effectively as commercial systems. Perfect for beginners in IoT and home automation!
What You'll Create:
- A reliable motion detection system that sends instant alerts
- Your own IoT device that works with smart home platforms
- A professional-grade security sensor you built yourself
- Automated email notifications when motion is detected
Prerequisites :
- Active AskSensors account: Create AskSensors account.
- Create a new sensor. Follow the simple process described here.
Required Hardware:
- ESP32 board
- PIR motion sensor
- Jumper wires
- 1kΩ resistor
- Breadboard
- Micro USB cable
Quick Assembly:
- Connect PIR VCC → ESP32 5V
- Connect PIR GND → ESP32 GND
- Connect PIR DATA → ESP32 GPIO2 (with 1kΩ resistor)
Note: The ESP32 GPIOs require 3V3 signals (not 5V tolerent). For quick hack, you can only add a serial resistor of 1K between the PIR DATA pin and the ESP32 GPIO pin to protect the ESP32 GPIO from damage. However, for production, a 5V/3V3 level shifter is needed to guarantee long term circuit reliability. You can check this page to get a 5V/3V3 level shifter module.
Setup Instructions:
1. Prepare Your Environment
- Install the latest version of the Arduino IDE software (1.8.7 or higher).
- In your Arduino IDE, go to File> Preferences.
- Go to the “Additional Board Manager URLs” field, Enter the following URL: https://dl.espressif.com/dl/package_esp32_index.json
- If you already have the ESP8266 boards URL, separate the URLs with a comma as shown below:
- Now, open boards manager (Tools > Board > Boards Manager), search for ESP32 and click the install button for the “ESP32 by Espressif Systems”.
2. Code
- Install the MQTT PubSubClient Library for the Arduino IDE if you haven’t already.
- Download this demo from the AskSensors Github page.
- The provided code simply reads the status of the PIR sensor and send this information to AskSensors over MQTT. You need to modify the following variables:
- Your network credentials, so that ESP8266 can establish a connection with existing network
- The Api Key In and username to set the MQTT Topic:username/apiKeyIn
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";
const char* username = "YOUR_USERNAME";
const char* pubTopic = "publish/username/apiKeyIn";
3. Upload and Test
- Connect ESP32 via USB
- Check your Sensor data stream on AskSensors.
- You can cross-check the AskSensors graph readings with the values being printed on your ESP32 Serial Terminal.
- You can customize a Binary graph to plot your data as showing by next pictures.
4. Configure Email Alerts
- Log into your AskSensors Iot platform & select your sensor
- Click the 'Add Alert' button
- Select 'Email Alert' as the notification type
- Set your desired threshold values:
- Choose 'Max Value' = 1 to detect motion
- Enter your email address
- Save the configuration
Now you'll receive instant email notifications whenever motion is detected!
Perfect For:
- Home security
- Smart lighting automation
- Pet monitoring
- Visitor counting
- Energy saving
- Remote property monitoring
This project takes only 30 minutes to complete and can be a great addition to your smart home security system. With email alerts, you'll never miss any unauthorized movement again!
Top comments (0)