Skip to main content

Microchip PIC-IoT Wx-Based Indoor Air Monitoring Design

By Chris Mao, Mouser Electronics

(Image source: suebsiri/stock.adobe.com)

Introduction


According to a study by the World Health Organization1, indoor air pollution is estimated to be responsible for the loss of 86 million healthy life years, with 3.2 million people succumbing every year to diseases caused by indoor air pollution. With people spending an average of 80 percent of their lives indoors2, proper ventilation and filtering are critical, as even slightly poor indoor air quality can lead to headaches, fatigue, and lack of concentration.

This project presents an IoT-based indoor air monitoring system that consists of the Microchip Technology PIC-IoT WG development board, a temperature and humidity sensor, a particulate matter (PM) sensor, and an equivalent carbon dioxide (eCO2) and total volatile organic compounds (TVOC) sensor. The monitoring system then uploads the detected gas composition parameters to the Microsoft Azure IoT Hub through 2.4G wireless connectivity. The resulting changing trends in air quality can then be viewed through a mobile app or a computer client.

Note: This project and article were created before Microchip listed the PIC-IoT WG development board as obsolete. The PIC-IoT WA development board is a suitable replacement board for this project.

Project Background and Significance


With the advancement of smart and digital construction, indoor air quality control is not just a "pure detection" project but also requires automated, intelligent, and networked interactive pages, data management, and analysis.

Many countries use air quality indices (AQIs) to report the amount of TVOCs, eCO2, and PM in the air. The higher the AQI value, the higher the air pollution level and the greater the impact on our health. According to the standards of the US Environmental Protection Agency's AirNow.gov, the AQI index can be divided into six levels (Table 1):

AQI

Air Pollution Level

AQI Category and Color

Health Implications

Recommended Precautions

0~50

Level 1

Excellent

Green

Air quality is satisfactory and there is no air pollution.

Everyone can continue their outdoor activities normally.

51~100

Level 2

Good

Yellow

Air quality is acceptable, but some pollutants may slightly affect very few hypersensitive individuals.

Only very few hypersensitive people should reduce outdoor activities.

101~150

Level 3

Lightly Polluted

Orange

Healthy people may experience slight irritations and sensitive individuals will be slightly affected to a larger extent.

Children, seniors, and individuals with respiratory or heart diseases should reduce sustained and high-intensity outdoor exercises.

151~200

Level 4

Moderately Polluted

Red

Sensitive individuals will experience more severe conditions. The hearts and respiratory systems of healthy people may be affected.

Children, seniors, and individuals with respiratory or heart diseases should avoid sustained, high-intensity outdoor exercises. The general population should moderately reduce outdoor activities.

201~300

Level 5

Heavily Polluted

Purple

Healthy people will commonly show symptoms. People with respiratory or heart diseases will be significantly affected and experience reduced activity endurance.

Children, seniors, and individuals with heart or lung diseases should stay indoors and avoid outdoor activities. The general population should reduce outdoor activities.

>300

Level 6

Severely Polluted

Maroon

Healthy people will experience reduced endurance in activities and may also show noticeably strong symptoms. Other illnesses may be triggered in healthy people.

Children, seniors, and the sick should stay indoors and avoid physical exertion. The general population should avoid outdoor activities

Table 1: Classification of Air Quality Index (Source: AirNow.gov; Adapted by Mouser Electronics)

Project Materials and Resources


Project Bill of Materials

Software Development Tools

Additional Hardware

  • Windows-based PC
  • Jumper wires (male-to-female)

Project Technology Overview


The Microchip PIC-IoT WG Development Board (Figure 1) provides the simplest and most efficient way to connect embedded applications to the cloud IoT core by combining the powerful PIC24FJ128GA705 microcontroller (MCU), ATECC608A CryptoAuthentication™ secure element IC, and fully certified ATWINC1510 Wi-Fi® network controller. The board also includes an on-board debugger to program and debug the MCU without needing external hardware.


 
Figure 1: Microchip Technology PIC-IoT WG Development Board. Note that the PIC-IoT WA board contains the same features. (Source: Mouser Electronics)

The ATECC608A is a Secure Element from the Microchip CryptoAuthentication portfolio with advanced Elliptic Curve Cryptography (ECC) capabilities. The ATECC608A can manage private and public keys for secure IoT communications. The ATECC608A communicates with the MCU through the I²C interface.

The ATWINC1510 Wi-Fi module is a low-power IEEE 802.11 b/g/n IoT module optimized for low-power IoT applications. The mikroBUS™ socket can be used to extend the functionality of the development kit with Mikroe Click boards and other mikroBUS add-on boards.

The Adafruit SGP30 Air Quality Sensor Breakout – VOC and eCO2 (Figure 2) incorporates a fully integrated MOX gas sensor from Sensirion that can be used to read the concentration of TVOC and eCO2 through an I2C interface, with a measurement accuracy of 15 percent.


 
Figure 2: Adafruit SGP30 Air Quality Sensor Breakout – VOC and eCO2 (Source: Mouser Electronics)

The Mikroe Temp&Hum 18 Click (Figure 3) integrates the Renesas HS3003 high-precision, fully calibrated relative humidity (RH) and temperature sensor. The Temp&Hum 18 Click provides fully corrected RH and temperature values via an I²C interface.


 
Figure 3: Mikroe Temp&Hum 18 Click. (Source: Mouser Electronics)

The Mikroe OLED B Click (Figure 4) features a 19.3mm × 7.8mm, 96×39px light blue monochrome passive matrix OLED display with an integrated SSD1306 OLED controller. Functions include contrast control, normal or reverse scan image display, vertical and horizontal scrolling functions, and much more accessible through the I²C serial interface.

 
Figure 4: Mikroe OLED B Click. (Source: Mouser Electronics)

The Sensirion SPS30 (Figure 5) marks a technological breakthrough in optical PM sensors. Its measurement principle is based on laser scattering and uses Sensirion’s innovative contamination-resistance technology. This technology, together with high-quality and long-lasting components, enables precise measurements from the device’s first operation throughout its lifetime. The SPS30 provides UART and I²C interface options.

 
Figure 5: Sensirion SPS30 PM sensor. (Source: Mouser Electronics)

Mikroe’s MIKROE-2880 Shuttle click board (Figure 6) is an expansion board that enables designers to stack up to four Click boards on a single mikroBUS socket. When combined with the Mikroe MIKROE-2882 mikroBUS Shuttle boards (Figure 7), it allows designers to expand the development system’s capacity.

 
Figure 6: Mikroe MIKROE-2880 Shuttle Click Board (Source: Mouser Electronics)

 
Figure 7: Mikroe MIKROE-2882 mikroBUS shuttle (Source: Mouser Electronics)

Microchip Technology MPLAB X integrated development environment (IDE) is an extensible, highly adjustable software program. It allows designers to explore, configure, develop, and debug most projects based on Microchip microcontrollers and data signal controllers.

Azure IoT Central is an IoT application platform that reduces the burden and cost of developing, managing, and maintaining enterprise-grade IoT solutions. Through the web UI, designers can connect devices, monitor device conditions, create rules, and manage millions of devices and their data throughout the device's lifecycle.

Software Configuration and Design


The following sections will guide readers through the process of developing the embedded software for the indoor air monitoring system:

Create a New Project in MPLAB X
Download and install the Microchip MPLAB X IDE and XC16 compiler. Then, use the following steps to create a new project.

  1. Connect the Microchip PIC-IoT WG development board to the computer using a Micro-USB cable.
  2. Click File, then click New Project.
  3. Click the Microchip Embedded folder, select Standalone Project (Figure 8), and click Next.

 
Figure 8: New Project window in MPLAB X IDE. (Source: Mouser Electronics)

4.    From the Device dropdown menu, select PIC24FJ128GA705.
5.    From the Tool dropdown menu, select the PIC-IoT WG-SN: debug tool (or the PIC-IoT WA-SN: debug tool if using that board), and then click Next.
 
Figure 9: Select Device window in MPLAB X IDE. (Source: Mouser Electronics)

6.    Select the XC16 compiler, and then click Next.
 
Figure 10: Select Compiler window in MPLAB X IDE. (Source: Mouser Electronics)

7.    Enter the project name, confirm the project location, and click Finish to create the project.
 
Figure 11: MPLAB X IDE project window. (Source: Mouser Electronics)

MPLAB Code Configurator
MPLAB Code Configurator (MCC) is a graphical programming environment that enables and configures a rich set of peripherals and functions specific to the application. To open the MCC, click the blue MCC icon in the MPLAB X toolbar at the top of the window.

MCC settings include the following:

  • System Module: Sets the project's clock, debugger interface (ICD), and watchdog.
  • Grid View Pin Manager and Pin Module assignment (Figure 12): Set the pin assignment of I2C1, I2C2, SPI1, and UART2 interface protocols (For more information, refer to the PIC-IoT WG Development User Guide).

 
Figure 12: Pin Manager window in MCC. (Source: Mouser Electronics)

  • WINC: Sets the SSID, password, and authentication type of the Wi-Fi network.
  • CryptoAuthLib: A cryptographic authentication library that the user cannot modify.
  • Cloud Services: Set up connections to cloud services.
  • Message Queuing Telemetry Transport (MQTT): MQTT is a messaging protocol that runs over TCP/UDP connections to transfer data between clients and a broker over the cloud.

How to go about the MCC settings? You need to refer to the circuit schematic in the PIC-IoT WG Development User Guide). The following are the interfaces that need to be set up for this project.

  1.  Assign RB14 to ANx for Mikroe sensor data acquisition.
  2. Assign RB8 to SCL1 and RB9 to SDA1 for the I²C interface on the mikroBUS socket.
  3. Assign RB3 to SCL2 and RB2 to SDA2 for I²C communication between the ATECC608A Secure Element and the MCU.
  4. Assign RB11 to PGCx and RB10 to PGDx for debugging channels of the PC and the development board.
  5. Assign RC2 to SCK1OUT, RA13 to SDI1, and RC0 to SDO1 for SPI communication between the wireless module and the MCU.
  6.  Assign RB6 to U2RX and RB5 to U2TX for the UART interface on the mikroBUS socket.

After completing the MCC settings, click Generate to generate the corresponding code (Figure 13).

 
Figure 13: In the MCC configuration window, click Generate to generate the corresponding code. (Source: Mouser Electronics)

Connect the PIC-IoT Board to Azure IoT Central
Utilizing Microsoft's Azure IoT Embedded C SDK to connect the PIC-IoT WG board to Azure IoT Hub (Figure 14), the PIC-IoT WG board, configured for Azure IoT services using self-signed X.509 certificate-based authentication. For details, please refer to Azure IoT PnP User Guide [PIC-IoT].


 
Figure 14: Communication method between PIC-IoT and Azure IoT. (Source: Microchip Technology)

System Debugging and Verification


After setting up the software environment, connect the hardware. Figure 15 shows the overall system scheme diagram.


 
Figure 15: System scheme diagram. (Source: Mouser Electronics)

Hardware Settings
The hardware connection setup is very simple, requiring no soldering.

  1. Connect the Mikroe Temp&Hum 18 Click and the Mikroe OLED B Click to the Mikroe MIKROE-2882 mikroBUS socket. To ensure a correct connection, align the 3V3 pin of the Click board with the 3V3 pin of the mikroBUS socket.
  2. Connect the Sensirion SPS30 PM Sensor and the Adafruit SGP30 Air Quality Sensor Breakout board to the Mikroe MIKROE-2882 mikroBUS socket using jumper wires. Figure 16 shows the Sensirion SPS30 pinouts.

Figure 16: Sensirion SPS30 module pinout list. (Source: Sensirion)

3.    Connect the Sensirion SPS30 PM sensor to the Mikroe MIKROE-2882:
       a.    VDD to +5V
       b.    RX(SDA) to RX
       c.    TX(SCL) to TX
      d.    SEL is floating
      e.    GND to GND

4.    Connect the Adafruit SGP30 Air Quality Sensor Breakout board to the Mikroe MIKROE-2882:
     a.    VIN to +3.3V
     b.    GND to GND
     c.    SCL to SCL
     d.    SDA to SDA

Figure 17 shows the completed hardware connection:
 
Figure 17: hardware connection for air quality detection (Source: Mouser Electronics)

Software Flow
Navigate to the Mouser Electronics GitHub for the program source code. Figure 18 shows the flowchart of the software logic.


 
Figure 18: Project software flow. (Source: Mouser Electronics)

In this application, the MCU monitors critical air pollutants, processes the readings, calculates the AQI based on the PM2.5 sensor readings, and displays these parameters on the OLED B Click board (Figure 19).

 
Figure 19: Parameter data displayed on the OLED B Click board. (Source: Mouser Electronics)

If you connected the board to the internet, the AQI and other parameters will be uploaded to the Azure IoT center, which will plot the change curve (Figure 20).

 
Figure 20: Azure cloud data curves. (Source: Mouser Electronics)

Conclusion


Indoor air quality is increasingly important as populations spend an increasingly longer time inside. Proper ventilation and filtering are critical, as even slightly poor indoor air quality can lead to headaches, fatigue, and lack of concentration.

This project presented an IoT-based indoor air monitoring system based on the Microchip Technology PIC-IoT WG development board and a series of sensors. Beyond this project, indoor air quality monitoring can be used in air purifiers, air conditioners, humidifiers, kitchen and bathroom ventilation control systems, and more. The system's data can provide effective data support as an indispensable part of a smart home system.


 

1 “Household Air Pollution,” World Health Organization, November 28, 2022, https://www.who.int/news-room/fact-sheets/detail/household-air-pollution-and-health.

2 Judith A. Leech et al., “It’s about Time: A Comparison of Canadian and American Time–Activity Patterns,” Journal of Exposure Science & Environmental Epidemiology 12 (November 4, 2002): 427–432, https://doi.org/10.1038/sj.jea.7500244.

About the Author

Chris Mao joined Mouser Electronics in 2023 as a Technical Marketing Engineer for the APAC region. Prior to joining Mouser, he worked as a Field Application Engineer, where he was responsible for IP verification and providing technical support for display driver chips. During his free time, he enjoys traveling and photography. He holds a degree in Measurement and Control Technology from Henan University of Technology.

Profile Photo of Chris Mao