// This project implements the simulation of the reading a DHT sensor using an ESP32
// The source code is available on my git repo at : https://github.com/Bamamou/DHT11_ESP32.git
// the only difference is the sensor, Here; we use a DHT11 while in Platform io we use a DHT22
#include <DHT.h>
// Set up the DHT sensor
DHT dht(33, DHT22);
#define LED_Red 4
#define LED_Green 2
#define Buzzer 5
#define LED_Green 2
float temperature ;
float humidity;
const int pot1Pin = 35;
int pot1Value = 0;
int counter;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Hello, ESP32!");
pinMode(LED_Red, OUTPUT);
pinMode(LED_Green, OUTPUT);
pinMode(Buzzer, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.println("======================= ");
Serial.println("Data: "+ String(counter));
// Print the values of temperature in Celsus
Serial.print("Temperatue:\t");
Serial.print(dht.readTemperature(false));
Serial.println("°C");
// print Humidity in perscent
Serial.println("Humidity: \t"+String(humidity)+ "%");
// Print the values of the heat Index for both Units
delay(1000); // this speeds up the simulation
if (dht.readTemperature(false) >= 30)
{
digitalWrite(LED_Red, HIGH);
delay(100);
digitalWrite(LED_Green, LOW);
delay(100);
tone(Buzzer, 440, 500);
}
else
{
digitalWrite(LED_Red, LOW);
delay(100);
digitalWrite(LED_Green, HIGH);
delay(100);
}
counter++;
pot1Value = analogRead(potPin);
Serial.println(pot1Value);
delay(500);
}