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

ESP32-Based Wi-Fi Controlled Weather Station with Humidity and Temperature Monitoring

View and Edit Project In Cirkit DesignerImage of ESP32-Based Wi-Fi Controlled Weather Station with Humidity and Temperature Monitoring

Circuit Documentation

Summary

This circuit is a weather station that uses an ESP32 microcontroller to monitor temperature and humidity, control a fan, a heat lamp, a humidifier, and a servo motor. The data is displayed on an I2C LCD and can be monitored remotely using the Blynk platform.

Component List

  1. ESP32 (30 pin)

    • Description: A powerful microcontroller with WiFi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  2. Fan

    • Description: A 5V fan used for cooling.
    • Pins: GND, 5V
  3. Lamp Red

    • Description: A red lamp used for heating.
    • Pins: +, -
  4. DHT22

    • Description: A digital temperature and humidity sensor.
    • Pins: GND, VCC, DAT
  5. Micro servo 9G

    • Description: A small servo motor used for mechanical movements.
    • Pins: GND, +5V, PWM
  6. Relevo 4 canales

    • Description: A 4-channel relay module used to control high-power devices.
    • Pins: JD-VCC, VCC2, K4-NO, K4-NF, K4-Com, K3-NO, K3-NF, K3-Com, K1-NO, K1-NF, K1-Com, K2-NO, K2-NF, K2-Com, IN4, VCC, IN2, IN3, GND, IN1
  7. Humidifier

    • Description: A device used to increase humidity.
    • Pins: GND, 5V
  8. 8v power supply

    • Description: A power supply providing 8V.
    • Pins: +, -
  9. I2C DISPLAY

    • Description: An I2C LCD display used to show temperature and humidity readings.
    • Pins: GND, VCC, SDL, SCL

Wiring Details

ESP32 (30 pin)

Fan

Lamp Red

DHT22

Micro servo 9G

Relevo 4 canales

Humidifier

8v power supply

I2C DISPLAY

Code Documentation

#define BLYNK_TEMPLATE_ID "TMPL6fHqpw3qd"
#define BLYNK_TEMPLATE_NAME "Weather Station"
#define BLYNK_AUTH_TOKEN "3owX8_PhttfxGCat11b_58uEVZm-BwTq"
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <Adafruit_Sensor.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <ESP32Servo.h>
#include <LiquidCrystal_I2C.h>

int lcdColumns = 16;
int lcdRows = 2;

// Blynk Authentication
char auth[] = "3owX8_PhttfxGCat11b_58uEVZm-BwTq";
char ssid[] = "Xaena wifi";  // WiFi SSID
char pass[] = "radha@123";   // WiFi Password
BlynkTimer timer;

// Define the DHT sensor pin and type
#define DHTPIN 13
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

#define RELAYPIN 14
#define RELAY_HEATLAMP 26
#define RELAY_FAN 27

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

// Define the Servo motor pin
#define SERVOPIN 12  // Connect the signal pin of the servo to GPIO5
Servo servo;

// Variable to track the last servo position to avoid redundant movements
int lastServoPosition = -1;

void setup() {
  // Start the Serial Monitor
  Serial.begin(921600);
  Serial.println("DHT22 Sensor Reading:");

  // Initialize Blynk, DHT, and Servo
   Blynk.begin(auth, ssid, pass);
  dht.begin();
  servo.attach(SERVOPIN);

  // Start with the window fully closed
  servo.write(0);
  lastServoPosition = 0;

  // Set a timer to send sensor data periodically
  timer.setInterval(1000L, sendSensor);

  pinMode(RELAYPIN, OUTPUT);
  digitalWrite(RELAYPIN, LOW);

  pinMode(RELAY_HEATLAMP, OUTPUT);
  digitalWrite(RELAY_HEATLAMP, LOW);

  pinMode(RELAY_FAN, OUTPUT);
  digitalWrite(RELAY_FAN, LOW);

  lcd.init();
  lcd.backlight();
}

void sendSensor() {
  // Read temperature (Celsius)
  float temperature = dht.readTemperature();

  // Read humidity
  float humidity = dht.readHumidity();

  // Check if the readings are valid
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Error: Failed to read from DHT sensor!");
    return;
  }

  // Print temperature and humidity to Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.println("---------------------------");

  // Send temperature and humidity to Blynk
  Blynk.virtualWrite(V0, temperature);
  Blynk.virtualWrite(V1, humidity);

  // Servo position logic
  int desiredServoPosition = 0; // Default to 0
  if (temperature > 25) {
    desiredServoPosition = 180;
    Serial.println("Servo at 180° (Temperature > 25°C)");
  } else if (temperature >= 20) {
    desiredServoPosition = 90;
    Serial.println("Servo at 90° (20°C <= Temperature <= 25°C)");
  } else {
    desiredServoPosition = 0;
    Serial.println("Servo at 0° (Temperature < 20°C)");
  }

  // Move the servo only if the position has changed
  if (desiredServoPosition