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

Arduino UNO-Based Temperature-Controlled Fan with LCD Display

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

Circuit Documentation

Summary

This circuit is designed to control a fan based on temperature readings from a DHT11 temperature-humidity sensor. The temperature data is displayed on an LCD 16x2 screen, and the fan speed is adjusted accordingly using an NPN transistor. An Arduino UNO microcontroller is used to read the sensor data, control the LCD, and adjust the fan speed.

Component List

  1. Arduino UNO

    • Description: A 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. LCD 16x2 (Wokwi Compatible)

    • Description: A 16x2 character LCD display.
    • Pins: VSS, VDD, V0, RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7, A, K
  3. KY-015 DHT11 Temperature-Humidity Sensor Module

    • Description: A sensor module for measuring temperature and humidity.
    • Pins: VCC, GND, DOUT
  4. Fan

    • Description: A simple DC fan.
    • Pins: GND, 5V
  5. NPN Transistor (CBE)

    • Description: A transistor used to control the fan.
    • Pins: collector, base, emitter
  6. Trimmer Potentiometer

    • Description: A variable resistor used to adjust the contrast of the LCD.
    • Pins: leg1, wiper, leg2
    • Properties: Resistance: 10,000 Ohms

Wiring Details

Arduino UNO

LCD 16x2 (Wokwi Compatible)

KY-015 DHT11 Temperature-Humidity Sensor Module

Fan

NPN Transistor (CBE)

Trimmer Potentiometer

Code Documentation

//Sumit.in

#include <DHT.h>
#include<LiquidCrystal.h>

const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2, ct=9;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define DHTPIN 12     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
#define pwm 9

byte degree[8] = 
{
  0b00011,
  0b00011,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  lcd.begin(16, 2);
  lcd.createChar(1, degree);
  lcd.clear();
  lcd.print("   Fan Speed  ");
  lcd.setCursor(0,1);
  lcd.print("  Controlling ");
  delay(2000);
  analogWrite(pwm, 255);
  lcd.clear();
  lcd.print("Hello Sir ");
  delay(1000);
  Serial.begin(9600); 
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in t in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  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");

  if(t <24 ) {
    lcd.setCursor(0,0);
    lcd.print("temp: ");
    lcd.print(t);   // Printing tempature on LCD
    lcd.print(" C");
    lcd.setCursor(0,1);
    analogWrite(9,0);
    lcd.print("Fan OFF            ");
    delay(100);
  } else if(t>=24 && t<=26) {
    lcd.setCursor(0,0);
    lcd.print("temp: ");
    lcd.print(t);   // Printing tempature on LCD
    lcd.print(" C");
    lcd.setCursor(0,1);            
    analogWrite(pwm, 100);
    lcd.print("Fan Speed: 20%   ");
    delay(100);
  } else if(t>=26.1 && t<=28) {
    lcd.setCursor(0,0);
    lcd.print("temp: ");
    lcd.print(t);   // Printing tempature on LCD
    lcd.print(" C");
    lcd.setCursor(0,1);
    analogWrite(pwm, 132);
    lcd.print("Fan Speed: 40%   ");
    delay(100);
  } else if(t>=28.1 && t<=28.9) {
    lcd.setCursor(0,0);
    lcd.print("temp: ");
    lcd.print(t);   // Printing tempature on LCD
    lcd.print(" C");
    lcd.setCursor(0,1);
    analogWrite(pwm, 153);
    lcd.print("Fan Speed: 60%   ");
    delay(100);
  } else if(t==29) {
    lcd.setCursor(0,0);
    lcd.print("temp: ");
    lcd.print(t);   // Printing tempature on LCD
    lcd.print(" C