[经验分享] 【DigiKey“智造万物,快乐不停”创意大赛】基于Arduino Uno R4智能床头灯项目&7系统

eew_cT3H5d   2024-1-10 20:54 楼主

基于Arduino Uno R4智能床头灯项目的WIFI版本系统框架如图所示:

 

 

构成系统框架如图所示:二氧化碳空气质量指示系统:根据当前空气二氧化碳浓度显示不同颜色告知用户当前室内二氧化碳浓度状态;颗粒物空气质量调节系统:根据当前空气中颗粒物PM2.5的浓度自动开启负离子及风扇进行负离子净化空气

 

硬件框架图:

image.png    

①Arduino Uno R4扩展板

②四合一SEN44传感器(温度、湿度、PM2.5、VOC传感器)

③SCD30二氧化碳传感器

④负离子发生器模块

⑤涡轮风扇模块

⑥WS2812全彩LED灯

 

 

二氧化碳空气质量指示系统:

 

image.png  

 

 

 

颗粒物空气质量调节系统:

 

image.png    

 

 

系统代码调试:

#include <SPI.h>//驱动ws2812程序
#define NUMPIXELS 16 // 设置灯珠数量
//#define PIN_NEOPIXEL 11  // 设置SPI输出数据引脚
#define PIN_LED 10   // LED引脚设置

#include <Wire.h>//驱动SCD30二氧化碳程序
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;

#include <Arduino.h>//驱动多合一SEN44程序
#include <SensirionUartSen44.h>
#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);
    }
}








unsigned char R;
unsigned char G;
unsigned char B;
unsigned long RGB=0XFF00FF;
// 熄灭的数据
unsigned char default_tx0[24] = 
{
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, //G
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, //R
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80  //B
};

unsigned char WS2812[24] = 
{
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, //G
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, //R
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80  //B
};



// 点亮的数据
unsigned char default_tx1[3][24] = {
  //绿色-G
  {
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8,
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8,
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8
  },
  //红色-R
  {
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8,
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8,
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8
  },
  //蓝-B
  {
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8,
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8,
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8
  }    
};

void lgiht_Open()
{

for (int i = 0; i < 24; i++)
      {
        // 显示数据转换
        if((RGB>>i)&0X01)  { WS2812[23-i]=0xf8; }
          else             { WS2812[23-i]=0x80; }
      }  

for (int j = 0; j < 64; j++)
   {
    for (int i = 0; i < 24; i++)
        {
        // 显示
        SPI.transfer(WS2812[i]);
        } 
   }
}












// 当前灯珠指向
int idx = 0;

void lgiht_n(int n)
{
  for(int i=0;i<NUMPIXELS;i++) {
    if(i==n) {
      for (int i = 0; i < 24; i++)
      {
        // 点亮
        SPI.transfer(default_tx1[ n%3 ][i]);
      }      
    } else {
      for (int i = 0; i < 24; i++)
      {
        // 熄灭
        SPI.transfer(default_tx0[i]);
      } 
    }
  }
}

void setup(void)
{
  // 调试串口速率设置
  Serial.begin(115200);
  Serial1.begin(9600);
   Wire1.begin();//QWIIC使能
  // 设置LED3对应的引脚为输出
  pinMode(PIN_LED, OUTPUT);
airSensor.begin(Wire1);

SPI.beginTransaction(SPISettings(6400000, MSBFIRST, SPI_MODE0));

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

    sen44.begin(SENSOR_SERIAL_INTERFACE);
sen44.deviceReset();
sen44.startMeasurement();

  pinMode(A0, OUTPUT);//负离子发生器模块控制I/O
  pinMode(A1, OUTPUT);//涡轮风扇模块控制I/O

}

void loop(void)
{

    uint16_t massConcentrationPm1p0;
    uint16_t massConcentrationPm2p5;
    uint16_t massConcentrationPm4p0;
    uint16_t massConcentrationPm10p0;
    float vocIndex;
    float ambientHumidity;
    float ambientTemperature;
digitalWrite(PIN_LED, HIGH);delay(100);
digitalWrite(PIN_LED, LOW);delay(100);

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

if(massConcentrationPm2p5>76)
   {digitalWrite(A0, HIGH); digitalWrite(A1, HIGH);}//开启负离子净化系统
   else  
     {digitalWrite(A0, LOW); digitalWrite(A1, LOW);}//关闭负离子净化系统
        Serial.print("MassConcentrationPm2p5:");
        Serial.print(massConcentrationPm2p5);
        Serial.print("\t");
if (airSensor.dataAvailable())//获取二氧化碳浓度
   {
    int CO2;
    CO2=airSensor.getCO2();
    if(CO2<350){RGB=0X00FF00;lgiht_Open();}
      else if(CO2<450){RGB=0XFFFF00;lgiht_Open();}
          else if(CO2<550){RGB=0XFF7D2D;lgiht_Open();}
              else if(CO2<1000){RGB=0XFF0000;lgiht_Open();}


Serial.print("co2(ppm):");Serial.println(CO2);//串口显示二氧化碳浓度
   }






}

 

调试实物:

e955c4985420e8c96fb3bd061fd9fbf.jpg  

 

视频演示:

系统调试

 

本帖最后由 eew_cT3H5d 于 2024-1-11 16:11 编辑

回复评论 (3)

很专业,考虑很全面,系统框架清晰


点赞  2024-1-11 18:57

架构清晰,超喜欢这些传感器  

在爱好的道路上不断前进,在生活的迷雾中播撒光引
点赞  2024-1-12 09:01
引用: 秦天qintian0303 发表于 2024-1-12 09:01 架构清晰,超喜欢这些传感器  

这些传感器很稳定,就是价格太贵了

点赞  2024-1-12 14:30
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复