ESP32 - Motion Sensor Email Notification
In this tutorial, we will learn how to use an ESP32 and a motion sensor to send email notifications when someone illegally enters your room. This comprehensive guide covers the setup process, required components, and step-by-step instructions for integrating an ESP32 with a motion sensor and an email service. Enhance your home security and stay informed with real-time alerts sent directly to your inbox using the ESP32.

Hardware Used In This Tutorial
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Introduction to Motion Sensor and Gmail
We have specific tutorials about Motion Sensor and Gmail. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to ESP32, ESP32 code... Learn more about them at the following links:
- ESP32 - Motion Sensor tutorial
- ESP32 - Gmail tutorial
Wiring Diagram between Motion Sensor and ESP32
- How to connect ESP32 and motion sensor using breadboard (powered via USB cable)

This image is created using Fritzing. Click to enlarge image
- How to connect ESP32 and motion sensor using breadboard (powered via Vin pin)

This image is created using Fritzing. Click to enlarge image
- How to connect ESP32 and motion sensor using screw terminal block breakout board (powered via USB cable)

- How to connect ESP32 and motion sensor using screw terminal block breakout board (powered via Vin pin)

If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: The best way to Power ESP32 and sensors/displays.
ESP32 Code
Quick Instructions
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
- Connect the ESP32 board to the motion sensor
- Connect the ESP32 board to your PC via a micro USB cable
- Open Arduino IDE on your PC.
- Select the right ESP32 board (e.g. ESP32 Dev Module) and COM port.
- Open the Library Manager by clicking on the Library Manager icon on the left navigation bar of Arduino IDE.
- Search ESP Mail Client, then find the ESP Mail Client created by Mobizt.
- Click Install button to install ESP Mail Client library.

- Copy the above code and open with Arduino IDE
- Update the WiFi information (SSID and password) in the code by modifying the constants WIFI_SSID and WIFI_PASSWORD to match your own network credentials.
- Update the sender email and password in the code by modifying the constants SENDER_EMAIL and SENDER_PASSWORD to your own email account details.
- Update the recipient email in the code by modifying the constant RECIPIENT_EMAIL to your own email address. The recipient email can be the same as the sender email.
※ NOTE THAT:
- Sender email MUST be Gmail
- Sender password is the App passwords you got from previous step
- Recipient email can be any type of email
- Click Upload button on Arduino IDE to upload code to ESP32
- Open the Serial Monitor
- Make a movement in front of the motion sensor
- Check out the result on Serial Monitor.
- Check your recipient email box. You will get an email as below:

Video Tutorial
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.