Close

Testing the ESP's analog read with the MQ9(1)

A project log for Wearable CO monitor

A wearable CO monitor that uses an ESP8266

rahoon-goawayRahoon GOAWAY 01/13/2019 at 13:050 Comments

I connected the MQ sensor to jumper wires, and soldered one half of its pins together for Vcc(yellow wire), and on the other side I soldered the opposite two together for the output(orange wire), while the last pin was its GND(purple wire).

Then I connected it to the ESP, with its output pin going to the ESP's ADC pin.

Here's the code I uploaded to the ESP:

void setup() {
 Serial.begin(115200);
}

void loop() {
  delay(500);
  Serial.println(analogRead(A0));
}

But it only returned 1024, which meant the sensor's output voltage was equal to its input voltage, which means something is wrong. When removing the pin from the breadboard, the analog reading fluctuated, but returned to 1024. After checking the ESP8266 Arduino Core website(https://arduino-esp8266.readthedocs.io/en/latest/reference.html#analog-input), I found that the ADC pin can only handle 1V. I think the ADC on the chip may be broken, because I connected it to 5V initially, before changing it to 3.3V. Luckily, I have a spare. I'll have to use a voltage divider.

Discussions