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

Arduino UNO-Based Temperature and Humidity Controlled Fan with LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Temperature and Humidity Controlled Fan with LCD Display

Circuit Documentation

Summary

This circuit is a fan speed control system that uses an Arduino UNO microcontroller to read temperature and humidity data from a DHT11 sensor and display the information on a 16x2 I2C LCD. The fan speed is controlled based on the temperature readings using an NPN transistor as a switch.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. DHT11

    • Description: Temperature and humidity sensor.
    • Pins: DATA, GND, VCC
  3. 16x2 I2C LCD

    • Description: 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  4. Fan

    • Description: DC fan.
    • Pins: GND, 5V
  5. NPN Transistor (EBC)

    • Description: NPN transistor used for switching.
    • Pins: emitter, base, collector
  6. 9V Battery

    • Description: Power source.
    • Pins: -, +

Wiring Details

Arduino UNO

DHT11

16x2 I2C LCD

Fan

NPN Transistor (EBC)

9V Battery

Code Documentation

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

// Pin and type definitions
#define DHTPIN 7        // DHT sensor pin
#define DHTTYPE DHT11   // DHT 11 type
#define pwm 9           // Fan control PWM pin

// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);

// Initialize I2C LCD (update address if necessary)
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  // Initialize LCD
  lcd.init();              
  lcd.backlight();         
  lcd.setCursor(0, 0);
  lcd.print("Fan Speed Ctrl");
  delay(2000);

  // Display initialization message
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Initializing...");
  analogWrite(pwm, 255);   // Initialize fan at full speed
  delay(2000);

  // System ready message
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("System Ready");
  delay(2000);

  // Initialize Serial Monitor
  Serial.begin(9600);      
  Serial.println("Fan Speed Controlling System");
  
  // Initialize DHT sensor
  dht.begin();
}

void loop() {
  delay(1000);

  // Read temperature and humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();  // Celsius
  float f = dht.readTemperature(true);  // Fahrenheit

  // Check for sensor errors
  if (isnan(h) || isnan(t) || isnan(f)) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Sensor Error!");
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  float hi = dht.computeHeatIndex(f, h);

  // Print data to Serial Monitor
  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" °C ");
  Serial.print(f);
  Serial.print(" °F\t");
  Serial.print("Heat Index: ");
  Serial.print(hi);
  Serial.println(" °F");

  // Display temperature and humidity on the LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print(" C");

  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");

  // Fan speed control logic
  if (t < 25) {
    analogWrite(pwm, 0);
    Serial.println("Fan OFF");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan OFF");
  } else if (t >= 25 && t < 30) {
    analogWrite(pwm, 32); // Fan at 12.5% speed
    Serial.println("Fan Speed: 12.5%");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan Speed: 12.5%");
  } else if (t >= 30 && t < 35) {
    analogWrite(pwm, 64); // Fan at 25% speed
    Serial.println("Fan Speed: 25%");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan Speed: 25%");
  } else if (t >= 35 && t < 40) {
    analogWrite(pwm, 128); // Fan at 50% speed
    Serial.println("Fan Speed: 50%");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan Speed: 50%");
  } else if (t >= 40 && t < 45) {
    analogWrite(pwm, 191); // Fan at 75% speed
    Serial.println("Fan Speed: 75%");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan Speed: 75%");
  } else if (t >= 45 && t < 50) {
    analogWrite(pwm, 239); // Fan at 93.75% speed
    Serial.println("Fan Speed: 93.75%");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan Speed: 93.75%");
  } else {
    analogWrite(pwm, 255); // Fan at 100% speed
    Serial.println("Fan Speed: 100%");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Fan Speed: 100%");
  }

  delay(2000);  // Delay before the next iteration
}

This code initializes the DHT11 sensor and the 16x2 I2C LCD, reads temperature and humidity data, and controls the fan speed based on the temperature readings. The data is displayed on the LCD and printed to the Serial Monitor.