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

ESP32-Based Smart Weather Station with Wi-Fi and Battery Power

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Weather Station with Wi-Fi and Battery Power

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions using various sensors and an ESP32 microcontroller. The sensors include a temperature and humidity sensor, a barometric pressure sensor, a light sensor, a rain sensor, and a soil moisture sensor. The data collected from these sensors is processed by the ESP32 and sent to a server via WiFi. The circuit also includes a fan for ventilation, powered by a boost converter and a 18650 Li-ion battery.

Component List

  1. ESP32 (30 pin)

    • Description: 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. ENS160+AHT21

    • Description: Air quality sensor combined with a temperature and humidity sensor.
    • Pins: VIN, 3V3, GND, SCL, SDA, ADD, CS, INT
  3. BMP280

    • Description: Barometric pressure sensor.
    • Pins: SDO, CSB, SDA, SCL, GND, VCC
  4. BH1750

    • Description: Light intensity sensor.
    • Pins: VCC, GND, SCL, SDA, ADDR
  5. Fan

    • Description: Ventilation fan.
    • Pins: GND, 5V
  6. RAIN SENSOR

    • Description: Rain detection sensor.
    • Pins: AO, DO, GRD, VCC
  7. ESP32 - CAM

    • Description: ESP32 microcontroller with a camera module.
    • Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
  8. 18650 Li-ion Battery

    • Description: Rechargeable lithium-ion battery.
    • Pins: -, +
  9. SparkFun gator:soil

    • Description: Soil moisture sensor.
    • Pins: VCC, GND, SIG
  10. 5V Adapter

    • Description: Power adapter providing 5V output.
    • Pins: AC In 1, AC In 2, 5V, GND
  11. 5V 3A Li-ion Fast Charging Module

    • Description: Fast charging module for Li-ion batteries.
    • Pins: B-, B+, IN-, IN+, USB-C IN
  12. Boost Converter MT3608

    • Description: Boost converter to step up voltage.
    • Pins: OUTPUT +, OUTPUT -, INPUT +, INPUT -
  13. AC Supply

    • Description: AC power supply.
    • Pins: +ve, -ve

Wiring Details

ESP32 (30 pin)

ENS160+AHT21

BMP280

BH1750

Fan

RAIN SENSOR

ESP32 - CAM

18650 Li-ion Battery

SparkFun gator:soil

5V Adapter

5V 3A Li-ion Fast Charging Module

Boost Converter MT3608

AC Supply

Code Documentation

#include <WiFi.h>
#include <HTTPClient.h>
#include "SparkFun_ENS160.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include "DFRobot_AHT20.h"
#include <BH1750.h>
#include <Wire.h>

// WiFi Credentials
const char* ssid = "Mahir 2.4GHz";       // Replace with your SSID
const char* password = "01741238814";    // Replace with your password
const char* serverUrl = "http://192.168.0.187:3030/device1";

SparkFun_ENS160 myENS;
DFRobot_AHT20 aht20;
Adafruit_BMP280 bmp;
BH1750 lightMeter;
HTTPClient http;

// Shared data variables
float aqi, tvoc, co2, pressure, lux = 0;
int rain, ensStatus, temperature, humidity, soilMoisture = 0;

// FreeRTOS task handle for the WiFi task
TaskHandle_t wifiTaskHandle;

void setup() {
  Serial.begin(115200);
  
  // Initialize sensors
  initializeBmp();
  initializeEns();
  lightMeter.begin();
  aht20.begin();

  // Create WiFi and HTTP task on Core 0
  xTaskCreatePinnedToCore(
    wifiTask,        // Task function
    "WiFiTask",      // Task name
    4096,            // Stack size (bytes)
    NULL,            // Parameter
    1,               // Priority
    &wifiTaskHandle, // Task handle
    0                // Core 0
  );
}

void loop()