can you help me combine my code this
// Libraries
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
// Constants
#define DHTPIN A3 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
#define BUZZER_PIN 9 // Pin connected to the buzzer
#define TEMP_LIMIT 40 // New temperature limit (adjust as needed)
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
// Variables
int h; // Stores humidity value
int t; // Stores temperature value
void setup() {
Serial.begin(9600);
Serial.println("Temperature and Humidity Sensor Test");
dht.begin();
lcd.init(); // Initialize the lcd
lcd.backlight(); // Open the backlight
pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as output
}
void loop() {
// Read data and store it to variables h (humidity) and t (temperature)
h = dht.readHumidity();
t = dht.readTemperature();
// Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %, Temp: ");
Serial.print(t);
Serial.println(" ° Celsius");
// Set the cursor to (0,0) and print
lcd.setCursor(0, 0);
lcd.println(" TEMP AND HUMI ");
lcd.setCursor(0, 1);
lcd.print(" T:");
lcd.print(t);
lcd.print("C");
lcd.setCursor(11, 1);
lcd.print("H:");
lcd.print(h);
lcd.print("%");
// Check temperature against the limit
if (t > TEMP_LIMIT) {
digitalWrite(BUZZER_PIN, HIGH); // Turn buzzer on
} else {
digitalWrite(BUZZER_PIN, LOW); // Turn buzzer off
}
delay(100);
}
and this is my second code
#include <DHT.h>
#include <SoftwareSerial.h>
#define DHTPIN 2 // Pin where the DHT11 is connected
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial sim800(9, 10); // RX, TX for SIM800L
String phone_number = "YOUR_PHONE_NUMBER"; // Replace with your phone number
void setup() {
Serial.begin(9600);
sim800.begin(9600);
dht.begin();
delay(1000); // Give time for modules to initialize
Serial.println("System started");
}
void loop() {
float temp = dht.readTemperature();
if (isnan(temp)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" *C");
// If temperature exceeds 40°C, trigger a call
if (temp > 40) {
makeCall();
delay(300000); // Delay for 5 minutes before rechecking the temperature
}
delay(2000); // Read temperature every 2 seconds
}
void makeCall() {
Serial.println("Temperature exceeded 40°C. Making a call...");
// AT command to dial a number
sim800.print("ATD");
sim800.print(phone_number);
sim800.println(";");
delay(30000); // Allow the call to last for 30 seconds before hanging up
// AT command to hang up
sim800.println("ATH");
Serial.println("Call ended.");
}