This circuit is designed to automatically control a room heater based on the temperature readings from a DHT22 sensor. The system uses an Arduino UNO to read the temperature and control a relay, which in turn switches the heater element on or off. The goal is to maintain the room temperature above a specified threshold (22.0°C in this case).
Arduino UNO
1 Channel Relay 5V
Power 220V
DHT22
Heater Element
/*
* Automatic Temperature Control Room Heater System
*
* This Arduino sketch reads the temperature from a DHT22 sensor and controls
* a relay to turn a heater on or off based on the temperature reading. The
* relay is connected to a heater element, and the system aims to maintain
* the room temperature above a specified threshold (22.0°C in this case).
*/
#include <DHT.h>
#define DHTPIN 2 // Pin where the DHT22 is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define RELAY_PIN 3 // Pin where the relay is connected
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Ensure the relay is off initially
}
void loop() {
float temperature = dht.readTemperature();
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
if (temperature < 22.0) { // Set your desired temperature threshold
digitalWrite(RELAY_PIN, HIGH); // Turn on the heater
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off the heater
}
delay(2000); // Wait a few seconds between measurements
}
This code initializes the DHT22 sensor and the relay, reads the temperature from the sensor, and controls the relay to turn the heater on or off based on the temperature reading. The system aims to maintain the room temperature above 22.0°C.