#include <DHT.h>
#include <SoftwareSerial.h>
#define DHT_PIN 2 // Pin where the DHT22 is connected
#define AMMONIA_PIN A0 // Analog pin where the ammonia sensor is connected
#define PHONE_NUMBER "1234567890" // Replace with the phone number to receive SMS alerts
DHT dht(DHT_PIN, DHT22);
SoftwareSerial sim800l(10, 11); // RX, TX for SIM800L communication
void setup() {
Serial.begin(9600);
dht.begin();
sim800l.begin(9600);
}
void loop() {
delay(2000); // Adjust the delay based on your requirements
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int ammoniaValue = analogRead(AMMONIA_PIN);
if (temperature >= 28 && temperature <= 32 && ammoniaValue > YOUR_AMMONIA_THRESHOLD) {
sendAlertSMS();
}
}
void sendAlertSMS() {
sim800l.println("AT+CMGF=1"); // Set SMS mode to text
delay(1000);
sim800l.print("AT+CMGS=\"");
sim800l.print(PHONE_NUMBER);
sim800l.println("\"");
delay(1000);
sim800l.print("Alert: Temperature and/or Ammonia levels exceeded!");
sim800l.write(26); // End with Ctrl+Z
delay(1000);
}