Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Infineon Team
Published © MIT

CO2 Warning Light based on XMC and Arduino

Real-Time CO2 Monitoring with Light Indicator Using PAS CO2 Shield2Go and XMC1100 Boot Kit.

BeginnerFull instructions provided30 minutes312
CO2 Warning Light based on XMC and Arduino

Things used in this project

Hardware components

XENSIV™ PAS CO2 Shield2Go Board
Infineon XENSIV™ PAS CO2 Shield2Go Board
×1
Boot Kit XMC1100 (Arduino shield compatible)
Infineon Boot Kit XMC1100 (Arduino shield compatible)
×1
My IOT Adapter
Infineon My IOT Adapter
×1
LED Ring
×1
Micro USB Cable
×1
Power Supply
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Base

Sketchfab still processing.

Cover

Sketchfab still processing.

Cover

Sketchfab still processing.

Code

CO2 LIGHT

Arduino
#include <Arduino.h>

/* Import required libraries for CO2 sensor and LEDs */
#include <pas-co2-ino.hpp>
#include <Adafruit_NeoPixel.h>

/* ### CO2 Sensor ### */
/* Set parameters of CO2 sensor (copied from library example) */
#define CO2_I2C_FREQ_HZ 400000
#define CO2_DEMO_MEAS_INTERVAL_IN_SECONDS 10 /* demo-mode value; not recommended for long-term measurements */
#define CO2_STABLE_MEAS_INTERVAL_IN_SECONDS 60L /* specification value for stable operation (uncomment for long-time-measurements) */
#define CO2_SWITCH_OP_MODE_AFTER_SEC 180L

uint32_t co2_meas_interval = CO2_DEMO_MEAS_INTERVAL_IN_SECONDS; /* Start measure interval in demo mode. */

/* Prepare CO2 sensor library */
PASCO2Ino cotwo;
int16_t co2ppm;
Error_t ret;

/* ### Smart LEDs ### */
/* Set parameters of smart LEDs */
#define LED_PIN 3
#define LED_MAX_BRIGHTNESS 255
#define LED_COUNT 8

/* Prepare smart LED library */
Adafruit_NeoPixel leds(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

/* Helper function for setting LED ring color */
void setLEDColor(uint32_t color) {
  leds.fill(color);
  leds.show();
}

void setup() {
  /* Initialize serial interface, so measurement values can be printed to PC when connected. */
  Serial.begin(9600);
  delay(500);
  Serial.println("Serial initialized");

  /* Initialize the i2c interface used by the CO2 sensor */
  Wire.begin();
  Wire.setClock(CO2_I2C_FREQ_HZ);

  /* Initialize the CO2 sensor */
  ret = cotwo.begin();

  /* Error handling (in case of init error). */
  if (ret != XENSIV_PASCO2_OK) {
    Serial.print("initialization error: ");
    Serial.println(ret);
  }

  /* Initialize the smart LEDs and set to dim white*/


  leds.begin();  // INITIALIZE NeoPixel strip object (REQUIRED)
  leds.setBrightness(LED_MAX_BRIGHTNESS);
  setLEDColor(leds.Color(50, 50, 50));
}

void loop() {

  /* Trigger a measurement */
  ret = cotwo.startMeasure();

  /* Error handling (in case of measurement error). */
  if (ret != XENSIV_PASCO2_OK) {
    Serial.print("error: ");
    Serial.println(ret);
    setLEDColor(leds.Color(50, 50, 50));
  }

  /* 
  * Wait for the specified delay time.
  * This ensures:
  * - stable operation (>=60s measure interval during continues operation)
  * - readyness of the measurement when we recall it
  */
  delay(co2_meas_interval * 1000);

  ret = cotwo.getCO2(co2ppm);

  /* Error handling (in case of measurement error). */
  if (ret != XENSIV_PASCO2_OK) {
    Serial.print("error: ");
    Serial.println(ret);
    setLEDColor(leds.Color(50, 50, 50));
  }

  /* Print measurement result to serial interface (PC)... */
  Serial.print("CO2 measurement: ");
  Serial.print(co2ppm);
  Serial.println(" ppm");

  /* ...and set LED color according to CO2 limit. */
  if (co2ppm == 0) {
    // 0 ppm / No value: WHITE
    setLEDColor(leds.Color(50, 50, 50));
  } else if (co2ppm < 1000) {
    // Under 1000 ppm: GREEN
    setLEDColor(leds.Color(0, 180, 0));
  } else if (co2ppm < 1800) {
    // 1000-1799 ppm: YELLOW
    setLEDColor(leds.Color(200, 200, 0));
  } else if (co2ppm < 2800) {
    // 1800-2799 ppm: RED
    setLEDColor(leds.Color(255, 0, 0));
  } else {
    // More than 2800 ppm: RED and flashing
    for (uint8_t i = 0; i < 10; i++) {
      setLEDColor(leds.Color(0, 0, 0));
      delay(50);
      setLEDColor(leds.Color(255, 0, 0));
      delay(50);
    }
  }

  /* Switch from demo mode to stable operation mode after certain time */
  if (millis() > 1000L * CO2_SWITCH_OP_MODE_AFTER_SEC) {
    co2_meas_interval = 60;
  }
}

Credits

Infineon Team
102 projects • 165 followers
Contact

Comments

Please log in or sign up to comment.