Smart home air quality sensor. Responds to CO2.

about the project

Adequate ventilation is important for health. The MQ-135 sensor monitors the room air. To put it more precisely: According to the manufacturer's data sheet, it monitors the room air for CO2, alcohol, benzene, NOx, and NH3. CO2 is the fourth most common gas in the earth's atmosphere. The other of the gases mentioned are usually and fortunately much less common. We can use that and build a quasi-CO2 measuring device with the MQ-135, which is far cheaper than available CO2 measuring devices.

Of course, we cannot expect laboratory precision. It's more about showing whether it's time to ventilate again.

In addition, the playfulness, the enthusiasm for the IOT technologist should be in the foreground. Because in this kit we connect the MQ-135 on the one hand to an RBG LED to indicate whether the room air is OK (green) or whether it should be ventilated (red). After the start, a calibration phase lasting several minutes is run through (blue). We also connect the MQ-135 to the Internet via a Mini-NodeMCU microprocessor. The CO2 values can thus also be transferred to common smart home systems (such as Home Assistant) via MQTT.

The setup requires certain electronics and PC knowledge. A computer with an installed Arduino IDE is required to install the software.

Disclaimer: This is a kit for hobbyists who are enthusiastic about IOT. No responsibility can therefore be assumed for the functionality of the air quality measurement. The MQ-135 sensor itself gets warm and should therefore only be operated when you are present. In addition, the MQ-135 sensor has a certain burn-in time during which the values can still fluctuate.

hardware

Components

The following components are required for assembly:

  • MQ-135, sensor, standalone
  • 1 x 10 kiloohm resistor
  • WeMos D1 mini NodeMCU
  • 5mm RGB LED, 4pins, common cathode
  • 3 x 220 ohm resistors
  • Circuit board
  • Mounting screws (optional)
  • Housing (optional)

The complete kit in our shop:

soldering

So that the "D1 Mini NodeMCU" can be soldered to the circuit board, it must first be soldered to the PINs. Please make sure that the PINs are soldered on at right angles so that they later also fit the circuit board.

In the next step, all components are soldered to the circuit board.

The markings on the circuit board help to position the components correctly.

Please be sure to observe:

  • Please align the flattened side of the LED with the flattened side of the LED symbol on the circuit board, otherwise the kit will not work and the NodeMCU may be destroyed.
  • The resistors have different values, if they are soldered incorrectly, the kit will not work.
    • The resistors R1 - R3 have 220 ohms
    • Resistor R4 is 10 kilo ohms
  • The MQ-135 sensor has a symmetrical structure. So it doesn't matter which way around it is soldered onto the circuit board.

Then use suitable pliers to shorten the protruding wires on the components.

First test

If the components are incorrectly soldered and the NodeMCU is connected to the PC, this can damage the PC's USB port. Therefore, we first test by connecting the NodeMCU to a classic USB charger or a power bank with a USB cable. If nothing gets too hot there, that's a good sign.

ARDUINO PROGRAMMING

Download and install the Arduino IDE

We need the Arduino IDE, which can be downloaded for free here: https://www.arduino.cc/en/Main/Software

It's even easier on Windows PCs, where the Arduino IDE can be installed via the Microsoft Store.

Add ESP 8266 board

First, add the following "Additional Board Administrator URL" to the default settings: http://arduino.esp8266.com/stable/package_esp8266com_index.json

To do this, we proceed as follows:

1. We call up the default settings:

2. We add the URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Install "ESP8266" board

To do this, we navigate to "Tools -> Board -> Board Manager".

Now we search for "ESP8266" and install the board.

Select "Generic ESP8266 Module" as the board

To do this, we proceed as follows:

1. We navigate via "Tools -> Board -> ESP8266 Boards"

2. We select "Generic ESP8266 Module" as the board

Select upload speed

Under "Tools -> Upload Speed" we select 115200.

Manage libraries

We need the following Arduino libraries:

  • ESP8266WiFi.h
  • PubSubClient.h
  • ArduinoJson.h

The library "ESP8266WiFi.h "is automatically available by selecting the" Generic ESP8266 Module "as a board (see previous step).

We install the other two libraries as follows:

We can install the required libraries under “Tools -> Libraries”.

1. We search for "PubSubClient" and select Nick O'Leary's library and click on "install":

2. We search for "ArduinoJason" and select the Benoit Blanchon library and click on "install":

Copy the Arduino sketch from GitHub

Now we call up the following Arduino sketch from GitHub and copy it into a new sketch in our Arduino IDE using "Copy / Paste":

https://github.com/NEOE-IO/NEOE-IOT-Kit-1

Now we have to add individual information to the Arduino sketch (see comments in the sketch), e.g. for

  • WLAN access data
  • MQTT server data

Please read all comments in the sketch carefully.

Upload the Arduino sketch to the NodeMCU

Now we connect our air quality sensor to our computer using a USB cable.

Then we select the relevant USB interface (e.g. COM3 or COM4) via "Tools -> Port".

Now we click on "Sketch -> Upload" and if there are no more errors in the sketch, it can be successfully uploaded and we can now use our "air quality sensor".

CONNECTION TO SMART HOME SYSTEM

The NEOE IOT kits are developed and tested for home assistants, as this is the smart home system we currently prefer due to the extensive and well-engineered functionalities. For more information on Home Assistant, see https://www.home-assistant.io.

Home Assistant

For the basic setup of Home Assistant, see https://www.home-assistant.io/getting-started/.

We designed the Arduino Sketch to support Home Assistant's MQTT Discovery functionality. As a result, the sensor is automatically recognized by Home Assistant and the data transmitted via MQTT can be displayed directly in the dashboards. To activate the MQTT Discovery function in Home Assistant, see https://www.home-assistant.io/docs/mqtt/discovery/.

The sensor data can be displayed in the Home Assistant dashboards in different ways.

Sensor Card:

Gauge Card:

If you click on the respective card, a history is displayed:

Other smart home systems

Thanks to the use of the MQTT protocol, it should also be possible to connect to all other smart home systems that support MQTT. However, due to the large number of different systems, we cannot guarantee this. To connect to other smart home systems via MQTT, please consult the documentation for the respective smart home systems.

calibration

After each restart (i.e. new connection with power) the sensor goes through a calibration phase. During this time the indicator LED is blue. The current CO2 concentration in the room air is defined as 397.13 ppm. In order for the sensor to output correct values, this calibration must be carried out in the fresh air or at least in a completely ventilated room.

Once the calibration is complete, the indicator LED will turn green.

If the calibration was carried out in a poorly ventilated room and is then ventilated or the sensor is completely exposed to fresh air, the calibration starts again (the indicator LED turns blue again) until the sensor has been recalibrated.

Indicator LED

The indicator LED changes depending on the CO2 value determined (after calibration) in a flowing color gradient:

  • Below 1000 ppm it is green.
  • From approx. 1000 ppm, the green turns into a slight yellow tinge.
  • At around 1500 ppm it is yellow.
  • At around 2000 ppm it is red.

casing

If desired, the air quality sensor can be housed in a housing. There are two ways of doing this.

Variant 1: Create the housing yourself with a 3D printer

Print data see https://www.thingiverse.com/thing:3993650

Variant 2: Buy the housing in our shop

We offer this housing made of transparent acrylic glass as an option in our shop. Please refer: NEOE-Kit-1

Frequently asked questions

The values fluctuate a lot, what could be the reason?

  • The sensor may still be in the "burn-in phase". After approx. 48 hours of operation, the values should be more stable.
  • The sensor may not be properly inserted into the breadboard and the contact resistance changes when it is moved. Then check the plug connection of the sensor.

The indicator LED does not light up at all

  • Have the WLAN access data been stored correctly? Attention: upper and lower case is important.

The indicator LED changes between blue and green

  • We have programmed the indicator LED in such a way that it changes to green after 95% calibration has been carried out. If the CO2 value or the value of one of the other gases detected by the sensor is increased during the calibration phase, the change to green may take place too early. If the value then goes back, the program recognizes that the calibration has not yet been completed and the LED lights up blue again. The calibration will then continue until the target value is reached.

The CO2 value levels off somewhere between 400 and 450 ppm when the window is open. Shouldn't it be 397.13 ppm?

  • The values of the MQ-135 sensor fluctuate somewhat for technical reasons. Our calibration algorithm defines the lowest possible value as 397.13 ppm. The “leveled out” CO2 value is therefore the lowest possible value plus the technically-related fluctuations in the sensor. The information quality should be sufficient for the function “Is the room air OK or should it be ventilated again?”. If a more precise CO2 value has to be determined, we recommend special measuring devices, which are much more expensive.

The Arduino program code does not work and an error message appears in the Arduino IDE

  • Automatic translation from English to German is activated in some browsers. As a result, the Arduino program code on GitHub is automatically translated into German and is therefore displayed incorrectly. In this case, please deactivate the automatic translation before copying and transferring the Arduino program code. 

When compiling the Arduino sketch, I get the error message "ESP8266WiFi.h: No such file or directory"

  • The wrong board was selected. In order for the sketch to be compiled / uploaded successfully, the board "Generic ESP8266 Module ". See section" Arduino programming ".

 

 

Disclaimer - all information without guarantee:

The information contained in this tutorial (contribution) has been researched and compiled to the best of our knowledge and belief. However, mistakes can happen to us too. And something can also go wrong during the implementation of the tutorial or the content can be misunderstood. We cannot therefore accept any liability for any damage caused by following this tutorial. We are continuing to develop our tutorials. If something is inconsistent or unclear, please let us know so that we can correct or add to the point concerned. Thanks very much.

 

    Leave a comment

    Please note, comments must be approved before they are published