Air Quality with MQ-135 and Wemos D1 mini ESP8266

Measure Air quality with MQ-135 and ESP8266 Wemos D1 mini

As the MQ135 is not  really suited as a CO2 sensor (See my previous blog) and I still wanted to use it, I will use it as an air quality probe on an ESP8266.

As the title mentioned I will use an ESP8266 connected to my local WiFi router for this to send the data to thingspeak.com.Image of the Wemos d1 mini ESP8266 module
The ESP8266 I use is the Wemos D1 mini. The Wemos D1 mini has an USB interface and can be programmed with the normal Arduino GUI. You can add the board to it. See this article for how to add this board to the GUI.

I also use an DHT22 (AM2302) in this project to measure temperature and dht22 connectionshumidity. The DHT22 data pin is connected to pin D5 of the ESP8266 in my project. VCC is connected to the 5V of the ESP, GND is connected to GND.  You can of course any digital pin you want in your project. Just change line “#define DHTPIN D5” with the pin number you want.

For the MQ-135 you can only connect it to pin A0, as this is the only analog pin on the ESP8266.

For the air quality I store the lowest measured value in the EEPROM, so anything worse/higher that this best value is bad air quality. I use variable a1 & a2 & a3 to check if it is an new ESP8266, if these value in EEPROM are different than the stored values I presume that it is a new ESP and then set the lowest value to 510, if the values are the same I do not change the lowest value in EEPROM.

Below the program I use for this project.
I will try to describe any main step of it.

If you only want to use the MQ135 and no DHT22 then use the code below.

shop at aliexpress

counter

7 thoughts on “Air Quality with MQ-135 and Wemos D1 mini ESP8266”

  1. Please help me. I’m a beginner.
    Unfortunately, the code does not work. I can upload it without error, but it is not connected to the router. I replaced the semicolons because they did not abandon the Arduino IDE.
    Do not know where the bug is?
    Thanks

    1. Hi Jozsef,

      Lets try it without the multi SSID’s

      Just above the “WiFi.begin(ssid, password);” add two lines:
      ssid = ssid1;
      password = password1;
      WiFi.begin(ssid, password);

      Change the ssid1 and password1 with the login values of your router.

      Regards,
      Rob.

  2. Hello,
    This is Bhavana, I have stated this project directly with NodeMCU8266 I’m also facing the same problem can you help me as soon as possible.

    Regards,
    Bhavana.

  3. Hi,
    what this value means ? “int s = 25; ”
    Can i change it? or how do i know which value is ok for me?

    Thanks.

    1. Hi Dani,

      It is used in a loop. the loop now runs 25 times and measures the air quality. All measurements are added to one total and then divided again thru 25. So the outcome is the average of the 25 measurements.
      You can change the number, but better not make it smaller, otherwise it will fluctuate much more.
      Making s bigger is no problem.

      Regards,
      Rob.

Leave a Reply

Your email address will not be published. Required fields are marked *