Overview:
Environmental conditions have direct impact on human health and comfort. Thus, it's essential to monitor environmental factors like temperature, humidity, pressure, and dust particulate to make sure we're at the safe healthy condition. In this tutorial, we'll look at how to integrate the BME280 module which measures pressure, humidity, and temperature, as well as the dust particle sensor, which can calculate PM10 and PM 2.5 values (air quality index). We will use Wemos D1 mini to process the data and visualize its results in Cayenne cloud platform.
Hardware and software components:
Hardware:Software:
Online Platform:
Application Description:
Hardware:
- WeMos D1 Mini Module ESP8266
This mini development board is based on ESP-8266E chip and is useful for applications that need wireless data transmission. It is compatible with Arduino IDE and NodeMCU firmware and useful when you want to build innovative projects.
Specifications:
- Input Voltage:7-12V recommended, 6-15V Maximum, (or can be run directly using the integrated USB port.)
- Digital Input/Outputs:9 digital input/output pins, all pins support interrupt/PWM/I2C/one-wire except D0
- Analog Inputs:1 x 10-bit resolution input.
- TTL Serial Ports:1 (Additional Serial ports can be implemented using SoftwareSerial)
- Maximum Output Current:12mA per pin source current, 20mA sink current MAXIMUM
- Flash Memory:4 Megabytes
- SRAM:2KB
- EEPROM:1KB
- Size:3cm x 2.5cm x 0.7cm
- Weight:5 Grams
- USB Port:Micro USB using CH340G driver
Pinout:
-
BME280 Barometric Pressure, Temperature & Humidity Sensor (SPI/I2C)
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure and humidity. This sensor is great for all sorts of indoor environmental sensing and can even be used in both I2C and SPI.
Specifications:
- Interface: I2C (up to 3.4MHz), SPI (up to 10 MHz)
- Temperature: -40 to 85 degrees Celsius
- Humidity: 0 to 100%
- Pressure: 300 to 1100 hPa
- Height: 0 to 30,000 feet
- I2C and SPI interface
- Operation: 3.3V / 5V
- 100% brand new and high quality.
Resolution:
- Temperature: 0.01°C
- Humidity: 0.008%
- Pressure: 0.18Pa
Accuracy:
- Temperature: +-1°C
- Humidity: +-3%
- Pressure: +-1Pa
I2C address:
- SDO LOW : 0x76
- SDO HIGH: 0x77
Pinout:
-
Dust Particulate Sensor w/ Cable
The dust sensor module DSM501A is low cost, compact size for a particle density sensor.
- Quantitative particle measurement with the principle of particle counter.
- Fine particle of which diameters are bigger than one micron could be detected with high sensitivity.
- Inside heater realizes the self-air taking.
- One control contact and two output contacts.
- It can simple use for arduino
The DSM501A consists of:
- Light Emitting Diode(LED) Lamp
- Detector
- Signal amplifier circuit
- Output drive circuit 1
- Output drive circuit 2
- Heater
Application
- Air cleaner or Air purifier
- Air condition
- Air quality monitor
- Ventilator etc.
Pinout of the connector:
Pin Description
1 Input
2 Vout 2
3 VDC (5V)
4 Vout 1
5 GND
Hardware Set-up:
Connect the BME280 and ESP8266. Take note: BME280 requires 3.3v.
ESP8266 D1 - BME280 (SDA)
ESP8266 D2 - BME280 (SCL)
ESP8266 VCC - BME280 (3.3v)
ESP8266 GND - BME280 (GND)
Next, connect up the ESP8266 and DSM501a, follow the pinout below. From the left, line 1-5. Take note: DSM501a requires 5v.
ESP8266 D6 - DSM501a Line 2 (PM1.0)
ESP8266 D5 - DSM501a Line 4 (PM2.5)
ESP8266 VIN - DSM501a Line 3 (VCC)
ESP8266 GND - DSM501a Line 5 (GND)
Software set-up:
NOTE: We must first download the following libraries before we proceed with the coding.
- #include <CayenneMQTTESP8266.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- #include<string.h>
---------------------------------------------------------------------------------------------------------
#define CAYENNE_DEBUG#define CAYENNE_PRINT Serial#include <CayenneMQTTESP8266.h>#include <Wire.h>#include <SPI.h>#include <Adafruit_Sensor.h>#include <Adafruit_BME280.h>#include<string.h>#define PM1PIN 14 //DSM501A input D6 on ESP8266#define PM25PIN 12 //DSM501A input D5 on ESP8266byte buff[2];unsigned long durationPM1;unsigned long durationPM25;unsigned long starttime;unsigned long endtime;unsigned long sampletime_ms = 30000;unsigned long lowpulseoccupancyPM1 = 0;unsigned long lowpulseoccupancyPM25 = 0;Adafruit_BME280 bme; // I2C// WiFi network info.char ssid[] = "MO CONNECT KA?";char wifiPassword[] = "AMBOTwalakokabalo_2022";// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.char username[] = "e3849d00-ab91-11ed-b0e7-e768b61d6137";char password[] = "5b7630330806de309ce7c343c63bc997d80044bb";char clientID[] = "13b95b60-ad35-11ed-b0e7-e768b61d6137";int i=0;void setup() {Serial.begin(9600);unsigned status;status = bme.begin(0x76);Serial.println();pinMode(PM1PIN,INPUT);pinMode(PM25PIN,INPUT);starttime = millis();Cayenne.begin(username, password, clientID, ssid, wifiPassword);}float calculateConcentration(long lowpulseInMicroSeconds, long durationinSeconds){float ratio = (lowpulseInMicroSeconds/1000000.0)/30.0*100.0; //Calculate the ratiofloat concentration = 0.001915 * pow(ratio,2) + 0.09522 * ratio - 0.04884;//Calculate the mg/m3Serial.print("lowpulseoccupancy:");Serial.print(lowpulseInMicroSeconds);Serial.print(" ratio:");Serial.print(ratio);Serial.print(" Concentration:");Serial.println(concentration);return concentration;}void loop() {Cayenne.loop();printValues();durationPM1 = pulseIn(PM1PIN, LOW);durationPM25 = pulseIn(PM25PIN, LOW);lowpulseoccupancyPM1 += durationPM1;lowpulseoccupancyPM25 += durationPM25;endtime = millis();if ((endtime-starttime) > sampletime_ms) //Only after 30s has passed we calcualte the ratio{float conPM1 = calculateConcentration(lowpulseoccupancyPM1,30);float conPM25 = calculateConcentration(lowpulseoccupancyPM25,30);Serial.print("PM1 ");Serial.print(conPM1);Serial.print(" PM25 ");Serial.println(conPM25);lowpulseoccupancyPM1 = 0;lowpulseoccupancyPM25 = 0;starttime = millis();Cayenne.virtualWrite(4, conPM1);Cayenne.virtualWrite(5, conPM25);}}void printValues() {Serial.print("Temperature = ");Serial.print(bme.readTemperature());Serial.println(" °C");Serial.print("Pressure = ");Serial.print(bme.readPressure() / 100.0F);Serial.println(" hPa");Serial.print("Humidity = ");Serial.print(bme.readHumidity());Serial.println(" %");Serial.println();}CAYENNE_OUT_DEFAULT(){Cayenne.celsiusWrite(1, bme.readTemperature());Cayenne.virtualWrite(2, bme.readPressure()/100, "bp", "pa");Cayenne.virtualWrite(3, bme.readHumidity(), "rel_hum", "p");}
Code Breakdown:
Libraries:
Tells the compiler to use the BME280 sensor library. Can be download in Arduino's Library manager.- #include <Wire.h>
- #include <SPI.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
The library for Cayenne Dashboard connection to display the sensor data online. Can be download in Arduino's Library manager.
- #include <CayenneMQTTESP8266.h>
For Cayenne platform
- #define CAYENNE_PRINT Serial
- Enables Cayenne Serial Print
- char username[]
- Device's Cayenne username (provided in the Cayenne link code)
- char password[]
- Device's Cayenne password (provided in the Cayenne link code)
- char clientID[]
- Device's Cayenne client ID (provided in the Cayenne link code)
- Cayenne.begin(username, password, clientID)
- Starts cayenne connection and displays status
- Cayenne.loop()
- Calls the CAYENNE_OUT(VIRTUAL_CHANNEL) class
- Cayenne.virtualWrite()
Uploads the sensor output value to the Cayenn's dashboard
Dust particulate sensor DSM501A and BME280
- unsigned long - The time allotted to stabilize the sensor before requesting output value
-
float conPM1 and float conPM25 - calculating the concentration
- bme.read() - gets the output from the BME280 sensor
- printValues() - gets updated sensor output to display on serial monitor
Note: Before on checking the output, check first the table below which shows the Air quality index (AQI) values, PM2.5 and PM10 conc. air pollution levels, color codes, and health concerns. This will assist you in interpreting the Dust Particulate Sensor DSM501a's output. (Research gate)
Cayenne output:
Video Demonstration:
Conclusion:
We have demonstrated in this mini project the use of WEMOS D1 Mini as main controller to read data from BME280 sensor and DSM501A dust particle sensor. Using Wi-fi to transmit data to Cayene cloud platform, we were able to display data in the web browser in real-time. Sensor modules like these can have a significant help in environment monitoring.References:
- https://www.researchgate.net/figure/Air-quality-index-AQI-values-PM25-and-PM10-conc-color-codes-air-pollutant-level-of_tbl1_343404673
- https://www.instructables.com/Dust-Sensor-With-DSM501a-and-ESP8266/
- https://www.connectedlittleboxes.com/proj02temperaturedisplay.html
- http://www.esp8266learning.com/esp8266-and-bme280-temperature-sensor-example.php