Gas Sensor ESP32-C6 — Xiao Esp32C6 simulation

Grove Multichannel Gas Sensor V2 with XIAO ESP32-C6

An interactive Xiao Esp32C6 circuit simulation you can run free in your browser on Velxio, by itsmebenn.

Components

Sketch code

// Grove - Multichannel Gas Sensor v2 on XIAO ESP32-C6
// Adapted from the Seeed wiki (MIT). SDA -> D4 (GPIO22), SCL -> D5 (GPIO23).
// #include <Wire.h>

// const uint8_t ADDR = 0x08;

// uint32_t channel(uint8_t command) {
//   Wire.beginTransmission(ADDR);
//   Wire.write(command);
//   Wire.endTransmission();
//   delay(2);
//   Wire.requestFrom(ADDR, (uint8_t)4);
//   uint32_t v = Wire.read();
//   v |= (uint32_t)Wire.read() << 8;
//   v |= (uint32_t)Wire.read() << 16;
//   v |= (uint32_t)Wire.read() << 24;
//   return v;
// }

// void setup() {
//   Serial.begin(115200);
//   Wire.begin(22, 23);
//   Wire.beginTransmission(ADDR);
//   Wire.write(0x21);                    // heaters on
//   Wire.endTransmission();
// }

// void loop() {
//   Serial.print("NO2 "); Serial.print(channel(0x01));
//   Serial.print("  ethanol "); Serial.print(channel(0x03));
//   Serial.print("  VOC "); Serial.print(channel(0x05));
//   Serial.print("  CO "); Serial.println(channel(0x07));
//   delay(1000);
// }
#include <Wire.h>
#include "MutichannelGasSensor.h"

MultichannelGasSensor gas;

void setup() {
  Serial.begin(115200);
  while (!Serial); // Wait for Serial Monitor to open

  Serial.println("Initializing I2C...");
  Wire.begin(22, 23); // Explicitly define ESP32 I2C pins (SDA, SCL)

  // Initialize sensor (Default I2C address is 0x08)
  gas.begin(Wire, 0x08); 
  
  // Power up the internal heater elements
  gas.changeGM102B(1);
  gas.changeGM302B(1);
  gas.changeGM502B(1);
  gas.changeGM702B(1);
  
  Serial.println("Sensor initialized. Warming up...");
}

void loop() {
  // Read raw ADC values (0 - 1023)
  uint16_t gm102 = gas.getGM102B(); // CO / Reducing gases
  uint16_t gm302 = gas.getGM302B(); // NO2 / Oxidizing gases
  uint16_t gm502 = gas.getGM502B(); // C2H5OH / Alcohol
  uint16_t gm702 = gas.getGM702B(); // VOCs

  // Print results
  Serial.print("GM102 (CO): "); Serial.print(gm102);
  Serial.print(" | GM302 (NO2): "); Serial.print(gm302);
  Serial.print(" | GM502 (Alcohol): "); Serial.print(gm502);
  Serial.print(" | GM702 (VOC): "); Serial.println(gm702);

  delay(2000); // Read every 2 seconds
}

More projects by itsmebenn