For my IoT project, I'm creating a smoke and gas detector. Although I am using this mq2 library, it appears that the readTemperature member of the MQ2 class is missing. Can somebody help me to check the error?
void notification() {float t = mq2.readTemperature();
if (t > t_threshold && alert_sent == false) {digitalWrite(Green, HIGH);digitalWrite(Red, LOW);digitalWrite(Buzzer, LOW);Blynk.logEvent("gas_leak_detected", String("The temperature is ") +t); Serial.println("High temperature alert!");Serial.println("Blynk Alert Notification sent!");Serial.println();alert_sent = true;
`} else if (t <= t_threshold && alert_sent == true) {`
`Serial.println("Temperature back to normal");`
`Serial.println();`
`alert_sent = false;`
`}`
}
void loop() {Blynk.run();timer.run();}
This is the error:
C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino: In function 'void setup()':
C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino:27:3: error: 'mq2' was not declared in this scope
27 | mq2.begin();
| ^~~
C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino: In function 'void notification()':
C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino:42:13: error: 'mq2' was not declared in this scope
42 | float t = mq2.readTemperature();
| ^~~
exit status 1
Compilation error: 'mq2' was not declared in this scope
For my IoT project, I'm creating a smoke and gas detector. Although I am using this mq2 library, it appears that the readTemperature member of the MQ2 class is missing. Can somebody help me to check the error?
The code:
#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxx"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <MQ2.h>
char ssid[] = "xxxxxxxxxxxxxx";
char pass[] ="xxxxxxxxxxxxxx";
BlynkTimer timer;
int pinValue = 0;
#define Buzzer D5
#define Green D6
#define Red D7
#define MQ2PIN A0
float t_threshold = 50.00;
bool alert_sent = false;
void setup() {
Serial.begin(9600);
mq2.begin();
pinMode(Green, OUTPUT);
pinMode(Red, OUTPUT);
pinMode(Buzzer, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, notification);
}
BLYNK_WRITE(V0) {
pinValue = param.asInt();
}
void notification() {
float t = mq2.readTemperature();
if (t > t_threshold && alert_sent == false) {
digitalWrite(Green, HIGH);
digitalWrite(Red, LOW);
digitalWrite(Buzzer, LOW);
Blynk.logEvent("gas_leak_detected", String("The temperature is ") +t);
Serial.println("High temperature alert!");
Serial.println("Blynk Alert Notification sent!");
Serial.println();
alert_sent = true;
}
void loop() {
Blynk.run();
timer.run();
}
This is the error:
C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino: In function 'void setup()': C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino:27:3: error: 'mq2' was not declared in this scope 27 | mq2.begin(); | ^~~ C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino: In function 'void notification()': C:\Users\User\OneDrive\Documents\Arduino\coding-2\coding-2\coding-2.ino:42:13: error: 'mq2' was not declared in this scope 42 | float t = mq2.readTemperature(); | ^~~
exit status 1
Compilation error: 'mq2' was not declared in this scope