HannTu
HannTu

Reputation: 1

Analog Reading Issue with MQ2 Sensor on ESP32 (Always 0)

I’m trying to use an MQ2 gas sensor with my ESP32, but I’m having some issues. I've already done the preheating process for the MQ2 sensor, but the analog reading from the sensor always shows 0 in the serial monitor. When I connect the same sensor and circuit to an Arduino Uno (using A0 pin), it works fine and gives good analog readings.

Code I'm using:

#define MQpin 34

float RL = 1.0;               //load resistance (in kilo Ohms)
float analogVal,VRL, Rs, Ro;

void setup(){
  Serial.begin(115200);
  pinMode(MQpin, INPUT);
}
 
void loop(){
  analogVal = analogRead(MQpin);
  VRL = analogVal * (3.3 / 4095.0);
  Rs = RL * ((3.3/VRL) - 1);
  Ro = Rs / 9.531618832347878;  // from datasheet MQ2

  Serial.print("Analaog val = ");
  Serial.println(analogVal);
  Serial.print("Ro in clean air = ");
  Serial.println(Ro);i

I’m not using WiFi or Bluetooth functionalities on the ESP3. I also changed the ADC pin from GPIO 34 to other ADC pins on the ESP32, but the readings are still 0. Previously, I got some readings, but they were highly unstable, fluctuating significantly, and sometimes dropping to 0. But now, after another attempt with preheating, the sensor consistently reads 0.

Is there any specific configuration required on the ESP32 to read analog pins that I might be missing? or any recommendations to ensure proper analog readings from the MQ2 sensor on the ESP32?

Upvotes: 0

Views: 61

Answers (0)

Related Questions