Hello, I have a problem with my project. I am totally new in Blynk. I’ve spent hours trying to understand the code for Blynk and so on.
My problem is my sensor reading stuck at “0” when I write “Blynk.begin(auth, ssid, pass);” inside void setup()
and when I wite “Blynk.run” inside the void loop()
However, when I mark “//” these two lines, the sensor reads the data like usual. Need help!
Another details
- I’m using ESP32 Dev Module, 38pins
- Smartphone: Samsung A32 5G, android 13.
- Blynk version (coped from Serial Monitor): v1.2.0 on ESP32
- Blynk library: Blynk by Volodymyr Shymanskyy 1.2.0
#define BLYNK_TEMPLATE_NAME "HUHA2"
#define BLYNK_AUTH_TOKEN "psznFo-_IrkwEgGGmUgb1LtTwhoEtJx_"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "お前はだれ";
char pass[] = "olio26222";
#define Threshold 400
int MQ2pin = 4;
int sensorValue;
void myTimerEvent() {
sensorValue = analogRead(MQ2pin);
Blynk.virtualWrite(V0, sensorValue);
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
if (sensorValue > Threshold) {
Serial.print(" | Smoke detected!");
Blynk.logEvent("gas_alert","Gas Leakage Detected");
}
Serial.println("");
delay(500);
}
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(MQ2pin, INPUT);
Serial.println("MQ2 warming up!");
timer.setInterval(500L, myTimerEvent);
delay(3000);
}
void loop() {
Blynk.run();
timer.run();
}