Education in Bangladesh faces an invisible enemy: poor classroom environments. High temperatures, rising humidity, and elevated CO2 levels directly impact a student's cognitive function, leading to fatigue and reduced attention spans. At Virtual Science Club Bangladesh (VSC.BD), we decided to tackle this issue not with assumptions, but with hard, real-time data.
Welcome to the engineering log of the Smart Classroom Environment Monitor. This project leverages the Internet of Things (IoT) to continuously track temperature, humidity, air quality, and noise levels, streaming the data to a live cloud dashboard. Let’s break down the architecture of this digital nervous system.
1. The System Architecture: From Physical to Digital
An IoT system consists of three main layers: Perception (Sensors), Network (Microcontroller & Wi-Fi), and Application (Cloud & Dashboard). We needed a system that was robust, low-power, and capable of handling continuous data streams without crashing.
// LOGICAL_ENGINEERING_NOTE
A common mistake in IoT is using the Arduino Uno with an ESP8266 Wi-Fi module attached. This creates a bottleneck. True logical engineering demands efficiency. By using the ESP32, we utilize a dual-core processor with built-in Wi-Fi and Bluetooth, drastically reducing circuit complexity and power consumption.
2. Hardware Selection & Calibration
Selecting the right sensors is critical. Cheap sensors provide noisy data, which renders the entire system useless. Here is our carefully curated hardware stack:
- The Core (ESP32): The brains of the operation. Running at 240MHz, it has plenty of processing power to read analog sensors, format data into JSON, and maintain a secure SSL connection with the cloud.
- Temperature & Humidity (DHT22): We opted for the DHT22 over the cheaper DHT11 because it offers a wider range and higher precision (±0.5°C vs ±2°C).
- Air Quality / CO2 Proxy (MQ-135): This analog gas sensor is highly sensitive to Ammonia, Sulfide, Benzene, and CO2. Crucial Note: The MQ-135 requires a 24-hour "burn-in" or pre-heating phase to provide stable readings. We implemented a calibration algorithm in our code to map the analog values to approximate PPM (Parts Per Million).
- Noise Level (MAX4466): A high-quality microphone amplifier with adjustable gain. We use it to monitor decibel levels, allowing administrators to identify excessively disruptive environments.
3. Cloud Integration: Why Firebase?
We needed a database that could update our web dashboard instantly without the user having to refresh the page. Traditional SQL databases are too slow and rigid for this. We chose Google Firebase Realtime Database (NoSQL).
Firebase stores data as a massive JSON tree. When the ESP32 pushes a new temperature value to the database, Firebase immediately synchronizes that change across all connected clients (the teachers' laptops or principals' phones) within milliseconds.
4. The Firmware (Non-Blocking C++ Code)
One of the biggest flaws in amateur Arduino programming is the use of the delay() function. If you use delay(5000) to wait 5 seconds between database uploads, the microcontroller is completely frozen for those 5 seconds. It cannot read the noise sensor or respond to emergencies.
We implemented non-blocking code using the millis() function. This allows the ESP32 to multitask—continuously sampling the noise level while periodically uploading to Firebase.
// Connecting ESP32 to Firebase using non-blocking logic
#include <WiFi.h>
#include <FirebaseESP32.h>
#include "DHT.h"
#define WIFI_SSID "VSC_Network"
#define WIFI_PASSWORD "LogicalMindsOnly"
#define FIREBASE_HOST "vsc-classroom-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "Your_Database_Secret"
FirebaseData fbdo;
unsigned long previousMillis = 0;
const long interval = 10000; // Upload every 10 seconds
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
// Awaiting connection without hard delay loops if possible
delay(500);
}
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
}
void loop() {
unsigned long currentMillis = millis();
// 1. Continuous task: Monitor sharp noise spikes constantly
checkNoiseLevel();
// 2. Periodic task: Upload data every 10 seconds without freezing
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
float temp = dht.readTemperature();
int airQuality = analogRead(MQ135_PIN);
if (Firebase.setFloat(fbdo, "/Classroom_A/Temperature", temp)) {
Serial.println("Temp Uploaded.");
}
Firebase.setInt(fbdo, "/Classroom_A/AirQuality", airQuality);
}
}
5. Real-World Application & Future Roadmap
By deploying this system in test classrooms, the data revealed clear patterns. At 1:00 PM, CO2 levels spiked significantly, correlating directly with reported student drowsiness. By simply scheduling a 5-minute cross-ventilation window, cognitive engagement noticeably improved.
The Next Step: Monitoring is only phase one. Phase two is Automation. We are currently updating the firmware to allow the ESP32 to trigger relay modules. If the MQ-135 sensor detects CO2 levels crossing 1000 PPM, the system will autonomously activate the classroom's exhaust fans. This transforms the project from a passive monitor into an active environment control system.
At VSC.BD, we build systems that solve real problems. Data without action is just noise.