IOT ARCHITECTURE & PROTOCOLS (202046714)
G..H PATEL COLLEGE OF ENGINEERING AND TECHNOLOGY
Practical - 5
Aim: To Send an SMS Using an ESP8266/NodeMCU
Apparatus: NodeMCU (ESP8266), WiFi Connection, Circuit Digest Cloud account,
USB cable (for programming), Computer with Arduino IDE.
Theory: Sending SMS via ESP8266 Using Circuit Digest
Cloud
Circuit Digest Cloud is an IoT platform that allows ESP8266 to send HTTP requests to
perform various actions, such as sending SMS notifications.
How It Works:
1. ESP8266 connects to WiFi and establishes internet access.
2. Sends an HTTP request to Circuit Digest Cloud's API with the required parameters.
3. The API processes the request and sends an SMS to the registered phone number.
Procedure: Setting Up SMS API on Circuit Digest Cloud
Step 1: Access the Platform
Open Circuit Digest Cloud.
Log in or sign up for a new account if you don’t have one.
Step 2: Register and Log In
Click on Login to access both Login and Register options.
If new, fill in the registration form to create an account.
Step 3: Understand the SMS API Template
Before creating an API key, understand the predefined SMS template system.
Each template has a unique template ID, template name, and customizable variables (e.g.,
#var#).
In this example, we will use Template ID: 104 for a battery low alert SMS.
The message format includes placeholders (#var#), where values like "GPS TRACKER" and
"20" will be inserted dynamically.
Step 4: Create an API Key
Name: Prem Kumar Das En.No.:12202110501075
IOT ARCHITECTURE & PROTOCOLS (202046714)
G..H PATEL COLLEGE OF ENGINEERING AND TECHNOLOGY
After logging in, go to "My Account" in the top-right corner.
Click on Create API Key.
Complete the captcha and submit.
Step 5: API Key Activation
If the captcha is correct, an API key is generated.
The API key allows 100 free SMS per month.
This key expires after one month, so a new key must be generated periodically.
Step 6: Link a Phone Number for SMS Alerts
Scroll down to the phone number linking section.
Enter your phone number and complete the captcha.
Click "Get OTP".
A pop-up will confirm that the OTP has been sent to the entered number.
Step 7: Verify the OTP
Enter the received OTP in the provided field.
Click OK to complete the phone number verification.
Code :
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
const char* ssid = "kqugiqbf";
const char* password = "craxxxxxx05";
const char* apiKey = "xxxxxxxxxxx";
const char* templateID = "104";
const char* mobileNumber = "xxxxxxxxxxxxx";
const char* var1 = "GPS TRACKER";
const char* var2 = "20";
Name: Prem Kumar Das En.No.:12202110501075
IOT ARCHITECTURE & PROTOCOLS (202046714)
G..H PATEL COLLEGE OF ENGINEERING AND TECHNOLOGY
void sendSMS() {
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client; // Use WiFiClientSecure for HTTPS connections
client.setInsecure(); // Skip certificate validation (not secure but works for
development)
HTTPClient http;
// Build the API URL with the template ID
String apiUrl = "https://www.circuitdigest.cloud/send_sms?ID=" +
String(templateID);
// Start the HTTPS connection with WiFiClientSecure
http.begin(client, apiUrl);
http.addHeader("Authorization", apiKey);
http.addHeader("Content-Type", "application/json");
// Create the JSON payload with SMS details
String payload = "{\"mobiles\":\"" + String(mobileNumber) + "\",\"var1\":\"" +
String(var1) +
"\",\"var2\":\"" + String(var2) + "\"}";
// Send POST request
int httpResponseCode = http.POST(payload);
// Check response
if (httpResponseCode == 200) {
Serial.println("SMS sent successfully!");
Serial.println(http.getString());
} else {
Name: Prem Kumar Das En.No.:12202110501075
IOT ARCHITECTURE & PROTOCOLS (202046714)
G..H PATEL COLLEGE OF ENGINEERING AND TECHNOLOGY
Serial.print("Failed to send SMS. Error code: ");
Serial.println(httpResponseCode);
Serial.println("Response: " + http.getString());
http.end(); // End connection
} else {
Serial.println("WiFi not connected!");
void setup() {
Serial.begin(9600);
WiFi.begin(ssid,password);
Serial.print("Connecting to wifi");
while(WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
Serial.println("\nConnected!");
sendSMS();
void loop() {
// put your main code here, to run repeatedly:
}
Name: Prem Kumar Das En.No.:12202110501075
IOT ARCHITECTURE & PROTOCOLS (202046714)
G..H PATEL COLLEGE OF ENGINEERING AND TECHNOLOGY
Conclusion:
1. The ESP8266 successfully sends an SMS using Circuit Digest Cloud without a
GSM module.
2. This method is simple and effective for IoT applications like sensor alerts,
home automation, or emergency notifications.
3. The Circuit Digest API acts as an intermediary, enabling the ESP8266 to send
SMS over the internet.
Name: Prem Kumar Das En.No.:12202110501075