Blynk 2.0 with MQ2 sensor

I’m trying to read a MQ2 sensor inside the Blynk 2.0 app.
not finding any examples for an ESP32.
Trying to convert a legacy example I found with no luck.
any input would be welcomed.

  Blynk.Edgent implements:
  - Blynk.Inject - Dynamic WiFi credentials provisioning
  - Blynk.Air    - Over The Air firmware updates
  - Device state indication using a physical LED
  - Credentials reset using a physical Button

/* Fill in information from your Blynk Template here */
/* Read more: */
//#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
//#define BLYNK_TEMPLATE_NAME         "Device"

#define BLYNK_TEMPLATE_ID "template ID"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG


#define MQ2 34         // pin for sensor
#define GREEN 16    // green led
#define RED 17         // red led
#define Blynk_Print Serial

int SensorValue = 0;
boolean state = false;

#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
#include "BlynkEdgent.h"

void sendUptime()
SensorValue = analogRead(MQ2);                  //reading sensor
Blynk.virtualWrite (V20, SensorValue);            // want it to send data to virtual pin 20
//if (SensorValue >800)

 //digitalWrite (GREEN,LOW);
 //digitalWrite (RED),HIGH);

// digitalWrite (GREEN ,HIGH);
 //digitalWrite (RED,LOW);

void setup()
pinMode (MQ2, INPUT);                               // sensor input
pinMode(GREEN, OUTPUT);                       // led out
pinMode (RED, OUTPUT);                           // led out
timer.setInterval(1000L, sendUptime);          // timer delay, will be adding others later


void loop() {;

void loop()

What is the actual problem? Sensor values not being read? Blynk not connecting, Blynk connecting but values not displayed in app? Other?

Need more info to help, plus read the guide on what info to include when creating a post.


Your code has two void loops!

What type of MQ2 sensor board are you using, and how have you wired it to your ESP32?

What purpose are you using the MQ2 for, what is it that you are trying to detect?


Yea, I guess stating what was not happening would help, sorry.
I am using a MQ2 sensor on a breadboard, if I run a non Blynk sketch, I can get readings in the serial monitor. So I know the Wiring is Ok.
When trying this sketch to get a smoke reading on the Blynk dashboard or app, the device makes connection. I have a Labeled Value, A Radial Gauge, along with Gauge all looking at v20 with no reading .
I running this on an ESP32 Wroom board.

Thank Bill S.

You’re missing; from your void loop, so the sendUptime function is never being called.