1848 views|1 replies

222

Posts

3

Resources
The OP
 

[DFRobot Skylark Weather Meter Review] Arduino Wireless Intelligent Air Monitoring System Construction-06 Indoor Air Quality Sensor.... [Copy link]

This post was last edited by eew_TKwwQ7 on 2023-12-17 23:09

In order to make the intelligent air monitoring system detect information more comprehensive and reliable, an all-in-one air quality sensor SEN44 is added indoors. The sensor is the previous generation product of Sensrion. The product has been updated to the SEN5X series. It detects parameters such as temperature, humidity, PM2.5, VOC, etc. The entire intelligent air monitoring system is shown in the figure:

SEN44:

1. Default official website SEN44 reference program

Program source code:

#include <Arduino.h>
#include <SensirionUartSen44.h>

// Adjust as needed for you Arduino board.
// [Serial, Serial1, Serial2, etc.]
#define SENSOR_SERIAL_INTERFACE Serial1

SensirionUartSen44 sen44;

void printModuleVersions() {
    uint16_t error;
    char errorMessage[256];

    uint8_t firmwareMajor;
    uint8_t firmwareMinor;
    bool firmwareDebug;
    uint8_t hardwareMajor;
    uint8_t hardwareMinor;
    uint8_t protocolMajor;
    uint8_t protocolMinor;

    error = sen44.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 {
        if (firmwareDebug) {
            printf("Development firmware version: ");
        }
        Serial.print("Firmware: ");
        Serial.print(firmwareMajor);
        Serial.print(".");
        Serial.print(firmwareMinor);
        Serial.print(", ");

        Serial.print("Hardware: ");
        Serial.print(hardwareMajor);
        Serial.print(".");
        Serial.print(hardwareMinor);
        Serial.print(", ");

        Serial.print("Protocol: ");
        Serial.print(protocolMajor);
        Serial.print(".");
        Serial.println(protocolMinor);
    }
}

void printSerialNumber() {
    uint16_t error;
    char errorMessage[256];

    unsigned char serialNumber[32];
    uint8_t serialNumberSize = 32;

    error = sen44.getSerialNumber(serialNumber, serialNumberSize);

    if (error) {
        Serial.print("Error trying to execute getSerialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        Serial.print("Serial number: ");
        Serial.println((char*)serialNumber);
    }
}

void setup() {
    uint16_t error;
    char errorMessage[256];

    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }

    SENSOR_SERIAL_INTERFACE.begin(115200);
    while (!SENSOR_SERIAL_INTERFACE) {
        delay(100);
    }

    sen44.begin(SENSOR_SERIAL_INTERFACE);

    error = sen44.deviceReset();
    if (error) {
        Serial.print("Error trying to execute getSerialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    }

    // Print SEN44 module information
    printSerialNumber();
    printModuleVersions();

    // Start Measurement
    error = sen44.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
    uint16_t massConcentrationPm1p0;
    uint16_t massConcentrationPm2p5;
    uint16_t massConcentrationPm4p0;
    uint16_t massConcentrationPm10p0;
    float vocIndex;
    float ambientHumidity;
    float ambientTemperature;

    error = sen44.readMeasuredMassConcentrationAndAmbientValues(
        massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
        massConcentrationPm10p0, vocIndex, ambientHumidity, ambientTemperature);

    if (error) {
        Serial.print("Error trying to execute "
                     "readMeasuredMassConcentrationAndAmbientValues(): ");
        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("VocIndex:");
        Serial.print(vocIndex);
        Serial.print("\t");
        Serial.print("AmbientHumidity:");
        Serial.print(ambientHumidity);
        Serial.print("\t");
        Serial.print("AmbientTemperature:");
        Serial.println(ambientTemperature);
    }
}

Successfully obtained air quality parameters: MassConcentrationPm4p0:8 MassConcentrationPm10p0:8 VocIndex:209.00 AmbientHumidity:71.35 AmbientTemperature:11.42

2. Modify the software serial port

Because the hardware serial port 1 is used for Xbee, another serial port is needed for the SENN44 sensor to communicate. The SoftwareSerial case in the Leonardo development board on the official website points out that not all I/O can be used as software serial ports:

Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX:8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

Then just use 8 and 9 as software serial ports

Modified program code:


#include <Arduino.h>
#include <SensirionUartSen44.h>
#include <SoftwareSerial.h>
// Adjust as needed for you Arduino board.
// [Serial, Serial1, Serial2, etc.]

SoftwareSerial Serial3(8, 9);
#define SENSOR_SERIAL_INTERFACE Serial3

SensirionUartSen44 sen44;

void printModuleVersions() {
    uint16_t error;
    char errorMessage[256];

    uint8_t firmwareMajor;
    uint8_t firmwareMinor;
    bool firmwareDebug;
    uint8_t hardwareMajor;
    uint8_t hardwareMinor;
    uint8_t protocolMajor;
    uint8_t protocolMinor;

    error = sen44.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 {
        if (firmwareDebug) {
            printf("Development firmware version: ");
        }
        Serial.print("Firmware: ");
        Serial.print(firmwareMajor);
        Serial.print(".");
        Serial.print(firmwareMinor);
        Serial.print(", ");

        Serial.print("Hardware: ");
        Serial.print(hardwareMajor);
        Serial.print(".");
        Serial.print(hardwareMinor);
        Serial.print(", ");

        Serial.print("Protocol: ");
        Serial.print(protocolMajor);
        Serial.print(".");
        Serial.println(protocolMinor);
    }
}

void printSerialNumber() {
    uint16_t error;
    char errorMessage[256];

    unsigned char serialNumber[32];
    uint8_t serialNumberSize = 32;

    error = sen44.getSerialNumber(serialNumber, serialNumberSize);

    if (error) {
        Serial.print("Error trying to execute getSerialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        Serial.print("Serial number: ");
        Serial.println((char*)serialNumber);
    }
}

void setup() {
    uint16_t error;
    char errorMessage[256];

    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }

    SENSOR_SERIAL_INTERFACE.begin(115200);
    while (!SENSOR_SERIAL_INTERFACE) {
        delay(100);
    }

    sen44.begin(SENSOR_SERIAL_INTERFACE);

    error = sen44.deviceReset();
    if (error) {
        Serial.print("Error trying to execute getSerialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    }

    // Print SEN44 module information
    printSerialNumber();
    printModuleVersions();

    // Start Measurement
    error = sen44.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
    uint16_t massConcentrationPm1p0;
    uint16_t massConcentrationPm2p5;
    uint16_t massConcentrationPm4p0;
    uint16_t massConcentrationPm10p0;
    float vocIndex;
    float ambientHumidity;
    float ambientTemperature;

    error = sen44.readMeasuredMassConcentrationAndAmbientValues(
        massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
        massConcentrationPm10p0, vocIndex, ambientHumidity, ambientTemperature);

    if (error) {
        Serial.print("Error trying to execute "
                     "readMeasuredMassConcentrationAndAmbientValues(): ");
        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("VocIndex:");
        Serial.print(vocIndex);
        Serial.print("\t");
        Serial.print("AmbientHumidity:");
        Serial.print(ambientHumidity);
        Serial.print("\t");
        Serial.print("AmbientTemperature:");
        Serial.println(ambientTemperature);
    }
}

Normally obtain sensor SEN44 data, and the serial port prints out the obtained air quality data:

The hardware connection is as shown in the figure:

This post is from Sensor

Latest reply

The original poster took the trouble to provide very detailed technical content, which is of great practical value. I have learned a lot. Thank you for your selflessness.   Details Published on 2023-12-27 15:22
 
 

725

Posts

4

Resources
2
 

The original poster took the trouble to provide very detailed technical content, which is of great practical value. I have learned a lot. Thank you for your selflessness.

This post is from Sensor
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list