How to send WhatsApp messages from ESP32?

Published  February 23, 2026   0
B Bharani Dharan R
Author
ESP32 Temperature Monitoring with WhatsApp Alert System

This ESP32 WhatsApp notification project shows how to send real-time WhatsApp alerts directly from an ESP32 using WiFi and the CircuitDigest Cloud WhatsApp API. The ESP32 reads sensor data, checks for a defined condition such as high temperature or motion detection, and immediately pushes a WhatsApp alert to your phone. And the best part is you do not need a WhatsApp API subscription or GSM module or SIM card to do this. 

The idea behind this tutorial is to help engineers and makers to quickly and easily send WhatsApp messages from  ESP32. For the sake of demonstration, we have connected a DHT11 sensor to the ESP32 to read and send the temperature and humidity values as a WhatsApp alert message. But you can use it for any project as you see fit. The tutorial uses the WhatsApp API service that we have built here using CircuitDigest.cloud. If you are looking for more alert notifications from ESP32, check out Email notification from ESP32 and send text message from ESP32 tutorial, all of which are built and serviced by CircuitDigest Cloud. For more tutorials using ESP32, explore our collection of ESP32 projects.

How does the ESP32 WhatsApp Alert Message work?

The ESP32 uses its built-in WiFi to communicate with CircuitDigest Cloud WhatsApp API and send WhatsApp notifications whenever a sensor condition is triggered. The device doesn't connect directly to WhatsApp servers. Instead, it sends a secure API request to the CircuitDigest cloud platform, which verifies your account, formats the message using a pre-approved template, and delivers it to pre-registered recipient numbers. Also note that you can send WhatsApp message alerts to a maximum of 5 numbers and a total of 100 messages per month. This process keeps the ESP32 WhatsApp alert system simple, secure, and more importantly, free for everyone to use. To put it short

  • ESP32 connects to WiFi and sends an HTTPS POST request with phone number, template ID, and alert variables
  • CircuitDigest Cloud validates the API key and allows delivery only to verified and approved recipient numbers
  • The platform formats the template and delivers the final alert instantly to WhatsApp
  • You can send a WhatsApp message to a maximum of 5 numbers and a total of 100 messages per month per user. 

Components Used to Send WhatsApp Alert

This project uses a small set of basic hardware components to keep the setup simple and easy to replicate. The ESP32 handles WiFi communication and API requests, while the DHT11 sensor provides temperature data that triggers the WhatsApp alert. If you want to learn more about using the DHT11 sensor with ESP32, check out our tutorial on ESP32 webserver for temperature and humidity measurement using DHT11 sensor.

Components Used to Send WhatsApp Notification

Circuit Diagram to connect DHT11 with ESP32

Refer to the circuit diagram below for the complete wiring layout. This minimal wiring reduces hardware complexity making it easy to demo the ESP32 WhatsApp alert system. 

Whatsapp API ESP32 Circuit Diagram

The table below shows the connection of the DHT11 to the ESP32 Development Board

DHT11ESP32
VCC5V
GNDGND
DATAGPIO 23

Once the connections are done, your hardware should look like something as shown in the image below. Again, you can connect any sensor of your choice to read its value and send your whatsapp message, we are using DHT11 only for the sake of this demo. 

Hardware Setup ESP32 Temperature Monitoring with WhatsApp Alert System

Generating API Key on CircuitDigest Cloud

Step 1: Open CircuitDigest Cloud in your browser and click the Login button. Enter your credentials to sign in. If you do not have an account, create one using the Register option.

CircuitDigest Cloud Login Page

Step 2: After logging in, click the Account button at the top right corner. Select API Key from the dropdown menu. The system opens the API key management page.

API Keys option in the profile page

Step 3: Generate a new API key. The platform assigns a free usage limit and allows renewal after expiry. Copy this key because you will paste it into your ESP32 code.

API Keys and Monthly Usage Limits

Step 4: Scroll down to the WhatsApp Notification API section and click View Details. This section contains all controls related to WhatsApp alert delivery.

WhatsApp Notification API option

Step 5: Open the Link Phone Number option. Add the phone numbers that should receive alerts from your device. You can register upto 4 verified phone numbers. 

Link Phone Number Page

Step 6: Enter the selected number and request verification. The system sends a one-time code to confirm ownership. After verification, the number appears in your approved list and becomes ready to receive WhatsApp alert from your ESP32.

Linked Phone Numbers List

WhatsApp Templates of CircuitDigest Cloud

CircuitDigest Cloud provides a set of pre-approved WhatsApp alert templates that you can use directly with your ESP32 WhatsApp notification system. These templates follow WhatsApp's messaging guidelines and ensure reliable delivery without manual alert formatting. Instead of writing full text inside the firmware, you simply select a template ID and pass variable values such as device name, temperature, or location. The platform automatically inserts these values into the final alert before sending it to the recipient. 

Each template targets a specific alert use case like temperature warnings, system errors, motion detection, or maintenance reminders. Choose the template that best matches your application and include its ID in your API request.

Template IDTemplate TypeMessage
system_error_diagnosticsSystem Error NotificationA diagnostic issue has been reported by {#var#}. Error type: {#var#}. Error detail: {#var#}. Location: {#var#}. Please inspect the system.
critical_event_alertCritical Event AlertHigh priority alert from {#var#}. Event type: {#var#}. Recorded value: {#var#}. Location: {#var#}. Immediate attention required.
threshold_violation_alertThreshold Violation AlertA monitored parameter exceeded limits on {#var#}. Parameter: {#var#}. Measured value: {#var#}. Configured limit: {#var#}. Location: {#var#}.
operational_status_updateOperational Status UpdateStatus update from {#var#}. Current status: {#var#}. Detail: {#var#}. Location: {#var#}. No action required unless unexpected.
command_execution_confirmationCommand Execution Confirmation{#var#} processed a command. Command: {#var#}. Result: {#var#}. Location: {#var#}.
location_movement_updateLocation / Movement UpdateUpdate from {#var#}. Movement status: {#var#}. Current location: {#var#}. Recorded at: {#var#}.
service_reminder_notificationScheduled Service ReminderService reminder for {#var#}. Service type: {#var#}. Usage detail: {#var#}. Recommended service date: {#var#}.
responsible_contact_informationContact InformationFor alerts from {#var#}, contact {#var#}. Phone: {#var#}. Department or location: {#var#}.

Each WhatsApp template uses placeholders written as {#var#}. These placeholders act as dynamic fields that your firmware fills at runtime. You do not modify the alert text itself. Instead, you send values inside the variables object of the JSON payload. The system maps each value to the template placeholders in order and automatically generates a clean, readable WhatsApp alert. For example, if you send a temperature alert using threshold_violation_alert, you pass values such as device name, parameter, measured value, limit, and location. CircuitDigest Cloud inserts these values into the predefined template and delivers the formatted alert instantly to the user.

Templates Payload Structure 

Every WhatsApp alert sent from your ESP32 follows the same HTTPS request format. You do not need separate functions for each template. You only change two things: the template_id and the values inside the variables object. Everything else remains identical. This approach keeps the firmware simple, reduces bugs, and makes the code reusable across different sensors and projects.

Think of the payload as a container. The structure stays fixed, while the data changes dynamically based on your sensor readings. For example, one project may send temperature values, while another sends motion status or battery level. The CircuitDigest Cloud platform reads your JSON, inserts the variable values into the selected template, and delivers the final WhatsApp alert automatically. 

Standard JSON Format

Use this structure for all templates. Do not modify the field names.

String payload =
"{"
"\"phone_number\":\"YOUR_NUMBER\","
"\"template_id\":\"YOUR_TEMPLATE_ID\","
"\"variables\":{"
"\"device_name\":\"YOUR_DEVICE\","
"\"var1\":\"VALUE1\","
"\"var2\":\"VALUE2\","
"\"var3\":\"VALUE3\","
"\"var4\":\"VALUE4\""
"}}";

Field Explanation

  • phone_number - recipient WhatsApp number with country code
  • template_id - selects which alert format to use
  • variables - dynamic values inserted into the template
  • device_name / var1 / var2 / var3 / var4 - any sensor data or text you want to send

You can rename variables based on the template requirements, such as parameter, measured_value, or location. The platform maps them automatically.

Example Payloads (Reference Only)

These examples demonstrate format only. Replace all values with your real sensor data.

Temperature Alert from DHT11

"template_id":"threshold_violation_alert"

Used when the temperature crosses a limit.

Motion Detection from PIR

"template_id":"critical_event_alert"

Used for intrusion or emergency alerts.

Device Online or Offline Status

"template_id":"operational_status_update"

Used to notify system status changes.

Maintenance or Service Reminder

"template_id":"service_reminder_notification"

Used for scheduled service alerts.

Before You Build the Payload

Treat the examples only as a guide to understand the format. Do not copy the values as they are. Replace them with your own sensor readings or device data. You can send temperature, distance, motion status, voltage, battery level, or any other value that your project generates. The ESP32 sends notification to the smartphone, simply places whatever you send into the selected template.

Keep things simple while building the payload. Select the correct template_id and keep the JSON format valid. Once these two are correct, the alert will be delivered without issues. Everything else, including variable names and values, remains completely under your control.

Firmware Working and Code Explanation

The sketch starts by loading the required libraries. These libraries handle WiFi communication, secure HTTPS requests, and sensor data reading.

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <DHT.h>

WiFi.h manages internet connectivity, WiFiClientSecure.h enables HTTPS communication with the cloud server, and DHT.h simplifies communication with the DHT11 sensor so you can read temperature using simple function calls.

Next, the code defines the GPIO pin and sensor type. Using macros makes the program easier to modify later and avoids hardcoding values throughout the sketch.

#define DHTPIN 23
#define DHTTYPE DHT11

The cooldown value is defined to prevent alert flooding. Without this delay, the ESP32 would send alerts continuously when the temperature stays high.

#define COOLDOWN_MS 15000

WiFi credentials and API details come next. These values allow the board to connect to the internet and authenticate requests with the WhatsApp API.

const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASS";
const char* apiKey = "YOUR_API_KEY";

The DHT sensor object is then created. This object provides built-in functions to read temperature easily.

DHT dht(DHTPIN, DHTTYPE);

A secure client object is initialized to send HTTPS requests. All communication with the cloud server uses this client.

WiFiClientSecure client;

A timer variable stores the last alert time. The program uses this value to calculate the cooldown interval.

unsigned long lastSent = 0;

The setup() function runs only once when the board powers on. It starts serial communication for debugging, initializes the sensor, and connects the ESP32 to WiFi. The program waits until the connection succeeds before moving forward, which ensures that alerts never fail due to a missing internet connection.

Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED);

Inside the main loop, the ESP32 reads the current temperature repeatedly. This continuous reading allows the device to respond immediately when the threshold is crossed.

float temperature = dht.readTemperature();

The program then checks whether the temperature exceeds the defined limit. If the condition becomes true and the cooldown period has passed, the device prepares to send an alert.

if (temperature >= 30 && millis() - lastSent > COOLDOWN_MS)

When triggered, the firmware calls the WhatsApp sending function. This function handles the entire API communication process.

sendWhatsApp(temperature);

Inside that function, the ESP32 first connects securely to the CircuitDigest Cloud server.

client.connect("www.circuitdigest.cloud", 443);

Next, the code builds the JSON payload. This payload includes the phone number, template ID, and dynamic sensor values that will appear in the WhatsApp alert.

String payload =
 "{"
 "\"phone_number\":\"919876543210\","  //Enter registered Mobile number
 "\"template_id\":\"threshold_violation_alert\","
 "\"variables\":{"
   "\"device_name\":\"Living Room Temp Node\","
   "\"parameter\":\"Temperature\","
   "\"measured_value\":\"" + tempString + "\","
   "\"limit\":\"30°C\","
   "\"location\":\"Living Room\""
 "}"
 "}";

The program then sends the HTTP headers followed by the JSON body. These lines form the actual API request.

client.println("POST /api/v1/whatsapp/send HTTP/1.1");
client.println("Authorization: " + String(apiKey));
client.println(payload);

After sending the request, the client waits for the server's response and closes the connection. This step confirms whether the alert was delivered successfully.

Finally, the firmware stores the current time to restart the cooldown timer. This prevents multiple alerts for the same event.

lastSent = millis();

The entire workflow stays simple and reliable. The ESP32 reads the sensor, checks the condition, sends a alert only when necessary, and repeats the cycle. This clean structure keeps the project easy to understand, easy to maintain, and suitable for any other sensor or alert type.

Uploading the Code

Install the required tools and upload the firmware to the ESP32 before testing the alert system. These steps prepare the board, flash the program, and verify that everything works correctly.

  • Install required libraries and board support: Open Arduino IDE and install the ESP32 board package from Boards Manager. Then install the DHT sensor library from Library Manager so the sketch can read temperature data.
  • Configure the project: Connect the ESP32 using a USB cable, open the sketch, and update your WiFi name, password, API key, and recipient phone number inside the code.
  • Select the board and upload: Choose your ESP32 model from Tools --> Board, select the correct Port, and click Upload to compile and flash the firmware into the board.
  • Verify operation: Open Serial Monitor (115200 baud) to confirm WiFi connection. Trigger the sensor threshold and check that the WhatsApp alert is delivered automatically.

Implementation Results

After uploading the firmware and powering the ESP32, the ESP32 WhatsApp alert system starts connecting to WiFi and begins reading temperature values from the DHT11 sensor continuously. You can monitor the live readings and connection status in the Serial Monitor. When the temperature crosses the defined threshold, the ESP32 immediately prepares the payload and sends a secure request to CircuitDigest Cloud, which then delivers the WhatsApp alert to the registered phone number.

ESP32 WhatsApp API Demo working demonstration

WhatsApp Alert Screenshot

In the demonstration shown above, you can see the temperature increasing near the sensor and the alert triggering as soon as the limit is reached. The ESP32 sends a WhatsApp alert that appears instantly with the device name, measured value, and location details. After sending one alert, the system waits for the cooldown period and then continues monitoring without spamming alerts. This notification system can be adapted for various applications. Explore more creative ideas in our electronics projects collection.

Need more features for your IoT projects? CircuitDigest Cloud has you covered. Automate emails with the Email Notification API, send SMS messages using the SMS Notification API, identify vehicle plates through the Vehicle Number Plate Reader, and display location data with the GeoLinker-GPS Visualizer API. Compatible with ESP32, Arduino, Raspberry Pi, and more, everything you need in one platform.

Github Repository

If you want the project files, wiring diagrams, sample videos or ready-made examples, find it stored cleanly in this GitHub repository.

ESP32 WhatsApp API Using CircuitDigest Cloud Github Repository LinkESP32 WhatsApp API Using CircuitDigest Cloud Zip File Download Link

Related Temperature Sensor Projects

Hands-on IoT projects demonstrating DHT11 temperature and humidity sensing with Arduino and ESP32, including basic interfacing and building web servers to monitor sensor data and control LEDs remotely.

 Interfacing DHT11 Humidity & Temperature Sensor with Arduino

Interfacing DHT11 Humidity & Temperature Sensor with Arduino

Learn how to interface the DHT11 temperature and humidity sensor with Arduino. Covers pinout, working principle, circuit diagram, 1-wire protocol, and example code.

 ESP32 Based Webserver for Temperature and Humidity Measurement using DHT11 Sensor

ESP32 Based Webserver for Temperature and Humidity Measurement using DHT11 Sensor

Build an ESP32-based webserver to monitor temperature and humidity using the DHT11 sensor. View live readings on a webpage and send email alerts via IFTTT.

 Building a Simple ESP32 LED Webserver: Step-by-Step Tutorial

Building a Simple ESP32 LED Webserver: Step-by-Step Tutorial

Learn how to build a simple ESP32 LED webserver to control LEDs over WiFi. This step-by-step tutorial covers circuit connections, code, and web-based ON/OFF control.

Complete Project Code

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <DHT.h>
#define DHTPIN 32
#define DHTTYPE DHT11
#define TEMP_LIMIT 30
#define COOLDOWN_MS 15000
const char* ssid     = "YOUR_WiFi_SSID";
const char* password = "YOUR_WiFi_PASSWORD";
const char* apiKey   = "YOUR_API_KEY";
const char* host = "www.circuitdigest.cloud";
const int httpsPort = 443;
DHT dht(DHTPIN, DHTTYPE);
WiFiClientSecure client;
unsigned long lastSentTime = 0;
void sendWhatsApp(float temperature)
{
if (!client.connect(host, httpsPort)) {
  Serial.println("HTTPS connection failed");
  return;
}
String tempString = String(temperature) + "°C";
String payload =
"{"
"\"phone_number\":\"919876543210\","  //Enter registered Mobile number
"\"template_id\":\"threshold_violation_alert\","
"\"variables\":{"
  "\"device_name\":\"Living Room Temp Node\","
  "\"parameter\":\"Temperature\","
  "\"measured_value\":\"" + tempString + "\","
  "\"limit\":\"30°C\","
  "\"location\":\"Living Room\""
"}"
"}";
client.println("POST /api/v1/whatsapp/send HTTP/1.1");
client.println("Host: www.circuitdigest.cloud");
client.println("Authorization: " + String(apiKey));
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(payload.length());
client.println();
client.println(payload);
while (client.connected()) {
  String line = client.readStringUntil('\n');
  if (line == "\r") break;
}
Serial.println(client.readString());
client.stop();
}
void setup()
{
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
Serial.print("Connecting WiFi");
while (WiFi.status() != WL_CONNECTED) {
  delay(300);
  Serial.print(".");
}
Serial.println("\nWiFi Connected");
client.setInsecure();   // for testing only
}
void loop()
{
float temperature = dht.readTemperature();
unsigned long now = millis();
Serial.print("Temperature: ");
Serial.println(temperature);
if (!isnan(temperature) &&
    temperature >= TEMP_LIMIT &&
    now - lastSentTime > COOLDOWN_MS)
{
  Serial.println("Threshold reached → Sending WhatsApp");
  sendWhatsApp(temperature);
  lastSentTime = now;
}
delay(2000);
}
Have any question related to this Article?

Add New Comment

Login to Comment Sign in with Google Log in with Facebook Sign in with GitHub