Connecting to blynk.cloud:80 -esp8266

Sorry, i don’t really understand. I think i already add a line of code after which is

 } else if (smoke <= smoke_threshold && alert_sent == true) {
 Serial.println("Temperature back to normal");
 Serial.println();
 alert_sent = false;

How does that show you, in the serial monitor, what the value of smoke is?

Pete.

Yes.
I try to use this

float t = mq2.readTemperature();

But it appears that the readTemperature member of the MQ2 class is missing. So i think i could not use it. Should i use float lpg = mq2.readLPG(); instead?

The serial monitor shows nothing just can connect to the wifi and blynk

That’s because you haven’t done this…

Pete.

I’d suggest that you read the specification sheet for the MQ-2 sensor. It’s a combustible gas sensor and has no temperature sensing capabilities.

Pete.

I forgot to add line of code after that. Sorry, my mistake. Instead of using MQ2, I switched back to sensor.

This is the code:

#define BLYNK_TEMPLATE_ID "xxxxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxx"

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[] = "xxxxxxxxxxx";
char pass[] = "xxxxxxxxxxx";

BlynkTimer timer;
int pinValue = 0;

#define Buzzer D5
#define Green D6
#define Red D7
#define Sensor A0

int sensor_threshold = 50;
bool alert_sent = false;

void setup() {
 Serial.begin(9600);
 pinMode(Green, OUTPUT);
 pinMode(Red, OUTPUT);
 pinMode(Buzzer, OUTPUT);
 pinMode(Sensor, INPUT);
 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 timer.setInterval(1000L, notification);
 }

BLYNK_WRITE(V0) {
 pinValue = param.asInt();
}

void notification() {
 int sensor = analogRead(Sensor);
 Serial.print("Temperature    = ");
 Serial.println(sensor);
 Serial.println();
 Blynk.virtualWrite(V1, sensor);

  if (sensor > sensor_threshold && alert_sent == false) {
   digitalWrite(Green, HIGH);
   digitalWrite(Red, LOW);
   digitalWrite(Buzzer, LOW);
   Blynk.logEvent("gas_leak_detected",  String("The temperature is ") + Sensor);
   Serial.println("High temperature alert!");
   Serial.println("Blynk Alert Notification sent!");
   Serial.println();
   alert_sent = true;

    } else if (sensor <= sensor_threshold && alert_sent == true) {
      Serial.println("Temperature back to normal");
      Serial.println();
      alert_sent = false;
     }
}

void loop() {
 Blynk.run();
 timer.run();
}

I assume it is already functional. It appears to already be capable of detecting the gas value.

I think that’s probably the wrong approach.

Pete.

Because I use this website’s code. It uses a sensor.

That project is being used to detect the butane from a unlit cigarette lighter.
You seem to be confused about whether you’re trying to detect smoke particles or temperature, and as I’ve already pointed-out the MQ-2 has no temperature sensing capabilities.

Pete.