Jan Ibrahim
Published © GPL3+

M5Stack Enviro Threat Detector

This project presents a multisensor environmental threat detector of TEMP, HUM, VOC, LUX, PM2, 5, CO2, and, X-RAY.

IntermediateShowcase (no instructions)10 hours2
M5Stack Enviro Threat Detector

Things used in this project

Hardware components

PM 2.5 SENSOR USB POWER/SHT20 (PMSA003)
M5Stack PM 2.5 SENSOR USB POWER/SHT20 (PMSA003)
×1
I2C Hub 1 to 6 Expansion TCA9548A Module
M5Stack I2C Hub 1 to 6 Expansion TCA9548A Module
×1
Dlight Unit - Ambient Light Sensor (BH1750FVI-TR)
M5Stack Dlight Unit - Ambient Light Sensor (BH1750FVI-TR)
×1
ENV II Unit with Temperature Humidity Pressure Sensor(SHT30+BMP280)
M5Stack ENV II Unit with Temperature Humidity Pressure Sensor(SHT30+BMP280)
×1
I/O Hub 1 to 6 Expansion
M5Stack I/O Hub 1 to 6 Expansion
×1
SparkFun Pocket geiger
×1
LEGO Technic 39369 6252630
×2
LEGO Technic 64179 6300331
×2
LEGO Technic 2780 4121715
×22
LEGO TECHNIC 15M BEAM
×1
PSG-JWS-65
×1
1700-0132
×1

Software apps and online services

M5Stack M5Flow
M5Stack M5Burner

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Code

M5STACK ENVIRO SENSORS

MicroPython
from m5stack import *
from m5ui import *
from uiflow import *
import machine
import module

import time
import unit


setScreenColor(0x222222)
env3_0 = unit.get(unit.ENV3, unit.PAHUB1)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA)
tvoc_0 = unit.get(unit.TVOC, unit.PAHUB2)
dlight_0 = unit.get(unit.DLIGHT, unit.PAHUB0)
pbhub_0 = unit.get(unit.PBHUB, unit.PAHUB3)




pm0 = module.get(module.PM25)

label0 = M5TextBox(0, 0, "T", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label1 = M5TextBox(0, 40, "H", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label2 = M5TextBox(0, 80, "VOC", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label3 = M5TextBox(0, 122, "LUX", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label4 = M5TextBox(0, 167, "PM2.5", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label5 = M5TextBox(0, 208, "CO2", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label12 = M5TextBox(158, 0, "SIG", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label6 = M5TextBox(71, 0, "TEMP", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label13 = M5TextBox(226, 0, "SIG", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label7 = M5TextBox(140, 40, "HUMI", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label14 = M5TextBox(155, 167, "NS", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label8 = M5TextBox(80, 80, "TVOC", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label15 = M5TextBox(226, 167, "NOISE", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label9 = M5TextBox(135, 122, "LUX", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label10 = M5TextBox(102, 167, "PM", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label11 = M5TextBox(133, 209, "CO2", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)

import math


def buttonC_wasPressed():
  # global params
  machine.reset()
  pass
btnC.wasPressed(buttonC_wasPressed)


pahub_0.select_only_on(0)
pahub_0.select_only_on(1)
pahub_0.select_only_on(2)
while True:
  label6.setText(str(round(env3_0.temperature)))
  label7.setText(str(round(env3_0.humidity)))
  label8.setText(str(tvoc_0.TVOC))
  label9.setText(str(dlight_0.get_lux()))
  label10.setText(str(pm0.get_pm2_5_factory()))
  label11.setText(str(tvoc_0.eCO2))
  label13.setText(str(pbhub_0.analogRead(0)))
  label15.setText(str(pbhub_0.analogRead(1)))
  wait_ms(50)
  if btnA.isPressed():
    while not (btnB.wasPressed()):
      speaker.setVolume(0)
    wait_ms(100)
  else:
    if (tvoc_0.TVOC) > 700:
      speaker.setVolume(1)
      speaker.tone(4800, 200)
      label2.setColor(0xff0000)
    else:
      label2.setColor(0x33ff33)
    if (tvoc_0.eCO2) > 700:
      speaker.setVolume(1)
      speaker.tone(2000, 200)
      label5.setColor(0xff0000)
    else:
      label5.setColor(0x33ff33)
    if (pm0.get_pm2_5_factory()) > 120:
      speaker.setVolume(1)
      speaker.tone(1000, 200)
      label4.setColor(0xff0000)
    else:
      label4.setColor(0x33ff33)
    if (dlight_0.get_lux()) < 100:
      speaker.setVolume(1)
      speaker.tone(500, 200)
      label3.setColor(0xff0000)
    else:
      label3.setColor(0x33ff33)
    if (env3_0.temperature) > 28:
      speaker.setVolume(1)
      speaker.sing(220, 1)
      label0.setColor(0xff0000)
    else:
      label0.setColor(0x33ff33)
    if (env3_0.humidity) > 70:
      speaker.setVolume(1)
      speaker.sing(494, 1)
      label1.setColor(0xff0000)
    else:
      label1.setColor(0x33ff33)
    wait_ms(100)
  wait_ms(100)
  wait_ms(2)

Credits

Jan Ibrahim

Jan Ibrahim

1 project • 11 followers

Comments

Add projectSign up / Login