pdf-icon

Arduino Quick Start

2. Devices & Examples

Air Quality SEN55 Sensor Data Acquisition

Air Quality SEN55 sensor related API and example program.

Before using the SEN55 sensor, you must enable the power switch by setting GPIO10 as an output and driving it LOW; LOW level enables the sensor.

Example

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#include <M5Unified.h>
#include <Wire.h>
#include <SensirionI2CSen5x.h>

// SEN55 instance
SensirionI2CSen5x sen5x;

void setup() {
  // Serial debug
  Serial.begin(115200);

  // Initialize the screen
  M5.begin();
  M5.Display.clear(TFT_BLACK);
  M5.Display.setTextSize(1);
  M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);

  // I2C pins (SDA=11, SCL=12), same configuration as before for data reading
  Wire.begin(11, 12);
  // AirQ external sensor enable pin, keep LOW
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);

  // Initialize SEN55
  sen5x.begin(Wire);
  uint16_t err;
  char msg[128];

  err = sen5x.deviceReset();
  if (err) {
    errorToString(err, msg, sizeof(msg));
    Serial.println("SEN55 reset failed: " + String(msg));
  }
  // Start measurement
  err = sen5x.startMeasurement();
  if (err) {
    errorToString(err, msg, sizeof(msg));
    Serial.println("Failed to start SEN55 measurement: " + String(msg));
  }
}

void loop() {
  // Read every 1 second
  delay(1000);

  float pm1, pm2_5, pm4, pm10, hum, temp, voc, nox;
  uint16_t err = sen5x.readMeasuredValues(
    pm1, pm2_5, pm4, pm10,
    hum, temp,
    voc, nox
  );

  // Clear screen and reset cursor
  M5.Display.fillScreen(TFT_BLACK);
  M5.Display.setCursor(10, 10);

  if (err) {
    // Read error
    M5.Display.setTextColor(TFT_RED, TFT_BLACK);
    char em[64];
    errorToString(err, em, sizeof(em));
    M5.Display.printf("Read Error:\n%s", em);
  } else {
    // Display values
    M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
    M5.Display.printf("PM1.0 : %.1f ug/m3\n",   pm1);
    M5.Display.printf("PM2.5 : %.1f ug/m3\n",   pm2_5);
    M5.Display.printf("PM4.0 : %.1f ug/m3\n",   pm4);
    M5.Display.printf("PM10  : %.1f ug/m3\n\n", pm10);
    M5.Display.printf("Hum   : %.1f %%\n",      hum);
    M5.Display.printf("Temp  : %.1f C\n\n",     temp);
    M5.Display.printf("VOC   : %.1f\n",        voc);
    M5.Display.printf("NOx   : %.1f\n",        nox);
  }
  // Update M5 events (required)
  M5.update();
}

After uploading, you will see the following result:

On This Page