This shows you the differences between two versions of the page.
|
iothings:proiecte:2025sric:windowopener [2025/04/23 13:41] matei.neaga [Hardware] |
iothings:proiecte:2025sric:windowopener [2025/05/18 18:18] (current) matei.neaga [Window opener, based on gas detection] |
||
|---|---|---|---|
| Line 11: | Line 11: | ||
| ====== Context ====== | ====== 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 |}} | ||
| Line 24: | Line 31: | ||
| Code snippets | Code snippets | ||
| + | <code cpp> | ||
| #include <WiFi.h> | #include <WiFi.h> | ||
| #include <WebServer.h> | #include <WebServer.h> | ||
| Line 30: | Line 38: | ||
| const char* ssid = ""; | const char* ssid = ""; | ||
| const char* password = ""; | const char* password = ""; | ||
| - | |||
| #define ANALOG_PIN 34 // Pinul conectat la AO al senzorului MQ-4 | #define ANALOG_PIN 34 // Pinul conectat la AO al senzorului MQ-4 | ||
| Line 41: | Line 48: | ||
| bool modAutomat = true; | bool modAutomat = true; | ||
| int pragActivare = 800; | int pragActivare = 800; | ||
| - | |||
| Servo myservo; | 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 ====== | ====== Challenges ====== | ||