This shows you the differences between two versions of the page.
iothings:proiecte:2025sric:windowopener [2025/04/22 22:22] matei.neaga |
iothings:proiecte:2025sric:windowopener [2025/05/18 18:18] (current) matei.neaga [Window opener, based on gas detection] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Window opener, based on gas detection | + | ====== Window opener, based on gas detection ====== |
* Author: Neaga Matei | * Author: Neaga Matei | ||
* Email: mateineaga@outlook.com, matei.neaga@stud.mec.upb.ro | * Email: mateineaga@outlook.com, matei.neaga@stud.mec.upb.ro | ||
* Master: IA | * Master: IA | ||
+ | |||
+ | ====== Introduction ====== | ||
+ | |||
+ | This project aims to build a setup based on a servomechanism and a sensor MQ-5, with the purpose of opening a window in case the gas concentration rises above a desired value. | ||
+ | |||
+ | ====== Context ====== | ||
+ | |||
+ | Block diagram of the project | ||
+ | |||
+ | {{ :iothings:proiecte:2025sric:block-diagram-neaga-matei.png |}} | ||
+ | |||
+ | Flowchart of the project | ||
+ | |||
+ | {{ :iothings:proiecte:2025sric:flowchart-neaga-matei.png |}} | ||
+ | |||
+ | |||
+ | ====== Hardware ====== | ||
+ | * ESP32 board | ||
+ | * MQ-4 sensor, detecting SnO2 | ||
+ | * SG90 servomechanism | ||
+ | * microusb - usb A cable | ||
+ | * dupont cables | ||
+ | |||
+ | ====== Software ====== | ||
+ | |||
+ | Code snippets | ||
+ | |||
+ | <code cpp> | ||
+ | #include <WiFi.h> | ||
+ | #include <WebServer.h> | ||
+ | #include <ESP32Servo.h> | ||
+ | |||
+ | const char* ssid = ""; | ||
+ | const char* password = ""; | ||
+ | |||
+ | #define ANALOG_PIN 34 // Pinul conectat la AO al senzorului MQ-4 | ||
+ | #define SERVO_PIN 13 // Pinul conectat la servomotor | ||
+ | |||
+ | int valoare_analogica = 0; | ||
+ | String nivelGaz = ""; | ||
+ | String culoareNivel = "green"; | ||
+ | bool servoActiv = false; | ||
+ | bool modAutomat = true; | ||
+ | int pragActivare = 800; | ||
+ | |||
+ | Servo myservo; | ||
+ | </code> | ||
+ | |||
+ | <code cpp> | ||
+ | void loop() { | ||
+ | server.handleClient(); | ||
+ | | ||
+ | | ||
+ | valoare_analogica = analogRead(ANALOG_PIN); | ||
+ | | ||
+ | | ||
+ | if (modAutomat) { | ||
+ | if (valoare_analogica >= pragActivare && !servoActiv) { | ||
+ | activeazaServo(); | ||
+ | } else if (valoare_analogica < pragActivare && servoActiv) { | ||
+ | dezactiveazaServo(); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | delay(100); | ||
+ | } | ||
+ | |||
+ | // Funcție pentru activarea servomotorului | ||
+ | void activeazaServo() { | ||
+ | myservo.write(90); | ||
+ | servoActiv = true; | ||
+ | Serial.println("Servo activat!"); | ||
+ | } | ||
+ | |||
+ | // Funcție pentru dezactivarea servomotorului | ||
+ | void dezactiveazaServo() { | ||
+ | myservo.write(0); | ||
+ | servoActiv = false; | ||
+ | Serial.println("Servo dezactivat!"); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ====== Challenges ====== | ||
+ | |||
+ | Figuring out a way to design the webpage to allow me to switch the servomechanism to "automated" or "manual" mode. | ||
+ | |||
+ | ====== References ====== | ||
+ | |||
+ | - |