Send real-time WhatsApp notifications from your Raspberry Pi Pico W using the CircuitDigest Cloud WhatsApp API. Monitor sensors, detect rain, and receive instant alerts directly to your smartphone without manual intervention.
- Introduction
- Components Required
- Circuit Diagram
- Hardware Setup
- CircuitDigest Cloud Setup
- Understanding Templates & Payload Structure
- Firmware Working & Code Explanation
- Uploading the Code
- Implementation Results
- License
- Contact
This project demonstrates how to build an automated rain detection system using Raspberry Pi Pico W that sends WhatsApp alerts when rain is detected. The system connects to WiFi, monitors a rain sensor continuously, and communicates with the CircuitDigest Cloud platform to deliver formatted WhatsApp messages to your phone.
Key Features:
- Real-time rain detection with instant WhatsApp notifications
- Secure HTTPS communication with CircuitDigest Cloud
- Customizable alert templates
- Cooldown mechanism to prevent message flooding
- Easy to adapt for other sensors (temperature, motion, etc.)
| Component | Description |
|---|---|
| Raspberry Pi Pico W | WiFi-enabled microcontroller |
| Rain Sensor Module | Digital rain/moisture detection sensor |
| Breadboard | For prototyping connections |
| Jumper Wires | Male-to-male and male-to-female |
| Micro USB Cable | For power and programming |
Connections:
- Rain Sensor VCC → Pico W 3.3V (Pin 36)
- Rain Sensor GND → Pico W GND (Pin 38)
- Rain Sensor D0 (Digital Output) → Pico W GP15 (Pin 20)
- Connect the rain sensor module to the Raspberry Pi Pico W as per the circuit diagram
- Ensure all ground connections are common
- Power the Pico W via Micro USB cable
- Verify the rain sensor LED indicator is functioning
The CircuitDigest Cloud platform provides a simple API for sending WhatsApp messages. Follow these steps to set up your account and get your API credentials.
Visit CircuitDigest Cloud and create a free account.
Navigate to the WhatsApp Notification API section from the dashboard.
Enter your WhatsApp-registered phone number (with country code) to receive alerts.
Verify that your number is successfully linked.
Copy your unique API key from the dashboard. This key authenticates all requests from your Raspberry Pi Pico W.
Review your API usage limits and available message quota.
Every WhatsApp message sent from your Raspberry Pi Pico W WhatsApp notification system 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 rain status, while another sends temperature values or motion detection. The CircuitDigest Cloud platform reads your JSON, inserts the variable values into the selected template, and delivers the final WhatsApp message automatically.
Use this structure for all templates. Do not modify the field names.
{
"phone_number": "+919876543210", //Replace with registered number
"template_id": "template_001",
"variables": {
"device_name": "Rain Sensor",
"var1": "Rain Detected",
"var2": "Active",
"var3": "Location XYZ"
}
}| Field | Description |
|---|---|
phone_number |
Recipient WhatsApp number with country code |
template_id |
Selects which message 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 event_type, status, or location. The platform maps them automatically.
The Pico W sends this JSON through an HTTPS POST request. CircuitDigest Cloud receives the request, validates your API key, reads the template_id, and loads the corresponding WhatsApp template. The system then replaces each {#var#} placeholder with the values you provided and sends the final formatted message to the user.
You do not build the message text manually. The template handles formatting. Your firmware only supplies data.
These examples demonstrate format only. Replace all values with your real sensor data.
Rain Detection Alert:
{
"phone_number": "+919876543210", //Replace with registered number
"template_id": "rain_alert",
"variables": {
"device_name": "Rain Sensor Module",
"event_type": "Rain Detection",
"status": "Rain Detected",
"location": "Backyard"
}
}System Status Update:
{
"phone_number": "+919876543210", //Replace with registered number
"template_id": "status_update",
"variables": {
"device_name": "Weather Station",
"status": "Operational",
"var1": "Monitoring Active"
}
}Maintenance or Service Reminder:
{
"phone_number": "+919876543210", //Replace with registered number
"template_id": "maintenance_alert",
"variables": {
"device_name": "Rain Sensor",
"message": "Sensor cleaning required"
}
}Important: 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 rain status, moisture level, sensor state, or any other value that your project generates. The system simply places whatever you send into the selected template.
Before diving into the complete sketch, understand the overall logic of the program. The Raspberry Pi Pico W connects to a WiFi network, reads the digital signal from the rain sensor, and checks whether rain has been detected. When the sensor detects moisture, the device sends a WhatsApp alert through CircuitDigest Cloud using a secure HTTPS request. The program then waits for a short cooldown period to avoid repeated alerts and continues monitoring the sensor.
The sketch starts by loading the required libraries. These libraries handle WiFi communication and secure HTTPS requests.
#include <WiFi.h>
#include <WiFiClientSecure.h>WiFi.hmanages internet connectivityWiFiClientSecure.henables HTTPS communication with the cloud server for secure message transmission
#define RAIN_SENSOR_PIN 15
#define COOLDOWN_PERIOD 60000 // 60 secondsThe code defines the GPIO pin for the rain sensor. Using macros makes the program easier to modify later and avoids hardcoding values throughout the sketch. The cooldown value prevents message flooding. Without this delay, the Pico W would send alerts continuously while the rain continues.
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* apiKey = "YOUR_API_KEY";
const char* phoneNumber = "+919876543210";WiFi credentials and API details come next. These values allow the board to connect to the internet and authenticate requests with the WhatsApp API.
The setup() function runs only once when the board powers on. It starts serial communication for debugging, configures the sensor pin as input, and connects the Pico W to WiFi. The program waits until the connection succeeds before moving forward, which ensures that alerts never fail due to a missing internet connection.
Inside the main loop, the Pico W reads the digital signal from the rain sensor repeatedly. This continuous reading allows the device to respond immediately when rain is detected.
The program then checks whether rain has been detected. The sensor output is LOW when moisture is present. If the condition becomes true and the cooldown period has passed, the device prepares to send an alert.
When triggered, the firmware calls the WhatsApp sending function. This function handles the entire API communication process:
- The Pico W first connects securely to the CircuitDigest Cloud server
- The code builds the JSON payload with phone number, template ID, and dynamic sensor status
- The program sends the HTTP headers followed by the JSON body
- After sending the request, the client waits for the server's response and closes the connection
- Finally, the firmware stores the current time to restart the cooldown timer
In short, the entire workflow stays simple and reliable. The Pico W reads the sensor, checks the condition, sends a message 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.
Install the required tools and upload the firmware to the Raspberry Pi Pico W before testing the alert system. These steps prepare the board, flash the program, and verify that everything works correctly.
-
Install required board support: Open Arduino IDE and install the Raspberry Pi Pico/RP2040 board package from Boards Manager. Search for "Raspberry Pi Pico" and install the official package by Earle F. Philhower, III.
-
Configure the project: Connect the Pico W using a Micro USB cable while holding the BOOTSEL button, open the sketch, and update your WiFi name, password, API key, and recipient phone number inside the code.
-
Select the board and upload: Choose "Raspberry Pi Pico W" 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. Test the rain sensor by applying water to the detection pad and check that the WhatsApp alert is delivered automatically.
After uploading the firmware and powering the Raspberry Pi Pico W, the Raspberry Pi Pico W WhatsApp alert system starts connecting to WiFi and begins monitoring the rain sensor continuously. You can observe the live sensor status and connection details in the Serial Monitor. When moisture is detected on the sensor pad, the Pico W immediately prepares the payload and sends a secure request to CircuitDigest Cloud, which then delivers the WhatsApp alert to the registered phone number.
In the demonstration, you can see water being applied to the rain sensor and the alert triggering as soon as moisture is detected. The Raspberry Pi Pico W notification appears instantly on WhatsApp with the device name, event type, status, and location details. After sending one alert, the system waits for the cooldown period and then continues monitoring without spamming messages.
This project is licensed under the MIT License.
For questions, support, or collaboration opportunities:
- Website: CircuitDigest
- Cloud Platform: CircuitDigest Cloud








