From 4eb2fcd6edec86a61269e737db09fbe7b25d07bc Mon Sep 17 00:00:00 2001 From: AlejandroJose2001 Date: Thu, 10 Apr 2025 16:18:14 +0200 Subject: [PATCH 1/3] Sensor MQ7 init and read --- hardware/include/MQ7.hpp | 35 +++++++++++++++++++++++++++++++++++ hardware/include/main.hpp | 1 + hardware/src/main.cpp | 4 +++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 hardware/include/MQ7.hpp diff --git a/hardware/include/MQ7.hpp b/hardware/include/MQ7.hpp new file mode 100644 index 0000000..1b875b1 --- /dev/null +++ b/hardware/include/MQ7.hpp @@ -0,0 +1,35 @@ +#include + +#define analogMQ7 33 +#define digitalMQ7 32 + +float sensor_volt; +float RS_air; +float R0; +float sensorValue; + +void MQ7_init(){ + pinMode(digitalMQ7, INPUT); + pinMode(analogMQ7, INPUT); +} + +void MQ7_read() +{ + analogWrite(analogMQ7, 1023); + delay(60000); + analogWrite(analogMQ7, (1023/5)*1.4 ); + + for(int i = 0; i<100; i++){ + sensorValue = sensorValue + analogRead(analogMQ7); + delay(90000); + } + + sensorValue = sensorValue/100.0; + sensor_volt = sensorValue/1024*5.0; + RS_air = (5.0-sensor_volt)/sensor_volt; + R0 = RS_air/(26+(1/3)); + + Serial.print("R0 = "); + Serial.println(R0); + delay(1000); +} \ No newline at end of file diff --git a/hardware/include/main.hpp b/hardware/include/main.hpp index 6d06a4a..df5dbd5 100644 --- a/hardware/include/main.hpp +++ b/hardware/include/main.hpp @@ -1,4 +1,5 @@ #include +#include #include "JsonTools.hpp" #include "RestClient.hpp" diff --git a/hardware/src/main.cpp b/hardware/src/main.cpp index fb27a34..cb6848c 100644 --- a/hardware/src/main.cpp +++ b/hardware/src/main.cpp @@ -22,11 +22,13 @@ void setup() { Serial.print("Error connecting to WiFi"); } + MQ7_init(); + // test get getRequest(httpClient, "http://172.20.10.7:8082/api/v1/sensors/1/values", response); deserializeSensorValue(httpClient, httpClient.GET()); } void loop() { - + MQ7_read(); } \ No newline at end of file From d83436a39506dc4fc039b8bfd0a9fc20318d0294 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Fri, 11 Apr 2025 09:12:30 +0200 Subject: [PATCH 2/3] Fixing files --- hardware/src/MQ7.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 hardware/src/MQ7.cpp diff --git a/hardware/src/MQ7.cpp b/hardware/src/MQ7.cpp new file mode 100644 index 0000000..2041d3d --- /dev/null +++ b/hardware/src/MQ7.cpp @@ -0,0 +1,26 @@ +#include "MQ7.hpp" + +void MQ7_init() { + pinMode(digitalMQ7, INPUT); + pinMode(analogMQ7, INPUT); +} + +void MQ7_read() { + analogWrite(analogMQ7, 1023); + delay(60000); + analogWrite(analogMQ7, (1023/5)*1.4 ); + + for(int i = 0; i<100; i++){ + sensorValue = sensorValue + analogRead(analogMQ7); + delay(90000); + } + + sensorValue = sensorValue/100.0; + sensor_volt = sensorValue/1024*5.0; + RS_air = (5.0-sensor_volt)/sensor_volt; + R0 = RS_air/(26+(1/3)); + + Serial.print("R0 = "); + Serial.println(R0); + delay(1000); +} \ No newline at end of file From 2ea77ee34bea785a384d1a9751a4104dd3465d84 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Fri, 11 Apr 2025 09:19:05 +0200 Subject: [PATCH 3/3] Refixing MQ7 --- hardware/include/MQ7.hpp | 33 ++------------------------------- hardware/include/main.hpp | 2 +- hardware/src/MQ7.cpp | 5 +++++ 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/hardware/include/MQ7.hpp b/hardware/include/MQ7.hpp index 1b875b1..c184b79 100644 --- a/hardware/include/MQ7.hpp +++ b/hardware/include/MQ7.hpp @@ -1,35 +1,6 @@ #include - #define analogMQ7 33 #define digitalMQ7 32 -float sensor_volt; -float RS_air; -float R0; -float sensorValue; - -void MQ7_init(){ - pinMode(digitalMQ7, INPUT); - pinMode(analogMQ7, INPUT); -} - -void MQ7_read() -{ - analogWrite(analogMQ7, 1023); - delay(60000); - analogWrite(analogMQ7, (1023/5)*1.4 ); - - for(int i = 0; i<100; i++){ - sensorValue = sensorValue + analogRead(analogMQ7); - delay(90000); - } - - sensorValue = sensorValue/100.0; - sensor_volt = sensorValue/1024*5.0; - RS_air = (5.0-sensor_volt)/sensor_volt; - R0 = RS_air/(26+(1/3)); - - Serial.print("R0 = "); - Serial.println(R0); - delay(1000); -} \ No newline at end of file +void MQ7_init(); +void MQ7_read(); \ No newline at end of file diff --git a/hardware/include/main.hpp b/hardware/include/main.hpp index df5dbd5..c1895ab 100644 --- a/hardware/include/main.hpp +++ b/hardware/include/main.hpp @@ -1,9 +1,9 @@ #include -#include #include "JsonTools.hpp" #include "RestClient.hpp" #include "WifiConnection.hpp" #include "MqttClient.hpp" +#include "MQ7.hpp" uint32_t getChipID(); \ No newline at end of file diff --git a/hardware/src/MQ7.cpp b/hardware/src/MQ7.cpp index 2041d3d..954b2cb 100644 --- a/hardware/src/MQ7.cpp +++ b/hardware/src/MQ7.cpp @@ -1,5 +1,10 @@ #include "MQ7.hpp" +float sensor_volt; +float RS_air; +float R0; +float sensorValue; + void MQ7_init() { pinMode(digitalMQ7, INPUT); pinMode(analogMQ7, INPUT);