Categories

EnviroSense Panel

EnviroSense, an STM 32 Base Environmental Monitoring System

I started working on this project back when I was in Edmonton. There was couple of attempts failed because of complexities involved. After COVID-19 I was able to save couple of hours every day not forcing to commute to work which helped me finish this project.

The system measures following parameters:

  1. Temperature
  2. Humidity
  3. Barometer pressure
  4. CO2
  5. PM1.0, PM2.0, and P.M10
  6. Light intensity level
  7. Sound noise level

My Take

The PMS7003 was easy to work with somehow reliable results, its physical connection was hard to integrate though and needed some hacks.

I was surprised by the STM32 power and number of connections, it is not easy to program it but since integration with Arduino IDE it is now much easier and libraries are more accessible.

The NRF24 is operating at 2.4 GHz and I found them easy to work with thanks to MySensor. Consider advancements such as ESP32, I cannot think of using them in my future projects!

I am planing to keep the station running from my balcony and compare the result with the one of City of North Vancouver air monitoring system.

System Architecture

Architect

Sensors

Prototype

BME 280

BME 280 is a well-known sensor from Bosch. It measures Temperature, Humidity, and Barometer pressure.

Use this page to learn more: BME280 Guide

NOTE: the I2C address is: 0x76

SCK pin to the I2C clock SCL pin on your Arduino. On an UNO & ‘328 based Arduino, this is also known as A5 SDI pin to the I2C data SDA pin on your Arduino. On an UNO & ‘328 based Arduino, this is also known as A4 It’s both 3.3 and 5 but I am using 3.3

you can also have a look at this web site: MySensors BME 280

MIC-NOISE

I started the project with one of those cheap microphones.

First soldering the mic: How to find the polarity of a microphone

Sparkfun has good tutorial on how to read from mic breakout boards: Sample code to read from amp

The next logical question I needed to answer was: Update: how to translate from sound to noise?

A useful post to answer the question: Sound level meter

Plotting the analogue pin output shows small variations in the pin output due sound, that could be related to the mic amplifier, so I changed my amplifier!

MIC-MAX9814

This is the module I am using: MAX9814 with Auto Gain Control

It works, now let’s move to STM 32:

For STM I am using Analogue pin (PA1) and this is the code:


const int sampleWindow = 200; // Sample window width in mS (250 mS = 4Hz)
#define AmpMax (4096 / 2)

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  long soundLevelAvg = 0;
  for (int i = 0; i <= 10; i++)
  {
    unsigned long start = millis(); // Start of sample window
    int numberOfSamples = 0;

    long soundVolMax = 0;
    // collect data for 200 miliseconds
    while (millis() - start < sampleWindow)
    {
      int k = analogRead(PA1);
      int amp = abs(k - AmpMax);
      soundVolMax = max(soundVolMax, amp);
      numberOfSamples += 1;
    }

    // convert from 0 to 100

    soundVolMax = 100 * soundVolMax / AmpMax;
    soundLevelAvg = soundLevelAvg + soundVolMax;
  }
  soundLevelAvg /= 10;
   Serial.println(" Amp: Max: " + String(soundLevelAvg));
}

MH-Z19B CO2 sensor

From the sensor manual:

MH-Z19B NDIR infrared gas module is a common type, small size sensor, using non-dispersive infrared (NDIR) principle to detect the existence of CO 2 in the air, with good selectivity, non-oxygen dependent and long life. Built-in temperature compensation; and it has UART output and PWM output.

MH-Z19B manual

Arduino Library

An example code using the sensor

Please be noted that the sensor needs 5v to operate properly

PMS7003 pm2.5

The PMS7003 is a particle matter counter capable of detecting particulates in the range of 0.3 to 10 microns. It provides PM1.0 (0.3-1.0um), PM2.5 (1.0-2.5um), and PM10 (2.5-10.0um).

A very good point to start: PMS7003 Arduino Library

I ended up using the PMS.h library as it puts the sensor into sleep. The sensor has a limited life.

A mysensor code [needs to be checked as it is for Arduino]: MySensors PMS7003

The Brain: STM32F103C8T6 AKA BluePill

As the Arduino nano and pro only have 1 UART and my air quality sensors both require UART, I am switching to the STM.

A good starting point: STM32 starting guide