Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
In today's interconnected world, real-time alerts are crucial for monitoring and responding to various conditions in real-time. Whether it's for home automation, industrial monitoring, or personal projects, the ability to receive immediate notifications can significantly enhance safety, efficiency, and convenience. This article will explore how to implement real-time alerts using Arduino, focusing on integrating sensors and communication modules to send alerts based on specific conditions.
Project: The project aims to create a real-time alert system using Arduino that monitors temperature and humidity levels. When the temperature or humidity exceeds predefined thresholds, the system will send an alert via an SMS message. This project is ideal for applications such as greenhouse monitoring, server room monitoring, or any environment where maintaining specific temperature and humidity levels is critical.
Components List:
Examples:
// Include necessary libraries
#include <DHT.h> // Library for DHT sensor
#include <SoftwareSerial.h> // Library for software serial communication
// Define pin connections and constants
#define DHTPIN 2 // DHT11 data pin connected to digital pin 2
#define DHTTYPE DHT11 // Define the type of DHT sensor
#define GSM_TX 7 // GSM module TX pin connected to digital pin 7
#define GSM_RX 8 // GSM module RX pin connected to digital pin 8
// Initialize DHT sensor and GSM module
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial gsm(GSM_TX, GSM_RX);
// Define threshold values for temperature and humidity
const float TEMP_THRESHOLD = 30.0; // Temperature threshold in Celsius
const float HUM_THRESHOLD = 70.0; // Humidity threshold in percentage
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
// Start software serial communication with GSM module
gsm.begin(9600);
// Initialize DHT sensor
dht.begin();
// Give some time for the GSM module to initialize
delay(10000);
// Send initial message to indicate system is ready
sendSMS("Alert System Initialized");
}
void loop() {
// Read temperature and humidity values
float temp = dht.readTemperature();
float hum = dht.readHumidity();
// Check if any reads failed and exit early
if (isnan(temp) || isnan(hum)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the values to the serial monitor
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" °C, Humidity: ");
Serial.print(hum);
Serial.println(" %");
// Check if temperature exceeds threshold
if (temp > TEMP_THRESHOLD) {
sendSMS("Temperature Alert! Current Temp: " + String(temp) + " °C");
}
// Check if humidity exceeds threshold
if (hum > HUM_THRESHOLD) {
sendSMS("Humidity Alert! Current Humidity: " + String(hum) + " %");
}
// Wait for 2 seconds before the next reading
delay(2000);
}
// Function to send SMS using GSM module
void sendSMS(String message) {
gsm.println("AT+CMGF=1"); // Set the GSM module to text mode
delay(1000);
gsm.println("AT+CMGS=\"+1234567890\""); // Replace with the recipient's phone number
delay(1000);
gsm.println(message); // The message to send
delay(1000);
gsm.println((char)26); // ASCII code for Ctrl+Z to send the message
delay(1000);
Serial.println("SMS Sent: " + message);
}
Explanation:
DHT.h
library is used for interfacing with the DHT11 sensor, and SoftwareSerial.h
is used for communication with the GSM module.