This circuit is designed to monitor temperature using a DHT11 sensor and control a fan based on the temperature readings. The system includes an Arduino UNO microcontroller, a 5V relay, an LCM1602 IIC LCD display, a DHT11 temperature and humidity sensor, an HC-05 Bluetooth module, and a fan. The Arduino UNO reads the temperature from the DHT11 sensor and displays it on the LCD. If the temperature exceeds a predefined threshold, the Arduino activates the relay to turn on the fan. The HC-05 Bluetooth module allows for wireless communication.
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2 // DHT sensor connected to digital pin 2
#define DHTTYPE DHT11 // DHT 11 or DHT 22, depending on your sensor
#define RELAY_PIN 3 // Relay connected to digital pin 3
#define TEMP_THRESHOLD 30 // Temperature threshold in Celsius
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address for 16x2 LCD
void setup() {
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight(); // Turn on the LCD backlight
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Initially turn off the fan
}
void loop() {
float temperature = dht.readTemperature(); // Read temperature in Celsius
// Check if the reading is valid
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
lcd.setCursor(0, 0);
lcd.print("Sensor Error ");
delay(2000);
return;
}
// Display temperature on the Serial Monitor and LCD
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C ");
// Fan control based on temperature
if (temperature >= TEMP_THRESHOLD) {
digitalWrite(RELAY_PIN, LOW); // Turn on the fan
lcd.setCursor(0, 1);
lcd.print("Fan: ON ");
} else {
digitalWrite(RELAY_PIN, HIGH); // Turn off the fan
lcd.setCursor(0, 1);
lcd.print("Fan: OFF ");
}
delay(2000); // Delay between readings
}
This code initializes the DHT11 sensor and the LCD display, reads the temperature from the DHT11 sensor, and displays it on the LCD. If the temperature exceeds the threshold, the relay is activated to turn on the fan. The system also prints the temperature readings to the Serial Monitor for debugging purposes.