Using the SEN5x adapter breakout with Arduino involves wiring up the adapter with a SEN5x sensor to your Arduino-compatible microcontroller, installing the Sensirion I2C SEN5X library, and running the provided example code.
This board does NOT come with a JST GH-compatible cable NOR a SEN5x sensor! You can pick up the cable here and a SEN5x from DigiKey.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout using the STEMMA QT connector:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
- SEN5x sensor to breakout JST GH port
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
- SEN5x sensor to breakout JST GH port
Library Installation
You can install the Sensirion I2C SEN5X library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Sensirion SEN5x, and select the Sensirion I2C SEN5X library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!
/* * I2C-Generator: 0.3.0 * Yaml Version: 2.1.3 * Template Version: 0.7.0-112-g190ecaa */ /* * Copyright (c) 2021, Sensirion AG * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name of Sensirion AG nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <Arduino.h> #include <SensirionI2CSen5x.h> #include <Wire.h> // The used commands use up to 48 bytes. On some Arduino's the default buffer // space is not large enough #define MAXBUF_REQUIREMENT 48 #if (defined(I2C_BUFFER_LENGTH) && \ (I2C_BUFFER_LENGTH >= MAXBUF_REQUIREMENT)) || \ (defined(BUFFER_LENGTH) && BUFFER_LENGTH >= MAXBUF_REQUIREMENT) #define USE_PRODUCT_INFO #endif SensirionI2CSen5x sen5x; void printModuleVersions() { uint16_t error; char errorMessage[256]; unsigned char productName[32]; uint8_t productNameSize = 32; error = sen5x.getProductName(productName, productNameSize); if (error) { Serial.print("Error trying to execute getProductName(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } else { Serial.print("ProductName:"); Serial.println((char*)productName); } uint8_t firmwareMajor; uint8_t firmwareMinor; bool firmwareDebug; uint8_t hardwareMajor; uint8_t hardwareMinor; uint8_t protocolMajor; uint8_t protocolMinor; error = sen5x.getVersion(firmwareMajor, firmwareMinor, firmwareDebug, hardwareMajor, hardwareMinor, protocolMajor, protocolMinor); if (error) { Serial.print("Error trying to execute getVersion(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } else { Serial.print("Firmware: "); Serial.print(firmwareMajor); Serial.print("."); Serial.print(firmwareMinor); Serial.print(", "); Serial.print("Hardware: "); Serial.print(hardwareMajor); Serial.print("."); Serial.println(hardwareMinor); } } void printSerialNumber() { uint16_t error; char errorMessage[256]; unsigned char serialNumber[32]; uint8_t serialNumberSize = 32; error = sen5x.getSerialNumber(serialNumber, serialNumberSize); if (error) { Serial.print("Error trying to execute getSerialNumber(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } else { Serial.print("SerialNumber:"); Serial.println((char*)serialNumber); } } void setup() { Serial.begin(115200); while (!Serial) { delay(100); } Wire.begin(); sen5x.begin(Wire); uint16_t error; char errorMessage[256]; error = sen5x.deviceReset(); if (error) { Serial.print("Error trying to execute deviceReset(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } // Print SEN55 module information if i2c buffers are large enough #ifdef USE_PRODUCT_INFO printSerialNumber(); printModuleVersions(); #endif // set a temperature offset in degrees celsius // Note: supported by SEN54 and SEN55 sensors // By default, the temperature and humidity outputs from the sensor // are compensated for the modules self-heating. If the module is // designed into a device, the temperature compensation might need // to be adapted to incorporate the change in thermal coupling and // self-heating of other device components. // // A guide to achieve optimal performance, including references // to mechanical design-in examples can be found in the app note // “SEN5x – Temperature Compensation Instruction” at www.sensirion.com. // Please refer to those application notes for further information // on the advanced compensation settings used // in `setTemperatureOffsetParameters`, `setWarmStartParameter` and // `setRhtAccelerationMode`. // // Adjust tempOffset to account for additional temperature offsets // exceeding the SEN module's self heating. float tempOffset = 0.0; error = sen5x.setTemperatureOffsetSimple(tempOffset); if (error) { Serial.print("Error trying to execute setTemperatureOffsetSimple(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } else { Serial.print("Temperature Offset set to "); Serial.print(tempOffset); Serial.println(" deg. Celsius (SEN54/SEN55 only"); } // Start Measurement error = sen5x.startMeasurement(); if (error) { Serial.print("Error trying to execute startMeasurement(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } } void loop() { uint16_t error; char errorMessage[256]; delay(1000); // Read Measurement float massConcentrationPm1p0; float massConcentrationPm2p5; float massConcentrationPm4p0; float massConcentrationPm10p0; float ambientHumidity; float ambientTemperature; float vocIndex; float noxIndex; error = sen5x.readMeasuredValues( massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex, noxIndex); if (error) { Serial.print("Error trying to execute readMeasuredValues(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } else { Serial.print("MassConcentrationPm1p0:"); Serial.print(massConcentrationPm1p0); Serial.print("\t"); Serial.print("MassConcentrationPm2p5:"); Serial.print(massConcentrationPm2p5); Serial.print("\t"); Serial.print("MassConcentrationPm4p0:"); Serial.print(massConcentrationPm4p0); Serial.print("\t"); Serial.print("MassConcentrationPm10p0:"); Serial.print(massConcentrationPm10p0); Serial.print("\t"); Serial.print("AmbientHumidity:"); if (isnan(ambientHumidity)) { Serial.print("n/a"); } else { Serial.print(ambientHumidity); } Serial.print("\t"); Serial.print("AmbientTemperature:"); if (isnan(ambientTemperature)) { Serial.print("n/a"); } else { Serial.print(ambientTemperature); } Serial.print("\t"); Serial.print("VocIndex:"); if (isnan(vocIndex)) { Serial.print("n/a"); } else { Serial.print(vocIndex); } Serial.print("\t"); Serial.print("NoxIndex:"); if (isnan(noxIndex)) { Serial.println("n/a"); } else { Serial.println(noxIndex); } } }
The Sensirion I2C SEN5X library has an example to read all of the available data from the SEN5x sensor over I2C. Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the PM1.0, PM2.5, PM4.0, PM10.0, humidity, temperature, VOC index and NOx index readings print to the Serial Monitor every second. Note that NOx readings are only available on the SEN55 sensor.
Text editor powered by tinymce.