Monitoring air quality is crucial for various applications, from industrial safety to home automation. In this project, we will interface the MICS-6814 multi-gas sensor with the Carenuity C3 Mini, an ESP32-C3-based development board. We will read Carbon Monoxide (CO), Ammonia (NH₃), and Nitrogen Dioxide (NO₂) levels and display them on an OLED screen using the U8g2 library.
Why Choose Carenuity C3 Mini for this project?The Carenuity C3 Mini stands out among development boards, especially when compared to ESP8266 and similar platforms. Here’s why it’s the perfect choice:
- More Analog Pins: Unlike ESP8266, which has only one ADC pin, the ESP32-C3-based Carenuity C3 Mini provides multiple ADC pins, making it ideal for multi-sensor applications.
- Low Power Consumption: Efficient power management makes it perfect for battery-powered projects.
- Built-in Wi-Fi & Bluetooth LE: Supports both connectivity options, opening doors for cloud integration and remote monitoring.
- Compact & Reliable: The board’s small size makes it ideal for embedded applications without sacrificing performance.
- Strong Developer Support: Compatible with Arduino IDE, ESP-IDF, and PlatformIO, ensuring seamless development.
- Carenuity C3 Mini (ESP32-C3 based board)
- MICS-6814 Multi-Gas Sensor (CO: Carbon Monoxide detection NH₃: Ammonia detection NO₂: Nitrogen Dioxide detection)
- 0.96-inch OLED Display (SSD1306)
- Jumper Wires
- Power Supply
- Detects multiple gases including CO, NH₃, and NO₂.
- Provides analog outputs corresponding to gas concentrations.
- Requires proper preheating before stable readings.
- Based on ESP32-C3, a low-power RISC-V microcontroller.
- Supports Wi-Fi and Bluetooth LE.
- Provides multiple ADC pins, unlike ESP8266 which has only one.
- More stable GPIO arrangement for sensor interfacing.
- Compact design suited for IoT and embedded systems.
- Monochrome display with I2C interface.
- Ideal for displaying sensor data in a compact setup.
Before uploading the code, ensure your Arduino IDE is properly set up for ESP32-C3 Mini:
Install ESP32 Board Package
- Open Arduino IDE and go to Preferences.
- Add the following URL to Additional Board Manager URLs:
https://dl.espressif.com/dl/package_esp32_index.json
- Open Boards Manager (Tools > Board > Boards Manager), search for ESP32, and install the package by Espressif.
Install ESP32 Board Package
Open Arduino IDE and go to Preferences.
Add the following URL to Additional Board Manager URLs: https://dl.espressif.com/dl/package_esp32_index.json
Open Boards Manager (Tools > Board > Boards Manager), search for ESP32, and install the package by Espressif.
Select the Correct Board
- Go to Tools > Board and select Lolin-
C3 Mini
. - Set the correct COM port under Tools > Port.
- Install Required LibrariesOpen Library Manager (Sketch > Include Library > Manage Libraries).Search and install
U8g2
for OLED display support.
Code Implementation
1. Include Required Libraries#include <Wire.h>
#include <U8g2lib.h>
This includes the necessary libraries for I2C communication and OLED display control.
2. Define Sensor Pins and Initialize OLED Display#define CO_SENSOR_PIN 0
#define NH3_SENSOR_PIN 1
#define NO2_SENSOR_PIN 2
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 7, /* data=*/ 6, /* reset=*/ U8X8_PIN_NONE);
This defines the gas sensor pins and initializes the OLED display using the U8g2 library.
3. Setup Functionvoid setup() {
Serial.begin(115200);
u8g2.begin();
}
Initializes the serial communication for debugging and starts the OLED display.
4. Read Sensor Data and Display on OLEDvoid loop() {
int co = analogRead(CO_SENSOR_PIN);
int nh3 = analogRead(NH3_SENSOR_PIN);
int no2 = analogRead(NO2_SENSOR_PIN);
Reads analog values from the gas sensors.
Serial.print("CO: "); Serial.print(co); Serial.println(" ppm");
Serial.print("NH3: "); Serial.print(nh3); Serial.println(" ppm");
Serial.print("NO2: "); Serial.print(no2); Serial.println(" ppm");
Prints the sensor values to the serial monitor.
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(0, 10, "Gas Readings:");
u8g2.setCursor(0, 30);
u8g2.print("CO: "); u8g2.print(co); u8g2.print(" ppm");
u8g2.setCursor(0, 45);
u8g2.print("NH3: "); u8g2.print(nh3); u8g2.print(" ppm");
u8g2.setCursor(0, 60);
u8g2.print("NO2: "); u8g2.print(no2); u8g2.print(" ppm");
u8g2.sendBuffer();
delay(2000);
}
Updates the OLED display with real-time gas sensor readings.
Each gas sensor has variations in readings due to environmental conditions. It is recommended that users:
- Calibrate the sensor with reference gas concentrations for accurate results.
- Use moving averages to smooth out readings.
- Adjust thresholds based on real-world conditions for precise detection.
This project successfully interfaces the MICS-6814 multi-gas sensor with the Carenuity C3 Mini and displays real-time gas concentration levels on an OLED screen. The Carenuity C3 Mini’s multiple ADC pins, Wi-Fi & Bluetooth LE, and compact design make it an excellent choice for embedded IoT applications. This setup can be expanded with data logging, MQTT integration, or cloud-based monitoring in future iterations, making it a powerful tool for air quality analysis.
Comments
Please log in or sign up to comment.