BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Problem analog to virtual pin


#1

Good morning,

I state that it is only recently that I entered the world of Blynk so I apologize if I ask stupid questions. I have Arduino one, Esp8266 and a sensor Mq-2. I would like to see the value of the gas in my house through Blynk, but I do not understand the values ​​that Blynk shows me since these values ​​never change (tested with the lighter). The links I made are:

Arduino connected to the pc
Esp8266:
Tx -> Tx Arduino (digital 1)
Rx -> Rx Arduino (digital 0)
Gnd -> Gnd
GPIO 0 -> Gnd
Vcc -> 3.3v
CH_PD -> 3.3v
GPIO2 -> Breadboard (LED)
RTD -> Nothing
Mq-2 sensor:
Vcc -> 5v
Gnd -> Gnd
A0 -> A0 (analogic)

I used the function of virtual pins but the values ​​I see on Blynk do not vary with the presence of the gas.

This is the sketch:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int gas = A0;
int smoke;
char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";
BLYNK_READ(V5)
{
smoke = analogRead(gas);
  Blynk.virtualWrite(V5,smoke);
  Serial.println(smoke);
}
void setup()
{  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
   pinMode(gas,INPUT);
}
void loop()
{
  Blynk.run();
}

Let me know where is that wrong? Thank you all for your help and patience.


#2

Hello and Welcome.

First I edited your post to properly format the posted code are per the Welcome Topic that you may have missed?

As for your setup… It doesn’t make sense to me… are you using an Arduino (what type) with an ESP (what type) as a shield? Or are you running the ESP as standalone as your Sketch libraries indicate?

Also these pinouts just don’t make sense… they show as if you are using an ESP (possibly ESP-01) as a shield, but your connections are all wrong. e.g. GPIO0->GND puts the ESP into flash mode, good for loading in your sketch, but must be floating or HIGH for starting the sketch - and this is assuming running in Standalone mode (no Arduino).

And then, now assuming ESP as shield, why is your ESP’s RX->RX on Arduino’s programming port, as is the TX.TX? Normally it would be RX->TX and TX->RX, but NOT using the programming ports, instead using Software Serial ports… then you program the Arduino (with proper libraries), not the ESP, as the ESP just becomes a simple Serial to WiFi adapter (GPIO0 unused).

I think you need to clarify what you are trying to connect and how…

Check out these documents for both ESP modes…

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-standalone

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware


#3

I think you’d find it beneficial to use the sketch builder to generate some Blynk code then work through that code to understand how it works. You should pay attention to how timers work, and how the timer is called in the void loop.

You’ll need a timed loop that checks the reading from your sensor at a sensible frequency (every 5 seconds maybe - check the specs on your device to see how long it takes to obtain a reading and what the suggested frequency of readings is).
Once you have that data, and you can see that it’s being output to your serial monitor, you’ll be able to push it to Blynk so that it can be displayed on a widget in your app.

Pete.


#4

Thanks for the answers. Is it possible to have an example of how I should connect esp-01 and the mq-2 sensor? Can you give me an example of a sketch on how I should use serial port knowing I need analog port 0? I hope I’m not too rude but I think your example would help me a lot. Thank you


#5

You don’t have any available analog ports on an ESP-01, so you might still be best suited as using it as a shield for the Arduino, as per that 2nd link I provided above (ESP with AT firmware).


#6

Good morning,

I state that it is only recently that I entered the world of Blynk so I apologize if I ask stupid questions. I have Arduino one, Esp-01 and a sensor Mq-2. I would like to see the value of the gas in my house through Blynk, but I do not understand the values ​​that Blynk shows me since these values ​​never change (tested with the lighter). The links I made are:

Arduino connected to the pc
Esp8266-01:
Tx -> Tx Arduino (digital 1)
Rx -> Rx Arduino (digital 0)
Gnd -> Gnd
GPIO 0 -> Gnd
Vcc -> 3.3v
CH_PD -> 3.3v
GPIO2 -> Breadboard (LED)
RTD -> Nothing
Mq-2 sensor:
Vcc -> 5v
Gnd -> Gnd
A0 -> A0 (analogic)

I used the function of virtual pins but the values ​​I see on Blynk do not vary with the presence of the gas.

This is the sketch:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int gas = A0;
int smoke;
char auth[] = “xxx”;
char ssid[] = “xxx”;
char pass[] = “xxx”;
BLYNK_READ(V5)
{
smoke = analogRead(gas);
Blynk.virtualWrite(V5,smoke);
Serial.println(smoke);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(gas,INPUT);
}
void loop()
{
Blynk.run();
}

you tell me where am I wrong?
Thank you all for your help and patience.


#7

You’ve already posted this here under a different title:


and we’ve had several PM discussions about the best way to connect this sensor to a NodeMCU device.

I’m not sure what you expect to achieve by re-posting this?

Pete.


#8

Merged it with original post