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

ESP32-Based Smart Temperature-Controlled Fan System with Wi-Fi Connectivity

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Temperature-Controlled Fan System with Wi-Fi Connectivity

Circuit Documentation

Summary

The circuit is designed to control a 220V fan and monitor temperature and humidity using an ESP32 Devkit V1 microcontroller. The system includes a DHT22 sensor for measuring temperature and humidity, a two-channel 5V relay to control the fan, LEDs for status indication, an LCD display for user feedback, a buzzer for alerts, and a power supply to provide the necessary voltages. The ESP32 is programmed to communicate with the Blynk platform for remote monitoring and control.

Component List

ESP32 Devkit V1

Two Channel Relay 5v

220V Fan

LED: Two Pin (red)

LED: Two Pin (green)

DHT22

LCD Display 16x4 I2C

POWER SUPPLY 5V 5AMP

Buzzer

Socket

Timer

Wiring Details

ESP32 Devkit V1

Two Channel Relay 5v

220V Fan

LED: Two Pin (red)

LED: Two Pin (green)

DHT22

LCD Display 16x4 I2C

POWER SUPPLY 5V 5AMP

Buzzer

Socket

Timer

Documented Code

ESP32 Devkit V1 Code

#define BLYNK_TEMPLATE_ID "TMPL6-vn2VN_V"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "vO02bgbn-43wyzsgJdoY47qDX3Jl8R8y"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <DHT.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>  // I2C LCD library

#define DHTPIN 4                 // Pin where the DHT22 data pin is connected
#define DHTTYPE DHT22            // DHT 22 (AM2302)
#define RELAY_PIN 26             // GPIO pin where relay is connected (IN1)
#define RED_LED_PIN 27           // GPIO pin where RED LED is connected
#define GREEN_LED_PIN 14         // GPIO pin where GREEN LED is connected
#define TEMP_MAX_THRESHOLD 65.0  // Maximum temperature threshold in Celsius
#define TEMP_MIN_THRESHOLD 60.0  // Minimum temperature threshold in Celsius

// WiFi credentials
char ssid[] = "haiyaaa";
char pass[] = "430578440";

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

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

bool blowerState = false;  // Blower state, controlled by Blynk
int blowerbutton;
int countdown = 0;  // Timer countdown (initially 0 seconds)
bool countdownActive = false;
BlynkTimer timer;  // Timer for sensor values and countdown

void setup() {
  Serial.begin(115200);
  dht.begin();  // Start reading the DHT sensor

  // Set relay and LED pins as outputs
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);

  // Ensure relay and RED LED are off initially, GREEN LED is off
  digitalWrite(RELAY_PIN, HIGH);      // Turn off the relay initially
  digitalWrite(RED_LED_PIN, LOW);     // Turn RED LED off initially
  digitalWrite(GREEN_LED_PIN, LOW);   // Turn GREEN LED off initially

  Serial.println("System initialized...");

  // Initialize LCD
  lcd.init();           // Initialize the LCD with 16 columns and 2 rows
  lcd.backlight();      // Turn on the LCD backlight
  lcd.setCursor(0, 0);
  lcd.print("Connecting to");
  lcd.setCursor(0, 1);
  lcd.print("Wifi");

  // Initialize Blynk connection
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Connected!!");

  delay(3000);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Cloth Dryer");

  digitalWrite(RELAY_PIN, HIGH);      // Turn blower OFF
  digitalWrite(RED_LED_PIN, LOW);     // Turn RED LED OFF (blower is OFF)
  digitalWrite(GREEN_LED_PIN, LOW);   // Turn GREEN LED OFF

  // Set a timer to read the sensor values every 2 seconds
  timer.setInterval(2000L, readDHTAndSendToBlynk);
}

// Blynk virtual pin to control the blower (relay)
BLYNK_WRITE(V1) {
  blowerbutton = param.asInt();  // Get value from Blynk app (1 or 0)

  if (blowerbutton == 1 && !countdownActive) {
    // If the blower is manually turned on from Blynk, start countdown
    countdownActive = true;
    startBlower();
  } else if (blowerbutton == 0) {
    stopBlower();  // Stop the blower if turned off in Blynk
  }
}

// Function to set the timer duration via Blynk app
BLYNK_WRITE(V2) {
  int timeSelected = param.asInt();  // Get selected time in minutes
  countdown = timeSelected * 60;  // Convert minutes to seconds
  if (countdown > 0) {
    countdownActive = true;
    startBlower();
    timer.setInterval(1000L, countdownFunction);  // Start countdown every second
  }
}

// Function to start the blower
void startBlower() {
  digitalWrite(RELAY_PIN, LOW);     // Turn blower ON
  digitalWrite(RED_LED_PIN, HIGH);  // Turn RED LED ON
  digitalWrite(GREEN_LED_PIN,