HDC1080+TEMT6000采集温湿度及亮度数据-Arduino中文社区 - Powered by Discuz! Archiver

coloz 发表于 2019-9-17 01:45

HDC1080+TEMT6000采集温湿度及亮度数据

wifiduino上的A0因为接了电阻,所以并不是很准,这里仅用于采集亮度变化。如果你需要准确的流明数据,建议还是用数字光强传感器。

界面:


示例:


#define BLINKER_WIFI
#include <Blinker.h>

char auth[] = "xxxxxxxxx";
char ssid[] = "xxxxx";
char pswd[] = "xxxxxxxxxxx";

BlinkerNumber TEMP("temp"); // Temperature
BlinkerNumber HUMI("humi"); // Humidity
BlinkerNumber BRIG("brig");    // brightness

int tempValue = 0;
int humiValue = 0;
int brigValue = 0;

// Download Adafruit-BMP085-Library library here:
// https://github.com/closedcube/ClosedCube_HDC1080_Arduino

#include <Wire.h>
#include <ClosedCube_HDC1080.h>

ClosedCube_HDC1080 hdc1080;
#define TEMT6000_PIN A0

void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

    Blinker.vibrate();

    uint32_t BlinkerTime = millis();

    Blinker.print("millis", BlinkerTime);
}

void dataStorage()
{
    readSensor();
    Blinker.dataStorage("temp", tempValue);
    Blinker.dataStorage("humi", humiValue);
    Blinker.dataStorage("brig", brigValue);
}

void heartbeat()
{
    TEMP.print(tempValue);
    HUMI.print(humiValue);
    BRIG.print(brigValue);
}

void readSensor()
{
    tempValue = hdc1080.readTemperature();
    humiValue = hdc1080.readHumidity();
    brigValue = analogRead(TEMT6000_PIN);
}

void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);

    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
   
    hdc1080.begin(0x40);
    readSensor();

    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);
    Blinker.attachHeartbeat(heartbeat);
    Blinker.attachDataStorage(dataStorage);

}

void loop()
{
    Blinker.run();
}


页: [1]
查看完整版本: HDC1080+TEMT6000采集温湿度及亮度数据