Circuit Documentation
Summary
This document provides a detailed overview of a beehive monitoring system circuit. The system utilizes an ESP32 microcontroller to interface with various sensors and modules, including a DHT22 temperature and humidity sensor, an MQ135 air quality sensor, an SW-420 vibration sensor, an HX711 load cell interface, and a buzzer module. The system is powered by a 18650 Li-ion battery managed by a TP4056 charging module.
Component List
ESP32 (30 pin)
- Description: A powerful microcontroller with built-in Wi-Fi 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
18650 Li-ion Battery
- Description: A rechargeable lithium-ion battery.
- Pins: -, +
TP4056
- Description: A lithium battery charger module with overcharge protection.
- Pins: OUT-, B-, B+, OUT+, IN-, IN+
SW-420 Vibration Sensor
- Description: A vibration sensor module that detects vibrations and outputs a digital signal.
- Pins: vcc, Ground, Digital output
DHT22
- Description: A temperature and humidity sensor.
- Pins: GND, VCC, DAT
MQ135
- Description: An air quality sensor that measures the concentration of various gases.
- Pins: VCC, GND, A0, D0
Buzzer Module
- Description: A simple buzzer module for audio alerts.
- Pins: GND, Vcc, I/O
HX711 - Bridge Sensor Interface
- Description: An interface module for load cells.
- Pins: E+, E-, A-, A+, B-, B+, GND - GROUND, DATA (OUT), SCK - CLOCK (IN), 3.3/3.5V Supply
Load Cell - Red/white/black/green
- Description: A load cell for measuring weight.
- Pins: E+, A-, E-, A+
Wiring Details
ESP32 (30 pin)
- D32 connected to MQ135 A0
- GND connected to:
- DHT22 GND
- Buzzer Module GND
- SW-420 Vibration Sensor Ground
- MQ135 GND
- HX711 - Bridge Sensor Interface GND - GROUND
- TP4056 OUT-
- Vin connected to TP4056 OUT+
- D23 connected to Buzzer Module I/O
- D19 connected to HX711 - Bridge Sensor Interface SCK - CLOCK (IN)
- D18 connected to HX711 - Bridge Sensor Interface DATA (OUT)
- D5 connected to SW-420 Vibration Sensor Digital output
- D4 connected to DHT22 DAT
- 3V3 connected to:
- DHT22 VCC
- Buzzer Module Vcc
- SW-420 Vibration Sensor vcc
- MQ135 VCC
- HX711 - Bridge Sensor Interface 3.3/3.5V Supply
18650 Li-ion Battery
- - connected to TP4056 B-
- + connected to TP4056 B+
TP4056
- OUT- connected to ESP32 GND
- OUT+ connected to ESP32 Vin
- B- connected to 18650 Li-ion Battery -
- B+ connected to 18650 Li-ion Battery +
SW-420 Vibration Sensor
- vcc connected to ESP32 3V3
- Ground connected to ESP32 GND
- Digital output connected to ESP32 D5
DHT22
- GND connected to ESP32 GND
- VCC connected to ESP32 3V3
- DAT connected to ESP32 D4
MQ135
- VCC connected to ESP32 3V3
- GND connected to ESP32 GND
- A0 connected to ESP32 D32
Buzzer Module
- GND connected to ESP32 GND
- Vcc connected to ESP32 3V3
- I/O connected to ESP32 D23
HX711 - Bridge Sensor Interface
- E+ connected to Load Cell E+
- E- connected to Load Cell E-
- A- connected to Load Cell A+
- A+ connected to Load Cell A-
- GND - GROUND connected to ESP32 GND
- DATA (OUT) connected to ESP32 D18
- SCK - CLOCK (IN) connected to ESP32 D19
- 3.3/3.5V Supply connected to ESP32 3V3
Load Cell - Red/white/black/green
- E+ connected to HX711 - Bridge Sensor Interface E+
- E- connected to HX711 - Bridge Sensor Interface E-
- A+ connected to HX711 - Bridge Sensor Interface A-
- A- connected to HX711 - Bridge Sensor Interface A+
Code Documentation
ESP32 Code
#include "HX711.h" // HX711 library for load cell
#include "DHT.h" // DHT sensor library
// --- Pin Definitions ---
// DHT22 Sensor
#define DHTPIN 4 // GPIO 4 for DHT22
#define DHTTYPE DHT22 // Define the type of DHT sensor
// HX711 Load Cell
#define HX711_DT 21 // GPIO 21 for DT (DOUT) of HX711
#define HX711_SCK 22 // GPIO 22 for SCK (CLK) of HX711
// MQ135 Air Quality Sensor
#define MQ135_PIN A0 // Analog pin A0 for MQ135
// SW-420 Vibration Sensor
#define VIBRATION_PIN 5 // GPIO 5 for vibration sensor output
// Buzzer
#define BUZZER_PIN 23 // GPIO 23 for buzzer control
// --- Sensor Objects ---
HX711 scale; // Initialize HX711
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor
// --- Threshold Values ---
float weightThreshold = 50.0; // Example weight threshold in kg
float tempThreshold = 35.0; // Temperature threshold in °C
float humidityThreshold = 70.0; // Humidity threshold in %
int airQualityThreshold = 300; // Air quality threshold (arbitrary ADC value)
// --- Setup Function ---
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize DHT sensor
dht.begin();
// Initialize HX711 load cell
scale.begin(HX711_DT, HX711_SCK);
scale.set_scale(); // Calibrate your load cell and set the scale factor here
scale.tare(); // Reset scale to zero
// Initialize pins
pinMode(VIBRATION_PIN, INPUT); // Vibration sensor as input
pinMode(BUZZER_PIN, OUTPUT); // Buzzer as output
// Ready message
Serial.println("Beehive Monitoring System Initialized!");
}
// --- Loop Function ---
void loop() {
// --- Read DHT22 Sensor Data ---
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT22 sensor!");
} else {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
// --- Read Load Cell Data ---
float weight = 0.0;
if (scale.is_ready()) {
weight = scale.get_units(10); // Average of 10 readings
Serial.print("Weight: ");
Serial.print(weight);
Serial.println(" kg");
} else {
Serial.println("HX711 not ready");
}
// --- Read MQ135 Air Quality Sensor ---
int airQuality = analogRead(MQ135_PIN);
Serial.print("Air Quality: ");
Serial.println(airQuality);
// --- Read Vibration Sensor ---
int vibration = digitalRead(VIBRATION_PIN);
Serial.print("Vibration Detected: ");
Serial.println(vibration == HIGH ? "Yes" : "No");
// --- Trigger Buzzer on Threshold Breach ---
if (temperature > tempThreshold ||
