#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h> // تضمين مكتبة DHT
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 1024.0
#define PIN_LM35 A0
#define DHTPIN 2 // تعيين رقم دبوس الاستشعار
#define DHTTYPE DHT22 // تحديد نوع المستشعر
DHT dht(DHTPIN, DHTTYPE); // تعريف المستشعر
// Set the LCD address to 0x27 or 0x3F based on your actual address
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change to your LCD's address
void setup() {
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight(); // Enable backlight
// Set up the LCD's number of columns and rows (not needed for LiquidCrystal_I2C)
// lcd.begin(16, 2);
dht.begin(); // بدء المستشعر
}
void loop() {
// قراءة بيانات درجة الحرارة والرطوبة
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// التحقق مما إذا كانت القراءة ناجحة
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// get the ADC value from the LM35 temperature sensor
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float tempC = milliVolt / 10;
// convert the Celsius to Fahrenheit
float tempF = tempC * 9 / 5 + 32;
// clear the LCD screen
lcd.clear();
// print the temperature on the LCD screen
lcd.setCursor(0, 0);
lcd.print("Temp LM35: ");
lcd.print(tempC); // print the temperature in Celsius
lcd.print("C ");
lcd.print(tempF); // print the temperature in Fahrenheit
lcd.print("F");
// print the temperature and humidity on the Serial Monitor
Serial.print("Temperature (LM35): ");
Serial.print(tempC); // print the temperature in Celsius
Serial.print("°C");
Serial.print(" ~ "); // separator between Celsius and Fahrenheit
Serial.print(tempF); // print the temperature in Fahrenheit
Serial.println("°F");
Serial.print("Temperature (DHT22): ");
Serial.print(temperature); // print the temperature in Celsius
Serial.print("°C");
Serial.print(" Humidity: ");
Serial.print(humidity); // print the humidity
Serial.println("%");
delay(1000);
}