#include <DHT.h> // Include the DHT sensor library
#define DHTPIN 16 // Define the pin to which the DHT sensor is connected
#define DHTTYPE DHT22 // Define the type of DHT sensor being used
DHT dht(DHTPIN, DHTTYPE); // Create a DHT object
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
Serial.begin(115200); // Initialize serial communication
dht.begin(); // Initialize the DHT sensor
pinMode(38, OUTPUT); // Set pin 38 as an output
pinMode(19, OUTPUT); // Set pin 19 as an output
lcd.begin(16, 2);
}
void loop() {
delay(2000); // Delay for 2 seconds
lcd.clear();// Clear LCD screen
float temp = dht.readTemperature(); // Read temperature from the DHT sensor
float hum = dht.readHumidity(); // Read humidity from the DHT sensor
int16_t ppmValue = analogRead(36);// Value after from AD convertor
int mappedppmValue = (ppmValue/4.095);// Map the correct value ad AD convertor expects max votage to be 3.3 V and we are sending 5 V
// Print temperature and humidity readings on LCD
lcd.setCursor(0, 0); // Set cursor to first column of first row
lcd.print("Temp:");
lcd.print(temp);
lcd.print(" C");
lcd.setCursor(0, 1); // Set cursor to first column of second row
lcd.print("H:");
lcd.print(hum);
lcd.print("%");
lcd.setCursor(9, 1); // Set cursor to first column of 3 row
lcd.print("PPM:");
lcd.print(mappedppmValue);
// Print temperature and humidity readings to the serial monitor
Serial.print("La température actuelle est : ");
Serial.print(temp);
Serial.println("°C");
Serial.print("humidité: ");
Serial.print(hum);
Serial.println(" %");
Serial.print("PPM: "); // Control the output based on temperature
Serial.println(mappedppmValue); // Print maapedTdsValue
if (temp > 27) {
for (int i = 0; i < 6; i++) {
digitalWrite(38, HIGH); // Turn on pin 38
delay(900); // Delay for 900 milliseconds
digitalWrite(38, LOW); // Turn off pin 38
delay(900); // Delay for another 900 milliseconds
}} else {
for (int i = 0; i < 6; i++) {
digitalWrite(19, HIGH); // Turn on pin 19
delay(900); // Delay for 900 milliseconds
digitalWrite(19, LOW); // Turn off pin 19
delay(900); // Delay for another 900 milliseconds
}}
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1