This shows you the differences between two versions of the page.
iothings:proiecte:2025sric:airquality [2025/05/28 21:59] ion_andrei.toader [Code Snippet] |
iothings:proiecte:2025sric:airquality [2025/05/28 22:29] (current) ion_andrei.toader [Web Application] |
||
---|---|---|---|
Line 150: | Line 150: | ||
====== Software Description ====== | ====== Software Description ====== | ||
- | The Air Sense Visualizer is a web application created to monitor and display air quality data in real time. It retrieves sensor readings—such as PPM values from an air quality sensor—and presents them through a clean, user-friendly interface. The application is designed for development and educational use, offering a simple way to test, view, and analyze environmental data either locally or through connection with cloud-based platforms. Its structure is modular and flexible, making it easy to adapt to different use cases and hardware setups. | + | The Air Quality is a web application created to monitor and display air quality data in real time. It retrieves sensor readings such as PPM values from an air quality sensor—and presents them through a clean, user-friendly interface. The application is designed for development and educational use, offering a simple way to test, view, and analyze environmental data either locally or through connection with cloud-based platforms. Its structure is modular and flexible, making it easy to adapt to different use cases and hardware setups. |
===== Code Snippet ===== | ===== Code Snippet ===== | ||
* Wi-Fi & Firebase Initialization | * Wi-Fi & Firebase Initialization | ||
+ | This part connects to Wi-Fi and initializes Firebase for anonymous sign-in and Realtime Database communication. | ||
<code> | <code> | ||
Line 192: | Line 193: | ||
} | } | ||
+ | </code> | ||
+ | |||
+ | * Sensor Reading & Conversion | ||
+ | Reads the analog value from the MQ-135 sensor, calculates Rs, and then converts that to a PPM (parts per million) estimate using a logarithmic formula. | ||
+ | |||
+ | <code> | ||
+ | #define MQ135_PIN 34 | ||
+ | #define RZERO 116404.0 | ||
+ | #define RL_VALUE 10000.0 | ||
+ | #define PARA 116.6020682 | ||
+ | #define PARB -2.769034857 | ||
+ | |||
+ | void loop() { | ||
+ | int adcValue = analogRead(MQ135_PIN); | ||
+ | float sensor_voltage = adcValue * (3.3 / 4095.0); | ||
+ | float rs = (3.3 - sensor_voltage) * RL_VALUE / sensor_voltage; | ||
+ | float ratio = rs / RZERO; | ||
+ | float ppm = PARA * pow(ratio, PARB); | ||
+ | } | ||
</code> | </code> | ||
+ | * Buzzer Alert Logic | ||
+ | Activates a buzzer if the air quality degrades beyond a certain threshold (800 PPM in this case). | ||
+ | |||
+ | <code> | ||
+ | #define BUZZER_PIN 25 | ||
+ | |||
+ | void setup() { | ||
+ | pinMode(BUZZER_PIN, OUTPUT); | ||
+ | digitalWrite(BUZZER_PIN, HIGH); // buzzer off | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // ... | ||
+ | if (ppm > 800) { | ||
+ | digitalWrite(BUZZER_PIN, LOW); // buzzer on | ||
+ | } else { | ||
+ | digitalWrite(BUZZER_PIN, HIGH); // buzzer off | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | * Sending Data to Firebase | ||
+ | Uploads the latest calculated PPM value to Firebase Realtime Database under the path /air_quality/ppm. | ||
+ | |||
+ | <code> | ||
+ | if (Firebase.RTDB.setFloat(&fbdo, "/air_quality/ppm", ppm)) { | ||
+ | Serial.println("Data sent to Firebase"); | ||
+ | } else { | ||
+ | Serial.print("Failed to send data: "); | ||
+ | Serial.println(fbdo.errorReason()); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | } | ||
+ | ===== Web Application ===== | ||
+ | |||
+ | {{ :iothings:proiecte:2025sric:web_app_2.png?direct&300 |}} | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | * [[https://www.instructables.com/Air-Quality-ESP32-Build-a-Portable-IoT-Sensor/]] | ||
+ | * [[https://www.hackster.io/dudelabweb/air-quality-monitoring-made-easy-an-iot-project-with-esp32-ee2777]] | ||
+ | * [[https://randomnerdtutorials.com/esp32-firebase-web-app/#install-vs-code]] | ||
+ | * [[https://randomnerdtutorials.com/getting-started-with-esp32/]] | ||
+ | * https://www.elprocus.com/mq135-air-quality-sensor/ |