【DigiKey“智造万物,快乐不停”创意大赛】基于Arduino Uno R4智能床头灯项目&1驱动3
[复制链接]
本帖最后由 eew_cT3H5d 于 2024-1-2 21:49 编辑
空气质量表示是一个复杂的问题,涉及很多参数,在选型传感器的时候发现一款盛思锐Sensirion将温度、湿度、PM2.5、PM10、VOC等参数做成一个传感器,eeworld网友说这个传感器非常不错,就立刻纠正使用这个传感器了,而且官网现在很多系列可选择,在digikey也有现货,可以选择最新版本的SEN5X系列,我这边选择一个老版本的SEN44,在网上淘的,很新
评估空气质量参数涉及很多参数,从下图可以看出参数包括:HCHO(甲醛)、RH/T(温湿度)、CO2(二氧化碳)、NOX(氮氧化合物)、PM25(颗粒物)、VOC(挥发物有机物)等
PM2.5指大气中不大于2.5微米的颗粒物,又称入肺颗粒物。指环境空气中空气动力学,当量直径小于等于2.5微米的颗粒物。它能较长时间悬浮于空气中,其在空气中含量浓度越高,就代表空气污染越严重。虽然PM2.5只是地球大气成分中含量很少的部分,但它对空气质量和能见度等有重要的影响。
激光原理PM2.5传感器的结构和电路相对复杂。其光源为激光二极管。采样空气通过风扇或鼓风机推动,通过复杂设计的风道,进行检测。当空气中的细颗粒物进入激光束所在区域时,将使激光发生散射;散射光在空间360°都有辐射,在适当位置放置光电探测器用以接收散射光,然后经过光电探测器的光电效应产生电流信号,经运放电路放大及处理后,即可得到细颗粒物浓度值。输出信号可用串口、I²C、PWM等多种方式。
VOC的主要成分有:烃类、卤代烃、氧烃和氮烃,它包括:苯系物、有机氯化物、氟里昂系列、有机酮、胺、醇、醚、酯、酸和石油烃化合物等。
VOC传感器一般分为化学传感器和半导体器件传感器,两者各有优缺点,VOC可以持续感知空气质量,不会像人的鼻子一样会因长时间适应而失效测试不准确
SEN44传感器提供串口和IIC接口进行通讯,本项目采用串口通讯,下载官方库即可实现读取传感器的温度、湿度、PM2.5、PM10、VOC等参数
基于Arduino Uno R4平台驱动无异常,选型确定OK,就选择大厂的盛思锐Sensirion多合一SEN系列传感器
#include <Arduino.h>
#include <SensirionUartSen44.h>
// Adjust as needed for you Arduino board.
// [Serial, Serial1, Serial2, etc.]
#define SENSOR_SERIAL_INTERFACE Serial
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);
}
}
|