Sunday, March 12, 2023

Teensy 4.1 with ENS160 Air Quality Sensor

Overview

The ENS160 air quality sensor outputs data for air quality index (1-5), total volatile organic compounds (in ppb) and CO2 concentration (in ppm). The code uses the Sparkfun ENS160 library, which can be downloaded from within the Arduino IDE. 


Hardware







The following connections should be made between the Teensy 4.1 and the ENS160:
  • Teensy 4.1 3V to ENS160 VCC - red in the above photo
  • Teensy 4.1 ground to ENS160 GND - blue in the above photo
  • Teensy 4.1 pin 19 / A5 / SCL / PWM to ENS160 SCL - green in the above photo
  • Teensy 4.1 pin 18 / A4 / SDA / PWM to ENS160 SDA - white in the above photo


Software

#include <Wire.h>
#include "SparkFun_ENS160.h"

SparkFun_ENS160 myENS;

int ensStatus;

void setup()
{
Wire.begin();
Serial.begin(115200);

if( !myENS.begin() )
{
Serial.println("Did not begin.");
while(1);
}

if( myENS.setOperatingMode(SFE_ENS160_RESET) )
Serial.println("Ready.");
delay(100);

myENS.setOperatingMode(SFE_ENS160_STANDARD);

ensStatus = myENS.getFlags();
Serial.print("Gas Sensor Status Flag: ");
Serial.println(ensStatus);
}

void loop()
{
if( myENS.checkDataStatus() )
{
Serial.print("Air Quality Index (1-5) : ");
Serial.println(myENS.getAQI());

Serial.print("Total Volatile Organic Compounds: ");
Serial.print(myENS.getTVOC());
Serial.println("ppb");

Serial.print("CO2 concentration: ");
Serial.print(myENS.getECO2());
Serial.println("ppm");
}

delay(200);
}

No comments:

Post a Comment