ESP32 & IFTTT e-mail door IoT sensor

This post will walk you through how I (with some help from others) made and IoT sensor that sends me an e-mail whenever someone opens my door. I did this, mainly to learn about Arduino and chips such as the ESP32. They are great tools to create IoT projects with minimal costs.

Things you will need:

You will also need some software before you start:

Once you are done with getting all the necessary materials, you are ready to start with your project. You will want to start by checking if your ESP32 board works properly by doing this LED Blink test. The guide on the LED Blink test will also help you set up the connection between the IDE and your board, and you will experience first-hand how to upload your code. NOTE: My ESP32 required me to hold the BOOT button while uploading, just a heads up if you come across a similar problem.

Software

The Code

I took most of the code for the sensor, and battery efficiency from this repository. However, I added some editted some stuff since the code above is supposed to send you an SMS message, and works with a different type of battery. So in the new code, there's the webhooks set up with IFTTT for emails, and another small edit for the power. Use the wifi setup from there too. See my edit here.

IFTTT and Webhooks

Once you have created an IFTTT account it's time to set up your applet. This will pretty much allow you to get the email when your door is openned. In short, this will tell you got to get the 'ifttturl' URL that you need to fill in the code above. Go on IFTTT, and under 'My applets' select "New applet". The for "+this" search and select Webhooks, and enter your event name. It should be something like door_open. Remember, this is the event name that you will use in your 'ifttturl' later on. When you create the trigger, chose "Email" for the '+that' field. Then, configure your email subject, body etc. Once you press finish, your applet is done. Time to get your URL now. Click the dropdown menu on your top right corner (with your username on it) and select "Services". Or, just go here. Choose webhooks. Then, click on "Documentation". Once you are there, you should see your unique URL key and URL. Insert the event name that you previously entered, and you have you'ifttturl' value. You can test it by using curl -X POST in your command line.

Hardware

Once you are done with the code, the hardware set up should be easy.If you are using a Power Bank, to power your ESP32, just plug the USB in. Next, you will want to connect the reed switch wires to the ESP32. Connect one wire to ground (GDN) and the other to GPIO 12. NOTE: This is only if you are using the code currently provided. If you change the GPIO in the code, connect your reed switch to the respective GPIO. Once that's done, you are ready to go! Glue your reed switch to the door, set up your ESP32 nearby, and that's it!

The sensor in action