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

Real-time Alerts Using Arduino and Sensors

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:

  • Arduino Uno (1)
  • DHT11 Temperature and Humidity Sensor (1)
  • GSM Module (SIM900 or similar) (1)
  • Breadboard (1)
  • Jumper Wires (various)
  • 9V Battery and Battery Connector (1)

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:

  1. Library Inclusions: The DHT.h library is used for interfacing with the DHT11 sensor, and SoftwareSerial.h is used for communication with the GSM module.
  2. Pin Definitions: The data pin for the DHT11 sensor and the TX/RX pins for the GSM module are defined.
  3. Thresholds: Temperature and humidity thresholds are set for triggering alerts.
  4. Setup Function: Initializes serial communication, the DHT sensor, and the GSM module. It also sends an initial SMS to indicate the system is ready.
  5. Loop Function: Reads temperature and humidity values, checks if they exceed the thresholds, and sends an SMS alert if they do.
  6. sendSMS Function: Sends an SMS message using the GSM module.

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.