
Air quality monitoring refers to collecting and measuring ambient air pollution samples. The harmful gases to be monitored include carbon monoxide (CO), nitrogen dioxide (NO₂), sulfur dioxide (SO₂), and particulate matter (PM).
In this article, we will discuss how to build an IoT air quality monitor from scratch by creating an example project.
In this article:
Part 1. Components for IoT Air Quality Monitoring Part 2. Schematic and PCB design for IoT Air Quality Monitoring Part 3: Codes for IoT Air Quality Monitoring Part 4: PCBA and Box-build Manufacturer for IoT Air Quality MonitorsComponents for IoT Air Quality Monitoring
The main components used in the example IoT air quality monitoring project in this article include the sensors, OLED, and MCU.
MG811 sensor detects the concentration of carbon dioxide in the air. It operates on low 3.3v. The onboard potentiometer/variable resistor is used for setting the sensitivity for the specific environment.

MQ9 carbon monoxide methane and LPG gas sensor operates on 3.3v and has single-wire communication. The resistance value of MQ-9 is different for different gases. So it needs sensitivity adjustment. You can calibrate the detector for 200ppm and 5000ppm CH4 or 1000ppm LPG concentration in air and use the Load resistance of about 20 KΩ (10KΩ to 47 KΩ).

In the MQ gas sensor series, the ppm is used to describe the performance of the sensor for the concentration.

For displaying the data we are using OLED 1.3". It is thin, has a color display, and uses inter-integrated communication protocol.
The microcontroller requires the use of WiFi to access the internet, so we will use the ESP32-S3, which has built-in WiFi as well as Bluetooth.

All the components used in the example IoT air quality monitoring project are below.
- ESP32-S3-MINI-1: Main microcontroller for IoT functionality (Wi-Fi, Bluetooth). It is compact, powerful, and integrates with various sensors.
- CH340G USB-to-UART converter: Facilitates USB programming and debugging. It is reliable, widely used, and KiCad-compatible.
- 40 MHz crystal (integrated): Provides clock signals for the ESP32 module. It is built-in, without a need for an external crystal.
- MQ-6 gas sensor: Detects air pollutants like LPG and methane. It is accurate gas sensing and easy interfacing via ADC.
- OLED SSD1351 display: Displays air quality index and sensor readings. It is compact, vibrant, and supports SPI.
- TP4056 battery charger: Manages Li-ion/LiPo battery charging. It is simple, cost-effective, and KiCad-compatible.
- AMS1117-3.3 voltage regulator: Converts battery voltage to stable 3.3V for components. It is low-cost and widely available.
- Capacitors (10 µF, 0.1 µF): Decoupling and power stability. It reduces noise and ensures stable operation.
- Resistors (10kΩ, 1kΩ): Pull-up for I2C and limiting current for LEDs. It ensures proper signal levels and protects components.
- LEDs (SMD 0805): Indicate power and system status, some LEDs are also connected to check the code is working.
- Micro-USB socket: Provides a USB interface for programming and power.
Schematic and PCB design for IoT Air Quality Monitoring
The schematic and the PCB layout can be designed in KiCAD. For the compact size and proper routing, two layers can be added.

In the above figure, the schematic has been shown. There is the microcontroller and sensors section, the voltage regulator section, the battery charging, the USB connector, and the USB to UART circuit. For sensors, the header pins have been added.

Due to the keep-out zone of ESP32, all the components have been placed on the top side and away from the keep-out zone.

The above image shows the vias between two layers, the top copper and the bottom copper.

The OLED is on the bottom side in the #D view, but it can be isolated from the main board and fitted according to the geometry and the dimensions of the casing. Similarly, sensors can also be isolated from the board. The connecting wires or the jumper wires can be used for this job.

The below image shows the vias.

The compact double-sided PCB design ensures the system is both versatile and professional.
Codes for IoT Air Quality Monitoring
Codes for building the example IoT air quality monitoring project are below.
Library and variable declarations:
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <WiFi.h>
#include <ThingSpeak.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET); // Initialize OLED
const char* ssid = "Your_SSID"; // Wi-Fi credentials
const char* password = "Your_PASSWORD";
WiFiClient client;
#define MQ135_PIN A0 // Pin for MQ-135 sensor
float sensorPPM = 0.0; // Variable for PPM value
Setup Function:
void setup() {
Serial.begin(115200);
// Initialize OLED
display.begin(SSD1306_I2C_ADDRESS, OLED_RESET);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Initializing...");
display.display();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to Wi-Fi...");
}
Serial.println("Connected to Wi-Fi!");
display.println("Wi-Fi Connected");
display.display();
ThingSpeak.begin(client); // Initialize ThingSpeak
}
Sensor reading block:
void readMQ135Sensor() {
int sensorValue = analogRead(MQ135_PIN); // Read MQ-135
float voltage = sensorValue * (5.0 / 1023.0); // Convert to voltage
sensorPPM = voltage * 100; // Estimate PPM (example)
Serial.print("MQ-135 PPM: ");
Serial.println(sensorPPM);
}
OLED display block:
void updateOLED() {
display.clearDisplay();
display.setCursor(0, 0);
display.println("Air Quality Monitor");
display.print("PPM: ");
display.println(sensorPPM);
display.display();
}
ThingSpeak upload block:
void uploadToThingSpeak() {
ThingSpeak.setField(1, sensorPPM); // Send PPM data
int response = ThingSpeak.writeFields(Your_Channel_ID, Your_API_Key);
if (response == 200) {
Serial.println("Data uploaded to ThingSpeak");
} else {
Serial.print("Error: ");
Serial.println(response);
}
}
Main loop:
oid loop() {
readMQ135Sensor(); // Read sensor
updateOLED(); // Update display
uploadToThingSpeak(); // Upload to ThingSpeak
delay(10000); // 10-second delay
}
The data will be logged on Google FireBase or ThingSpeak. The data will also be displayed on the onboard OLED (1.3 inches). In this way, one can check the Air Quality data on the device and the mobile phone.
PCBA and Box-build Manufacturer for IoT Air Quality Monitors
If you want to develop and manufacture any IoT air quality monitors under your brand or company name, work with the one-stop IoT PCBA manufacturer PCBONLINE with R&D and turnkey electronics manufacturing under one roof.
Founded in 1999, PCBONLINE has two large advanced PCB manufacturing bases, one PCB assembly factory, stable supply chains, and an R&D team. Besides, it has long-term cooperation with China's top 3 mold and enclosure factories for jigs and enclosures for PCB assembly and box-builds. What's more, PCBONLINE has strategic cooperation with mainstream microcontroller companies such as Espressif and Quectel.
PCBONLINE provides free design for manufacturing (DFM) and one-on-one engineering support for IoT air quality monitors and any IoT projects.
PCBONLINE has IoT project R&D capabilities and can do the R&D for your IoT air quality monitoring project or take part in your project's development from the early stage.
No worries about programming the MCU, as the one-stop PCBA manufacturer PCBONLINE offers free IC programming for you.
The IoT PCBs, PCBAs, and box-builds at PCBONLINE have gone through comprehensive tests, such as functional testing, 3D AOI, and application simulation testing.
High-quality IoT PCBA manufacturing certified with ISO 9001:2015, ISO 14001:2015, IATF 16949:2016, RoHS, REACH, UL, and IPC-A-610 Class 2/3.
When your IoT air quality monitoring and any other IOT project goes to bulky production, PCBONLINE refunds the fees of R&D, sampling, and PCBA functional testing. To get a quote for your IoT air quality monitor PCBA project, contact info@pcbonline.com.
Conclusion
By building an IoT-based air quality monitoring system, we can address air pollution and its impact on health. To develop and manufacture IoT air quality monitors and any other IoT devices, work with experienced experts like PCBONLINE to provide one-on-one engineering support and turnkey manufacturing.
PCB assembly at PCBONLINE.pdf