DEV Community

Cover image for Build a Motion-Triggered SMS Alert System with XIAO ESP32 S3 - No GSM Required
David Thomas
David Thomas

Posted on

Build a Motion-Triggered SMS Alert System with XIAO ESP32 S3 - No GSM Required

Imagine your basement door opens while you're away - within seconds, your phone buzzes with an SMS alert. That's exactly what this project Send SMS Alert using Seeed Studio XIAO ESP32 delivers, using the Seeed Studio XIAO ESP32 S3, an HC-SR04 ultrasonic sensor, and a free cloud SMS API from Circuit Digest Cloud.

What makes this approach simple is the absence of GSM hardware. Traditional SMS projects needed SIM cards and bulky GSM shields. Here, the ESP32's built-in Wi-Fi does all the heavy lifting - it sends an HTTP POST request to a cloud server, which handles SMS delivery to any mobile number worldwide.


How It Actually Works

Workflow-Diagram-of-Xiao-ESP32-SMS-Alert

The flow is straightforward but satisfying once you see it running live:

Power on → Connect Wi-Fi → Object detected <100 cm → HTTP POST to API → SMS delivered

The ultrasonic sensor fires a trigger pulse every 500ms and measures the echo return time. When something crosses the 100 cm threshold, the ESP32 hits the Circuit Digest Cloud API with a JSON payload — your phone number, a template ID, and two custom message variables. The cloud handles formatting and delivery.

Smart flag logic: an alertSent boolean prevents SMS spam. The system sends one alert per intrusion event and resets only after the object moves away. Simple, but critical for real deployments.


The Core of the Code

The distance function is clean and classic — a 10µs trigger pulse, a timed echo, and basic physics:

float readDistance() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  return duration * 0.034 / 2; // cm
}
Enter fullscreen mode Exit fullscreen mode

The SMS call wraps a WiFiClient connecting to the Circuit Digest endpoint on port 80, sending standard HTTP/1.1 headers with your API key as the Authorization value. The JSON payload is minimal — mobile number, and two string variables that slot into your pre-defined message template.


Why the XIAO ESP32 S3 Specifically?

Seeed-Studio-Xiao-ESP32-S3-Pinout

It's the size of a postage stamp with a full Xtensa LX7 dual-core processor, 8MB flash, and integrated Wi-Fi + Bluetooth. For a motion alert node you want to tuck inside a wall socket or behind a door frame, that form factor matters. It programs through Arduino IDE like any other ESP32, so there's no learning curve if you've built with ESP32 before.

The HC-SR04 only needs four connections: 5V, GND, and two GPIOs (pin 5 for trigger, pin 3 for echo). Total build time is under 15 minutes.


Real-World Use Cases

Use Case Description
Home security Entry points, windows, secure storage - instant alerts on intrusion detection.
Tank level monitoring Swap the trigger axis - alert when water level drops below a threshold.
Industrial safety zones Restricted area alerts - notify safety personnel when someone enters.
Agricultural protection Remote field monitoring - alerts when animals or intruders cross perimeters.

The sensor is also swappable. Replace the HC-SR04 with a DHT11 for temperature-triggered alerts, a PIR module for passive motion sensing, or a reed switch for magnetic door detection - the SMS infrastructure stays identical.

We have collection of IoT related project -> IoT Projects check these out for more project ideas.


Top comments (0)