Imagine getting an email every time someone enters your room. This project will actually help you understand how to use emails with your ESP32.
Today, we're building a smart motion detector using the ESP32 and an ultrasonic sensor, and yes, it sends you an email when movement is detected!
Here’s what you’ll need:- ESP32 Dev Board
- HC-SR04 Ultrasonic Sensor
- Wires
- Your Wi-Fi Credentials
- Gmail account with app password
We’ll wire the ultrasonic sensor to the ESP32 like this
Sensor Pin ESP32 Pin
VCC 5V
GND GND
TRIG D5
ECHO D18
SMTP - means simple mail transfer protocol, and it's an Internet standard for email transmissions.
For sending emails using an ESP32, you need to connect it to an SMTP server. First of all, we need to create an email account. I'm going to go with the Gmail account.
Next, we need to form an app password. It's actually a 16digit passcode that gives you a less secure app or device permission to access your Google account.
An app password can only be used with the accounts that have two-step verification turned on.
After completing the two step verification process you can go and search for the app password in the search panel, and from there, you just give a name to the app password, for example, ESP ESP or anything that you would like to, and it will pop up in a window with a password that you will use the ESP32 to send emails.
You need to save that password, even though the text shows that you won't need to remember it, but you have to save it because we will be using it in our code.
We'll be using the ESP mail client library. This library allows the ESP32 to send and receive emails with or without attachments via SMTP and IMAP servers. To install the ESP mail client library, go to the sketch include library, manage libraries, and search for the ESP mail client. Install the ESP mail client library by Mobizz
In the code, you need to add your email that you have just created for your ESP32 and also the Gmail app password, which you generated in the Google security settings.
If you would like to learn more about this code, you can check out my YouTube video (from 2:22 )
Now upload the code to your ESP32.
So what's next?
Watch how it works
Let's say I am in my hostel and I have some snacks in my drawer, and if I don't want anyone to open my drawer or see my snacks, I can just put our project right inside the drawer.
So every time someone opens this drawer, I'll get an email notification.
So use this device next time to save your snacks.
Comments