DEV Community

Cover image for ESP32 Email Alerts Made Simple (IoT Notification System with Ultrasonic Sensor)
David Thomas
David Thomas

Posted on

ESP32 Email Alerts Made Simple (IoT Notification System with Ultrasonic Sensor)

Ever built something cool and then realized… you still have to keep checking it manually?

Yeah, that gets annoying fast.

So instead of constantly watching your system, why not make it notify you automatically? That’s exactly what this Send Email Notifications using ESP32 project does using an ESP32 and a simple ultrasonic sensor.

What You’re Building

This is a smart alert system.

The ESP32 continuously measures distance using an ultrasonic sensor. When something comes too close, it instantly sends an email notification to your inbox.

No GSM. No complicated email servers. Just WiFi and a clean API-based approach.

Why This Approach Is Better

A lot of people try sending emails directly from microcontrollers.

That usually turns into a headache.

Here, the ESP32 doesn’t deal with email protocols at all. It just sends a small JSON request to a cloud API, and the platform handles formatting and delivery.
Less complexity, more reliability.

Hardware Setup (Super Simple)

Circuit-Diagram-of-ESP32-Setup

This is one of those builds where you don’t need much.

Just an ESP32 and an ultrasonic sensor.

The trigger pin sends a pulse, the echo pin reads the return signal, and that’s how distance is calculated. A couple of jumper wires and you’re good to go.

How the System Works

Email-Alert-Notification-From-the-ESP32

The logic is clean and easy to follow.

The sensor keeps checking distance in a loop. As long as everything is normal, nothing happens.

But the moment an object crosses the threshold, the ESP32 sends data to the cloud API, which then delivers an email alert.

Simple flow, real-world impact.

What’s Happening in the Code

There are three main parts in the code.

First, the ESP32 connects to WiFi. Then it reads distance using pulse timing. Finally, when the condition is met, it creates a JSON payload and sends it securely using HTTPS.

That payload includes your email, template ID, and sensor value.

Everything else is handled on the cloud side.

One Smart Feature You Shouldn’t Skip

There’s a small but important trick in this project.

A cooldown mechanism.

Without it, the ESP32 would keep sending emails again and again while the object stays close. So the code ensures only one alert is sent per event.

Once the object moves away, the system resets.

Where You Can Actually Use This

Real-time-Setup-of-the-ESP32-with-Ultrasonic-Sensor

This isn’t just a learning project.

You can turn it into something useful pretty quickly.

Think intrusion alerts, parking sensors, safety monitoring, or even simple automation triggers. Anywhere you need instant updates without checking manually, this fits in.

Common Issues (Quick Reality Check)

If emails aren’t coming through, don’t panic.

It’s usually an API key issue or an unverified email. Sometimes the message lands in spam, so check there too.

If the sensor isn’t working, it’s almost always wiring. Loose connections love to ruin otherwise perfect builds.

Why This Project Is Worth Trying

This is more than just sending an email.

You’re actually learning how real IoT systems work. Devices collect data, send it to the cloud, and trigger actions based on conditions.

Once you understand this flow, you can build way more advanced systems.

Swap the ultrasonic sensor with anything else, and you’ve got a completely new project.

Send Email Notifications using ESP32

Top comments (0)