/*
Arduino | general-help
Andriska — 3:47 PM Friday, January 2, 2026
Someone help please
*/
#include <DHT.h>
#define DHTTYPE DHT22
const int DHT_PIN = 10;
const int LED_PINS[] = {4, 3, 2};
// room temperature in Celsius
const float baselineTemp = 20.0;
DHT dht(DHT_PIN, DHTTYPE);
void turnAllOff() {
for (int i = 0; i < 3; i++) {
digitalWrite(LED_PINS[i], LOW);
}
}
void setup() {
// open a serial connection to display values
Serial.begin(9600);
// start DHT sensor
dht.begin();
// set the LED pins as outputs
for (int numLed = 0; numLed < 3; numLed++) {
pinMode(LED_PINS[numLed], OUTPUT);
}
}
void loop() {
// read the temperature from the DHT sensor
float temperature = dht.readTemperature(); // Celsius
// check if reading failed
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature, 1);
Serial.println("°C");
turnAllOff();
// if the current temperature is lower than the baseline turn off all LEDs
if (temperature < baselineTemp + 2) {
turnAllOff();
} // else if the temperature rises 2-4 degrees, turn an LED on
else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) {
digitalWrite(LED_PINS[0], HIGH);
} // else if the temperature rises 4-6 degrees, turn a second LED on
else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) {
digitalWrite(LED_PINS[1], HIGH);
} // if the temperature rises more than 6 degrees, turn all LEDs on
else if (temperature >= baselineTemp + 6) {
digitalWrite(LED_PINS[2], HIGH);
}
// DHT11 requires slow sampling rate
delay(2000);
}