Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
TIMOTHY MWALA
Published © GPL3+

Interfacing MICS-6814 Multi-Gas Sensor with ESP32-C3 Mini

Monitoring air quality is crucial for our health and various applications, from industrial safety to home automation.

BeginnerFull instructions provided1 hour249
Interfacing MICS-6814 Multi-Gas Sensor with ESP32-C3 Mini

Things used in this project

Hardware components

Carenuity C3-Mini
×1
0.96 OLED DISPLAY
×1
Bread Board
×1
MICS-6814 sensor
×1
Maker Essentials - Mini Breadboards & Jumper Jerky
Pimoroni Maker Essentials - Mini Breadboards & Jumper Jerky
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

ESP32-C3-Mini Multi-Gas Sensor Monitor with OLED Display Arduino Code

C/C++
Consider using calibration gases with known concentrations or professional air quality monitors to compare and fine-tune the scaling factors for precise calibration.
#include <Wire.h>
#include <U8g2lib.h>

// Initialize OLED (Set correct I2C address & SDA/SCL pins)
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// Define gas sensor pins (Analog Inputs)
#define CO_SENSOR_PIN A0   // GPIO 0
#define NH3_SENSOR_PIN A1  // GPIO 1
#define NO2_SENSOR_PIN A2  // GPIO 2

// Define the scaling factors based on known normal concentrations
float CO_SCALE = 0.1;  // Scaling factor for CO (to bring it closer to normal ppm values)
float NH3_SCALE = 0.1; // Scaling factor for NH₃
float NO2_SCALE = 0.01; // Scaling factor for NO₂

void setup() {
    Serial.begin(115200);
    u8g2.begin();
}

void loop() {
    // Read sensor values
    int co_raw = analogRead(CO_SENSOR_PIN);
    int nh3_raw = analogRead(NH3_SENSOR_PIN);
    int no2_raw = analogRead(NO2_SENSOR_PIN);

    // Convert raw ADC values to PPM using scaling factors
    float co_ppm = (co_raw / 1024.0) * 1000 * CO_SCALE;  // Apply scaling factor to CO
    float nh3_ppm = (nh3_raw / 1024.0) * 500 * NH3_SCALE; // Apply scaling factor to NH₃
    float no2_ppm = (no2_raw / 1024.0) * 200 * NO2_SCALE; // Apply scaling factor to NO₂

    // Print to Serial Monitor
    Serial.print("CO: "); Serial.print(co_ppm); Serial.println(" PPM");
    Serial.print("NH3: "); Serial.print(nh3_ppm); Serial.println(" PPM");
    Serial.print("NO2: "); Serial.print(no2_ppm); Serial.println(" PPM");
    Serial.println("----------------------");

    // Display on OLED
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr); // Set font

    u8g2.drawStr(10, 10, "Gas Sensor Readings:");
    char co_text[20], nh3_text[20], no2_text[20];
    sprintf(co_text, "CO: %.2f PPM", co_ppm);
    sprintf(nh3_text, "NH3: %.2f PPM", nh3_ppm);
    sprintf(no2_text, "NO2: %.2f PPM", no2_ppm);

    u8g2.drawStr(10, 25, co_text);
    u8g2.drawStr(10, 40, nh3_text);
    u8g2.drawStr(10, 55, no2_text);
    
    u8g2.sendBuffer(); // Send data to OLED
    
    delay(2000);  // Wait before next reading
}

Credits

TIMOTHY MWALA
29 projects • 17 followers
I am an Embedded engineer who like prototyping
Contact

Comments

Please log in or sign up to comment.