Monitor Co2 And Tvoc With Esp32
About the project
How to make a simple CO2/TVOC monitor.
Project info
Difficulty: Easy
Platforms: Arduino
Estimated time: 2 hours
License: GNU General Public License, version 3 or later (GPL3+)
Story
Due to the epidemic of covid-19, I have to work from home. In the winter, I have to close the doors and windows. The longer I stay in, the higher levels of CO2 increases, that made me a bit dizzy and lazy. Although CO2 is a harmless gas, people in high concentrations of CO2 for a long time will be harmful to health: Around 1000 ppm, a common indoor level, you will start to experience fatigue and sleepiness; For up to 2000 ppm, you will fall into sleep and feel really tired, that can’t go on any work. With prolonged exposure and increases in concentration, you may have a headache and feel physically uncomfortable.
Monitoring the indoor CO2 Level may actually be more important than our common sense, so I made a CO2 monitor to show the indoor CO2 level reminder me to open the door and windows timely for improving the indoor air.
The Sensor for monitoring CO2 and TVOC
At room temperature, carbon dioxide (CO2) is a colorless, odorless, non-flammable gas, that must have a specific sensor to monitor it. SGP30 is a gas sensor that intended for indoor air quality monitoring. SGP30 can detect a wide range of H2 and return an equivalent carbon dioxide reading calculated based on H2 concentration to the microcontroller over I2C. SGP30 has an ability to set humidity compensation for better accuracy, that it needs an external humidity sensor to work with. Besides, the SGP30 sensor can detect a wide range of Volatile Organic Compounds (VOCs) and return a total volatile organic compound (TVOC) reading.
I used the AM2302 to work with SGP30. AM2302 is a digital temperature and humidity sensor, it’s very common and easy to use.
The diagram for the monitor
As the figure shows, I need the microcontroller to receive the data and LCD module display besides the SGP30 and AM2302.
ESP32 3.2’’ LCD is a good selection as the microcontroller that contains the LCD display module. ESP32 3.2‘’ LCD is a board develop for Arduino and ESP32 that integrate LCD. The LCD is 320x240 TFT, with driver is ILI9341, it uses SPI for communication with ESP32. ESP32 3.2’’ LCD has been integrated SD module that can save data to the SD card over SPI. ESP32 3.2’’ LCD provides many expansion ports that many sensors are allowed to connect to the port. In addition, the board has the touch ability and the TFT can be used as an input device.
Preparation
2. SGP30
3. AM2302
4. Micro-USB cable
5. Jump wires
6. Breadboard
Connection
Firmware
1. The firmware can be obtained from here: https://github.com/Makerfabs/Project_Touch-Camera-ILI9341/tree/master/example/CO2_Monitor
2. Install the DHT sensor library of the Adafruit on the Arduino IDE.
3. Install the Adafruit SGP30 sensor library.
4. Install the TFT_eSPI library.
5. Initialize the AM2302 and SGP30 in the code “Project_Touch-Camera-ILI9341/example/CO2_Monitor/CO2_Monitor.ino”.
- dht.begin();
- if (! sgp.begin()){
- Serial.println("Sensor not found :(");
- while (1);
- }
6. Get the data of temperature and humidity from AM2302.
- float h = dht.readHumidity();
- float t = dht.readTemperature();
7. Set the absolute humidity value for compensation to increase precision of TVOC and eCO2.
- sgp.setHumidity(getAbsoluteHumidity(t, h));
8. Commands the sensor to return a single eCO2/VOC measurement.
- if (! sgp.IAQmeasure()) {
- Serial.println("Measurement failed");
- return;
- }
- Serial.print("TVOC ");
- Serial.print(sgp.TVOC);
- Serial.print(" ppbt");
- Serial.print("eCO2 ");
- Serial.print(sgp.eCO2);
- Serial.println(" ppm");
9. Display the value on the LCD.
- char buf[8];
- dtostrf(t, 4, 0, buf);
- tft.drawRightString(buf, 0 * 90 + 60 - 5, 167 - 27 + 155 - 18, 2);
- dtostrf(h, 4, 0, buf);
- tft.drawRightString(buf, 1 * 90 + 60 - 5, 167 - 27 + 155 - 18, 2);
- dtostrf(TVOC, 4, 0, buf);
- tft.drawRightString(buf, 2 * 90 + 60 - 5, 167 - 27 + 155 - 18, 2);
10. Upload the firmware to ESP32 3.2’’ LCD.
Test
In general, the CO2 level in outdoor air is 400 ppm. People have limited or no health effects in no more than 1000ppm CO2. Once the CO2 level over 1000ppm, people will feel fatigued, loss of focus and concentration. Power on the board, SGP30 takes a while for preparation. After the screen displays the CO2 level normally, I try to take a breather to the SGP30, the value will increase and then go back to about 400PPM. Put the board in a meeting room and the CO2 level will increase to 840PPM when the two-hour meeting is over. Put volatile compounds such as alcohol and shampoo besides the board, and the TVOC level will increase rapidly as evaporating.
Show
Extension
I used other ESP32+DISPLAY modules to achieve the same monitor. These monitors can be placed in homes, small rooms, offices, greenhouse, or cars to remind us to change fresh air in time and pay more attention to air quality. I can place the monitor in the workshop with many volatile organic compounds to measure the TVOC level, reminds workmates to take a mask or improve the air quality for health.
Leave your feedback...