MQ6 with esp8266 using digital out

I have simple program which consists of two mq6 gas sensor(using digital out) connecting with nodemcu.

I have two sensors of MQ6 so i am connecting with digital out from sensor and digital in to nodemcu. When i try to read the value i always get 1.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
#define BLYNK_PRINT Serial   // Comment this out to disable prints and save space
char auth[] = "Auth Token";  //Enter Authentication code sent by Blynk on your regested email


char ssid[] = "----------";  // Enter WIFI Name Here
char pass[] = "----------";  // Enter WIFI Password Here


const int MQ6_1 = 2;
int MQ6_1_data = 0;

const int MQ6_2 = 3;
int MQ6_2_data = 0;

const int button = 4;
int buttonStatus = 0;

void setup() {
  Serial.begin(115200);
  pinMode(button, INPUT);
  pinMode(MQ6_1,INPUT);
  pinMode(MQ6_2,INPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, getSendData);
}

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

void getSendData() {
  MQ6_1_data = digitalRead(MQ6_1);

  Serial.print("MQ6 DATA 1: ");
  Serial.print(MQ6_1_data);
  Serial.println();

  MQ6_2_data = digitalRead(MQ6_2);
  Serial.print("MQ6 DATA 2: ");
  Serial.print(MQ6_2_data);
  Serial.println();

  buttonStatus = digitalRead(button);
  Serial.print("Switch: ");
  Serial.print(buttonStatus);
  Serial.println();

  Blynk.virtualWrite(V2, MQ6_1_data);
  Blynk.virtualWrite(V3, MQ6_2_data);
  Blynk.virtualWrite(V4, buttonStatus);

  if (MQ6_1_data > 200) {
    Blynk.notify("Smoke Detected! First Sensor");
  }
  if (MQ6_2_data > 200) {
    Blynk.notify("Smoke Detected! Second  Sensor");
  }

  if (buttonStatus == HIGH) {
    Blynk.notify("Button On");
  }
}

kindly help me to rectify the issue. I googled it but i found only using analog out they connecting.

digitalRead() returns either 0 (no voltage) or 1 (voltage detected). Your condition will never match. I guess you expected another behavior of digitalRead().

MQ6 is an analog sensor, it has only an analog output.
MQ-4_pic

So I suspect what you have is a module containing an MQ6 sensor and a comparator chip, which turns the analog output into a digital signal (HIGH or LOW).

On the back side of the module there is a small "trimpot" which is a potentiometer you can adjust to set the threshold when the digital output changes from LOW to HIGH. If you adjust this with a small screwdriver, you can find a setting where it will read LOW until gas is detected.

However, you should not connect the digital output from the module directly to the ESP pin. The module requires 5V to power it, and the digital output will be a 5V signal. The ESP is a 3.3V device and could be damaged if you connect a 5V signal directly to it. To overcome this problem, use a voltage divider to reduce the 5V signal down to 3.3V. 10K + 22K resistors can be used.

@PaulRB @pylon ok i will try

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.