Skip to main content

One post tagged with "IoT"

Internet of Things projects and concepts

View All Tags

Building an Basic Air Quality Monitoring System with MicroPython

· 5 min read

This project combines gas detection with temperature and humidity monitoring. The goal is to create a reliable, low-cost system for monitoring indoor air quality using off-the-shelf components. I chose the MQ135 gas sensor for its ability to detect a wide range of gases, including CO2, and the DHT22 for accurate temperature and humidity readings. The system is built around a MicroPython-capable microcontroller (RP2350) and uses XBee modules for wireless communication.

Components

For this project, I used:

  • 2x MQ135 gas sensor for CO2 and other gas detection
  • 2x DHT22 sensor for temperature and humidity readings
  • 3x XBee modules for wireless communication
  • 2x MicroPython-capable microcontroller (RP2350)

Challenges with Gas Sensor Accuracy

One of the biggest challenges I faced was getting reliable readings from the MQ135 gas sensor. These sensors are sensitive to environmental factors, particularly temperature and humidity. RZERO values drift as the sensor ages and the standard libraries available don't account for these variables leading to inaccurate PPM (parts per million) calculations.

To solve this problem, I implemented a temperature and humidity compensation algorithm. This required:

  1. Calculating a correction factor based on current conditions
  2. Applying this correction to both resistance readings and PPM calculations
  3. Implementing a moving average for calibration stability
def _get_correction_factor(self, temperature, humidity):
"""Calculates the correction factor for ambient air temperature and relative humidity"""
if temperature < 20:
return self.CORA * temperature * temperature - self.CORB * temperature + self.CORC - (humidity - 33.) * self.CORD
return self.CORE * temperature + self.CORF * humidity + self.CORG

This function calculates how much we need to adjust our readings based on current environmental conditions, significantly improving accuracy.