MQ2 sensor readings

Hi all,

i have had someone code my ESp32 board with a MQ2 sensor to send an alert to an APK notification.
the issue i have is i keep getting the reading sensor value is 4095 as below

20:07:34.631 -> mq2 value is : 4095
20:07:36.767 -> mq2 value is : 4095

i know this isnt the correct reading, and when i use LPG gas near the senor the LED lights up, but the sensor readings dont change

A0 is connected to D4 on the ESP32

#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>
int smokeA0 = 4;
int sensorThres = 400;
#define FIREBASE_HOST "notificaton-ffcda.firebaseio.com/"
#define FIREBASE_AUTH "........."
#define WIFI_SSID "The only wifi"
#define WIFI_PASSWORD "########"

void setup() {
pinMode(smokeA0, INPUT);
Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

}

void loop() {

int analogSensor = analogRead(smokeA0);
Firebase.setFloat("Device/data",analogSensor);
Serial.print("mq2 value is : ");
Serial.println(analogSensor);

delay(100);
}

this is my first post, so if ive left anything out, please let me know

thank you in advance

Please use code tags when posting, as described in the "How to use this forum" post.

Please post a link to the product page for the exact module you are using.

Post a wiring diagram (hand drawn, not Fritzing). Did you connect the grounds?

Describe how you are powering the sensor.

Did you follow the directions in the data sheet and "burn in" or preheat for more than 48 hours?

TOPIC MERGED.

You may want to READ THIS for future reference.
It will help you get the best out of the forum.

Bob.

Hi Jremington

Thank you for the advice .
See attached wiring

Yes i have let the sensor burn for over 48 hours
ESp32 is powered by USB to a laptop
Sensor is powered by USB to a laptop as well, but on a separate port.

link for board HKD ESP-32 WIFI B/T DEV BOARD - Communica [Part No: HKD ESP-32 WIFI B/T DEV BOARD]

[#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>
int smokeA0 = 4;
int sensorThres = 400;
#define FIREBASE_HOST "notificaton-ffcda.firebaseio.com/"
#define FIREBASE_AUTH "YKh5eHVFVr8RbS64aLTHSfJHJ6qtVPSuKWzTNIDX"
#define WIFI_SSID "The only wifi"
#define WIFI_PASSWORD "Ad.Go0se01"

void setup() {
pinMode(smokeA0, INPUT);
Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

}

void loop() {

int analogSensor = analogRead(smokeA0);
Firebase.setFloat("Device/data",analogSensor);
Serial.print("mq2 value is : ");
Serial.println(analogSensor);

delay(100);
}]

Hope this is a better post, thank you for guiding me

Wiring.png

int smokeA0 = 4;

For the ESP32 D4 is not equal 4! If you connected the sensor to D4, use D4 in the code to reference the pin!

pylon:

int smokeA0 = 4;

For the ESP32 D4 is not equal 4! If you connected the sensor to D4, use D4 in the code to reference the pin!

Ok, this makes sense, i get an error though when changing it to D4

Hope this is a better post, thank you for guiding me

Edit your posts to add code tags and connect the grounds.

OP's image below.
Wiring.png

jremington:
Edit your posts to add code tags and connect the grounds.

OP's image below.

So if i understand you correctly, connect GND from Mq2 to GND of ESP32?

How many times do I have to repeat it?

You certainly won't get far with this hobby if you can't take time to read, understand and act on the responses to your posts.

jremington:
How many times do I have to repeat it?

You certainly won't get far with this hobby if you can't take time to read, understand and act on the responses to your posts.

Perhaps the issues is i dont understand what it is you need me to do, I believe i added code tags in the second response, if i didnt, or didnt do it correctly, you are welcome to show me how.

I have seen alot of forum responses calling people out when they dont post correctly, but honestly as a first time poster, its very difficult to understand first time all the things that are required.
i did read the tips and rules on posting and thought i had done it correctly.

Please read and follow the directions in the "How to use this forum" post.

If you have questions about a concept like "connect the grounds", google "connect the grounds" for lots of helpful advice.

as in the above reply, i did read the How to use this forum, but being a first time poster, im not going to get it right the first time.

i will google connect the grounds. I must say, there should be a seperate place on the forum for newbies because it feels like everyone that knows whats going one thinks the new guys also do. if i new all these things i wouldnt be on here in the first place

there isnt an internal cause to irritate or annoy, (it seems that is what i have achieved), i am just asking for guidance. i have already poured hours into google and this forum was my last attempt at figuring out my issue

im not going to get it right the first time.

We don't necessarily expect that.

However, when we specifically ask you to "edit your post to add code tags", it is an excellent idea to research how to do that and then do it.

Bye.

#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>
#define smokeA0 D4
int smokeA0 = D4;
int sensorThres = 400;
#define FIREBASE_HOST "notificaton-ffcda.firebaseio.com/"
#define FIREBASE_AUTH "1234567"
#define WIFI_SSID "The only wifi"
#define WIFI_PASSWORD "Ad.Go0se01"

void setup() {
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);                                  
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(300);
}



Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

}

void loop() {
  
  int analogSensor = analogRead(smokeA0);
  Firebase.setFloat("Device/data",analogSensor);
  Serial.print("mq2 value is : ");
  Serial.println(analogSensor);
  
  delay(100);
}

I think i have it now, and yes, i can see how that makes it easier to help me. thank you

i have adjusted the wiring, and i think by doing so i will avoid having to connect the grounds as there is now not 2 seperate power sources.

Wiring.png

I am still getting the same readings, if i pull the D4 pin out, the readings stop. showing me that the pin selection must be correct and that there is something wrong with the coding for the actual sensor. just not sure what it could be

A reading of 4095 tells you that the output value is higher than the maximum value the ESP32 can read. Be careful with such setups, your ESP32 might get damaged by providing higher voltages than 3.3V to it's inputs.