Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Automatic Temperature-Controlled Fan with DHT11 Sensor and I2C LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Automatic Temperature-Controlled Fan with DHT11 Sensor and I2C LCD Display

Circuit Documentation

Summary

This circuit is designed to monitor temperature using a DHT11 sensor and control a fan based on the temperature reading. It features an Arduino UNO as the central microcontroller, interfaced with a DHT11 temperature and humidity sensor, a 16x2 I2C LCD for displaying temperature and fan status, a 1-Channel Relay to control the fan, and a 9V battery to power the relay and fan. The Arduino UNO is programmed to read the temperature from the DHT11 sensor and turn the fan on or off depending on whether the temperature exceeds a predefined threshold.

Component List

Arduino UNO

DHT11

16x2 I2C LCD

1-Channel Relay (5V 10A)

Fan

9V Battery

Wiring Details

Arduino UNO

DHT11

16x2 I2C LCD

1-Channel Relay (5V 10A)

Fan

9V Battery

Documented Code

#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Settings for DHT11
#define DHTPIN 2          // DHT11 connected to digital pin 2
#define DHTTYPE DHT11     // DHT type is DHT11
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT

// Settings for I2C LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address for 16x2 LCD

// Fan settings
#define FAN_PIN 9         // Fan connected to digital pin 9
int tempThreshold = 30;  // Temperature threshold to turn on the fan (e.g., 30°C)

void setup() {
  pinMode(FAN_PIN, OUTPUT);
  digitalWrite(FAN_PIN, LOW); // Turn off fan at startup
  dht.begin();                // Initialize DHT11
  lcd.begin(16, 2);           // Initialize 16x2 LCD
  lcd.backlight();            // Turn on LCD backlight
  lcd.setCursor(0, 0);
  lcd.print("Auto Fan Control");
  delay(2000);
  lcd.clear();
}

void loop() {
  float temp = dht.readTemperature(); // Read temperature in Celsius

  // If reading fails, stop
  if (isnan(temp)) {
    lcd.setCursor(0, 0);
    lcd.print("Temp Read Fail!");
    return;
  }

  // Display temperature on LCD
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temp);
  lcd.print((char)223); // Degree character
  lcd.print("C   ");
  
  // Logic to turn on or off the fan
  if (temp >= tempThreshold) {
    digitalWrite(FAN_PIN, HIGH); // Turn on fan if temp >= tempThreshold
    lcd.setCursor(0, 1);
    lcd.print("Fan: ON ");
  } else {
    digitalWrite(FAN_PIN, LOW);  // Turn off fan if temp < tempThreshold
    lcd.setCursor(0, 1);
    lcd.print("Fan: OFF");
  }

  delay(2000); // Update every 2 seconds
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the DHT11 sensor and the I2C LCD, reads the temperature from the DHT11 sensor, and controls the fan via the relay based on the temperature reading. The LCD displays the current temperature and the status of the fan.