How To Monitor Your Room/Classroom Air Quality?

Hello, in this post i will show you how can you monitor your room/classroom air quality. It is important to have a well aired room for health. In winter sometimes we don’t aired our rooms or classrooms well. So room/classroom air quality is drop. In this project you can monitor your room or classroom air quality any time. We need 2 main component for this project:

1xRaspberry Pi Pico

1xMQ135 sensor.

A Typical MQ135 Air Quality Sensor(CO2 Sensor)

For connect Mq135 to Pico, use jumper cables. MQ135 Analog out to Pico Analog0, and connect GND and VCC. After connection Copy and paste code below to Thonny Editor.

# Import necessary libraries
import time
import board
import analogio

# Define analog input pin for MQ135 sensor
mq135_pin = analogio.AnalogIn(board.A0)

# Main loop
while True:
    # Get sensor data
    mq135_raw = mq135_pin.value  # Raw ADC value
    mq135_voltage = mq135_raw / 65535 * 3.3  # Convert raw ADC value to voltage
    mq135_rzero = 10  # Resistance of MQ135 sensor at 100 ppm CO2 (replace with actual value)
    mq135_ppm = 116.6020682 * (mq135_rzero / (mq135_voltage * 1000) - 1.0)  # Calculate CO2 concentration in ppm

    # Print data to terminal
    print("MQ135 Raw ADC: {}".format(mq135_raw))
    print("MQ135 Voltage: {:.2f} V".format(mq135_voltage))
    print("MQ135 CO2 Concentration: {:.2f} ppm".format(mq135_ppm))

    # Wait for 5 seconds
    time. Sleep(5)

And then click Run button on your Thonny Python. Now you can check room or classroom air quality every 5 seconds. You can also add a TFT/LCD panel and monitor rooms air quality via LCD. The code with LCD is below:

# Import necessary libraries
import time
import board
import busio
import adafruit_mq135
import adafruit_rgb_display.ili9341 as ili9341
from digitalio import DigitalInOut, Direction

# Initialize SPI bus and ILI9341 TFT-LCD display
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs_pin = DigitalInOut(board.CE0)
dc_pin = DigitalInOut(board.D9)
reset_pin = DigitalInOut(board.D5)
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin)

# Initialize MQ135 sensor
mq135 = adafruit_mq135.MQ135(board.A0)

# Set up display font
font_size = 20
font = displayio.Font("fonts/FreeMonoBold.ttf", size=font_size)
text_color = 0xFFFFFF
text_bg_color = 0x000000

# Main loop
while True:
    # Get sensor data
    co2_ppm = mq135.CO2

    # Clear display
    display.fill(text_bg_color)

    # Display CO2 concentration data
    co2_text = displayio.Group()
    co2_text.append(displayio.BitmapLabel(font, text="CO2 Concentration: {:.2f} ppm".format(co2_ppm), color=text_color))
    co2_text.x = 0
    co2_text.y = 0
    display.show(co2_text)

    # Pause for a moment before taking the next reading
    time. Sleep(0.5)

The code that should work for displaying the air quality data on a 240×320 TFT-LCD display connected to the Raspberry Pico over SPI using the MQ135 sensor. You have to connect TFT-LCD to Pico’s SPI pins. And note that you’ll need to install the adafruit-circuitpython-mq135 and adafruit-circuitpython-rgb-display libraries to use this code. You can install these libraries using the command sudo pip3 install adafruit-circuitpython-mq135 adafruit-circuitpython-rgb-display in a terminal.

Hope you enjoy this project. See you in an other project. Fell free to ask any question in comments below.

2 thoughts on “How To Monitor Your Room/Classroom Air Quality?

Leave a Reply

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