ESP32-Based Smart Weather Station with Wi-Fi and Battery Power
View and Edit Project In Cirkit Designer
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
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
ENS160+AHT21
- Description: Air quality sensor combined with a temperature and humidity sensor.
- Pins: VIN, 3V3, GND, SCL, SDA, ADD, CS, INT
BMP280
- Description: Barometric pressure sensor.
- Pins: SDO, CSB, SDA, SCL, GND, VCC
BH1750
- Description: Light intensity sensor.
- Pins: VCC, GND, SCL, SDA, ADDR
Fan
- Description: Ventilation fan.
- Pins: GND, 5V
RAIN SENSOR
- Description: Rain detection sensor.
- Pins: AO, DO, GRD, VCC
ESP32 - CAM
- Description: ESP32 microcontroller with a camera module.
- Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
18650 Li-ion Battery
- Description: Rechargeable lithium-ion battery.
- Pins: -, +
SparkFun gator:soil
- Description: Soil moisture sensor.
- Pins: VCC, GND, SIG
5V Adapter
- Description: Power adapter providing 5V output.
- Pins: AC In 1, AC In 2, 5V, GND
5V 3A Li-ion Fast Charging Module
- Description: Fast charging module for Li-ion batteries.
- Pins: B-, B+, IN-, IN+, USB-C IN
Boost Converter MT3608
- Description: Boost converter to step up voltage.
- Pins: OUTPUT +, OUTPUT -, INPUT +, INPUT -
AC Supply
- Description: AC power supply.
- Pins: +ve, -ve
Wiring Details
ESP32 (30 pin)
- D35 connected to RAIN SENSOR AO
- D33 connected to SparkFun gator:soil SIG
- GND connected to:
- BMP280 GND
- Fan GND
- Boost Converter MT3608 OUTPUT -
- BH1750 GND
- RAIN SENSOR GRD
- ESP32 - CAM GND
- SparkFun gator:soil GND
- ENS160+AHT21 GND
- Vin connected to:
- Fan 5V
- Boost Converter MT3608 OUTPUT +
- SparkFun gator:soil VCC
- ESP32 - CAM 5V
- ENS160+AHT21 VIN
- D22 connected to:
- BMP280 SCL
- BH1750 SCL
- ENS160+AHT21 SCL
- D21 connected to:
- BMP280 SDA
- BH1750 SDA
- ENS160+AHT21 SDA
- 3V3 connected to:
- BMP280 VCC
- BH1750 VCC
- RAIN SENSOR VCC
ENS160+AHT21
- VIN connected to ESP32 Vin
- GND connected to ESP32 GND
- SCL connected to ESP32 D22
- SDA connected to ESP32 D21
BMP280
- GND connected to ESP32 GND
- SCL connected to ESP32 D22
- SDA connected to ESP32 D21
- VCC connected to ESP32 3V3
BH1750
- GND connected to ESP32 GND
- SCL connected to ESP32 D22
- SDA connected to ESP32 D21
- VCC connected to ESP32 3V3
Fan
- GND connected to ESP32 GND
- 5V connected to ESP32 Vin
RAIN SENSOR
- AO connected to ESP32 D35
- GRD connected to ESP32 GND
- VCC connected to ESP32 3V3
ESP32 - CAM
- GND connected to ESP32 GND
- 5V connected to ESP32 Vin
18650 Li-ion Battery
- - connected to:
- Boost Converter MT3608 INPUT -
- 5V 3A Li-ion Fast Charging Module B-
- + connected to:
- Boost Converter MT3608 INPUT +
- 5V 3A Li-ion Fast Charging Module B+
SparkFun gator:soil
- SIG connected to ESP32 D33
- GND connected to ESP32 GND
- VCC connected to ESP32 Vin
5V Adapter
- AC In 1 connected to AC Supply -ve
- AC In 2 connected to AC Supply +ve
- 5V connected to 5V 3A Li-ion Fast Charging Module IN+
- GND connected to 5V 3A Li-ion Fast Charging Module IN-
5V 3A Li-ion Fast Charging Module
- IN+ connected to 5V Adapter 5V
- IN- connected to 5V Adapter GND
- B- connected to:
- Boost Converter MT3608 INPUT -
- 18650 Li-ion Battery -
- B+ connected to:
- Boost Converter MT3608 INPUT +
- 18650 Li-ion Battery +
Boost Converter MT3608
- OUTPUT - connected to ESP32 GND
- OUTPUT + connected to ESP32 Vin
- INPUT - connected to:
- 5V 3A Li-ion Fast Charging Module B-
- 18650 Li-ion Battery -
- INPUT + connected to:
- 5V 3A Li-ion Fast Charging Module B+
- 18650 Li-ion Battery +
AC Supply
- -ve connected to 5V Adapter AC In 1
- +ve connected to 5V Adapter AC In 2
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()