Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error: 'mq2' was not declared in this scope #10

Open
nisanisa22 opened this issue Mar 4, 2023 · 1 comment
Open

Compilation error: 'mq2' was not declared in this scope #10

nisanisa22 opened this issue Mar 4, 2023 · 1 comment

Comments

@nisanisa22
Copy link

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;

`} 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

@labay11
Copy link
Owner

labay11 commented Apr 17, 2023

You need to define the mq2 variable before setup: MQ2 mq2(MQ2PIN);.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants