//[1] Interface an ESP32 with a DHT22 sensor with appropriate connections. If the temperature is
//below a threshold value ‘T_thresh’, then use the color ‘RED’ in an RGB LED to notify the user. If
//the temperature is above ‘T_Thresh’, use the color ‘GREEN’.
#include <DHT.h>
#define DHTPIN 4
#define RED 25
#define GREEN 26
DHT dht(DHTPIN, DHT22);
float T_thresh = 25;
void setup() {
dht.begin();
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void loop() {
float t = dht.readTemperature();
if (t < T_thresh) {
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
} else {
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
}
delay(2000);
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4