Yousuke Tamai
Published

M5StickC Plus2 Air Quality Monitor with PM2.5 & PM10 Display

A compact, break‑out air quality monitor built using the M5StickC Plus2 and Grove HM3301 laser PM2.5 sensor. It detects PM2.5 and PM10 conce

BeginnerFull instructions provided1 hour144
M5StickC Plus2 Air Quality Monitor with PM2.5 & PM10 Display

Things used in this project

Story

Read more

Schematics

Wiring Diagram: Connecting Grove PM2.5 Sensor to M5StickC PLUS 2

This schematic shows how the Grove Laser PM2.5 Sensor (HM3301) is connected to the M5StickC PLUS 2 using the Grove port.

The sensor uses I2C communication. On the M5StickC PLUS 2, the Grove port corresponds to:
- SDA: GPIO21
- SCL: GPIO22

No additional components are required. Just plug the sensor into the Grove port.

Make sure the power is 3.3V or 5V (compatible with the sensor).

Code

PM2.5 and PM10 Display on M5StickC PLUS 2 with Grove HM3301

Python
This MicroPython code is for M5StickC PLUS 2 with a Grove - Laser PM2.5 Sensor (HM3301).
It reads PM2.5 and PM10 concentrations in the air and displays the values on the screen.
Connect the HM3301 sensor to PORTA on the M5StickC PLUS 2.
from m5stack import *
from m5stack_ui import *
from uiflow import *
import unit

screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0x000000)

pm25 = None
pm10 = None

label_pm25 = M5Label('PM2.5: -- ug/m3', x=10, y=20, color=0xffffff, font=FONT_MONT_24, parent=None)
label_pm10 = M5Label('PM10: -- ug/m3', x=10, y=60, color=0xffffff, font=FONT_MONT_24, parent=None)
label_status = M5Label('Status: --', x=10, y=100, color=0xff0000, font=FONT_MONT_18, parent=None)

pm25_1 = unit.get(unit.PM2_5, unit.PORTA)

def update_display():
    global pm25, pm10
    data = pm25_1.read()
    if data:
        pm25 = data['pm2_5']
        pm10 = data['pm10']
        label_pm25.set_text('PM2.5: {} ug/m3'.format(pm25))
        label_pm10.set_text('PM10:  {} ug/m3'.format(pm10))
        label_status.set_text('Status: OK')
        label_status.set_color(0x00ff00)
    else:
        label_status.set_text('Status: NG')
        label_status.set_color(0xff0000)

tim0 = Timer(1)
tim0.schedule(period=2000, mode=Timer.PERIODIC, callback=lambda t:update_display())

Credits

Yousuke Tamai
1 project • 0 followers
high school Biology teacher

Comments