Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

SMS Notifications with Arduino

Importance and Utility of SMS Notifications

SMS notifications are a powerful tool in today's world of connected devices and Internet of Things (IoT). They allow us to receive real-time alerts and updates on our mobile phones, enabling us to stay informed and take immediate action when necessary. SMS notifications can be used in a wide range of applications, such as home security systems, environmental monitoring, industrial automation, and more. By integrating Arduino with SMS capabilities, we can create smart and interactive systems that enhance our daily lives.

Project: Creating an SMS notification system with Arduino

In this example project, we will create an SMS notification system using Arduino and a GSM module. The objective is to receive notifications on our mobile phone whenever a specific event occurs. For simplicity, let's consider a scenario where we want to be notified whenever the temperature in a room exceeds a certain threshold.

The functionality of the project can be summarized as follows:

  1. Measure the temperature using a temperature sensor (e.g., DS18B20).
  2. Compare the measured temperature with a predefined threshold.
  3. If the temperature exceeds the threshold, send an SMS notification to a specified phone number.

List of components:

Examples:

1. Sending an SMS notification

#include <SoftwareSerial.h>

SoftwareSerial gsmSerial(2, 3); // RX, TX pins for GSM module

void setup() {
  Serial.begin(9600);
  gsmSerial.begin(9600);

  delay(2000); // Allow time for GSM module to initialize
  sendSMS("+1234567890", "Temperature exceeded threshold!"); // Replace with your phone number
}

void loop() {
  // Main program loop
}

void sendSMS(String phoneNumber, String message) {
  gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
  delay(1000);

  gsmSerial.println("AT+CMGS=\"" + phoneNumber + "\""); // Specify the recipient phone number
  delay(1000);

  gsmSerial.print(message); // Send the message content
  delay(1000);

  gsmSerial.write(26); // Send Ctrl+Z to indicate the end of the message
  delay(1000);
}

This example demonstrates how to send an SMS notification using Arduino and a GSM module. The sendSMS function takes a phone number and a message as input and sends the SMS. Make sure to replace "+1234567890" with your phone number.

2. Temperature monitoring and SMS notification

#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>

SoftwareSerial gsmSerial(2, 3); // RX, TX pins for GSM module
OneWire oneWire(4); // Data pin for DS18B20 temperature sensor
DallasTemperature sensors(&oneWire);

float temperatureThreshold = 25.0; // Temperature threshold in degrees Celsius

void setup() {
  Serial.begin(9600);
  gsmSerial.begin(9600);
  sensors.begin();

  delay(2000); // Allow time for GSM module to initialize
}

void loop() {
  sensors.requestTemperatures(); // Request temperature reading
  float temperature = sensors.getTempCByIndex(0); // Get temperature in degrees Celsius

  if (temperature > temperatureThreshold) {
    sendSMS("+1234567890", "Temperature exceeded threshold! Current temperature: " + String(temperature) + "°C");
  }

  delay(5000); // Wait for 5 seconds before checking temperature again
}

void sendSMS(String phoneNumber, String message) {
  gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
  delay(1000);

  gsmSerial.println("AT+CMGS=\"" + phoneNumber + "\""); // Specify the recipient phone number
  delay(1000);

  gsmSerial.print(message); // Send the message content
  delay(1000);

  gsmSerial.write(26); // Send Ctrl+Z to indicate the end of the message
  delay(1000);
}

This example extends the previous one by adding temperature monitoring. The temperature is measured using a DS18B20 temperature sensor, and if it exceeds the threshold, an SMS notification is sent. The current temperature is included in the message content.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.