Monday, February 3, 2020

ESP8266-based WiFi MQTT air quality monitoring system using PMS7003 sensor

Introduction


Low-cost (US$19) MQTT Air Quality Monitoring System





Purpose


The aim of this project is to use PMS7003 sensor to measure air quality and publish data to MQTT broker.

Features


This project is based on our previous project named "ESP8266-based air quality monitoring system using PMS7003 sensor". It adds MQTT functionality to publish measured data to the MQTT broker. Especially, io.adafruit.com offers a free account, which is good enough for prototyping IoT device easily.

Prerequisites


- Arduino IDE
- Adafruit MQTT Library(We can install this from Library Manager in Arduino IDE)
ESP8266 package for Arduino IDE
- io.adafruit.com free account

Requirements


Hardware
-Wemos D1 mini : US$1.77 on Aliexpress
-PMS7003 air quality sensor : US$16.80 on Aliexpress

Instructions


Step 1. Setup hardware

PMS7003 sensor comes with a small breakout board, which has TX, RX, VCC, GND pins. Connect TX of PMS7003 to D5 of Wemos, RX to D6, VCC to 5V, and GND to G. Finally, connect micro usb to Wemos for uploading firmware, and check serial monitor and serial plotter in Android IDE to make sure the sensor works correctly.



Step 2. Create io.adafruit.com free account and feeds. Additionally, create a dashboard to show the value of feeds.

In this project, we will create  3 feeds. Each feed stores value for PM1.0, PM2.5, and PM10.0, respectively. We will use the 'Key' of each feed in our sketch to publish new value to MQTT broker.



After creating feeds, click 'AIO Key' menu to find out IO_USERNAME and IO_KEY value, which we will use in our sketch.

Step 3. Upload sketch to Wemos D1 mini

In the following sketch, four values need to be modified with your own.

- WIFI_SSID    : Name of WiFi router
- WIFI_PASS    : Password of WiFi router
- AIO_USERNAME : Value of 'IO_USERNAME' of MQTT broker
AIO_KEY      : Value of 'IO_KEY' of the MQTT broker

For WiFi feature, three functions are added to the sketch of our previous project.

- connectWifi() : Connect to WiFi router
- connectMQTT() : Connect to MQTT broker
publishMQTT() : Publish to MQTT broker


Results


After uploading firmware, Wemos restarts itself automatically. Once Wemos D1 mini has restarted, serial monitor shows air quality data from PMS7003 every 5 minutes. In the following serial console output, it shows MQTT server is connected and published 3 feeds successfully.




On MQTT broker website, we can check the data which is sent from device. In the menu, go 'Feeds', then, click the name of feed to see the line graph of published value.



Additionally, we can create a dashboard to display all related feeds in a single screen such as following screenshot. In the dashboard, it shows value of PM1.0, PM2.5 and PM10.0 altogether.



References


Source codes at github

No comments:

Post a Comment