希望大佬们出一个模拟量的例程比如(环境光模拟量)
我手上有一个空气质量传感器,想做一个空气净化器,在线设置空气净化器的打开和关闭, 现在串口可以显示模拟量,app里显示不出来 模拟量就是个数字,就是blinker显示数字你直接发你的程序吧,我看看哪里错了 https://www.arduino.cn/thread-84098-1-1.html 这里有模拟量的例程 还带DHT数字量! 本帖最后由 ecstart 于 2019-2-22 11:14 编辑
极客杰 发表于 2019-2-21 22:42
现在串口可以显示模拟量,app里显示不出来
你不是用的我那个例程 不行嘛?A0 你更换模拟量传感器就好了,气体 光线 通用的 !模拟量不需要库支持!
要用作空气净化,你只要在 void loop() 里面加个if 语句设定你要启动净化器的阈值, 操作继电器操作就好了,通过继电器开关控制空气净化器启动。
如果你用我之前的例程,就加如下面语句就可以执行操作,t是你的模拟量变量,25是动作阈值,大概意思就是当t 》=25 就打开15io的继电器,持续5秒,建议可以改更长,让净化器工作久一点,让空气好一些,不然 继电器就会频繁动作。
if (t>=25) {
digitalWrite(15,HIGH);
delay(5000);
}
else
{ digitalWrite(15,LOW);
}
我现在是想加个滑块 控制继电器阈值,再加个开关来切换 手动和自动控制继电器,暂时还没成功,只能在代码里面写死阈值!
@ecstart了你的代码还是不行 #define BLINKER_WIFI#include <Blinker.h>char auth[] = "XXXXXXX"; char ssid[] = "XXXXXXX"; char pswd[] = "XXXXX";BlinkerNumber HUMI("humi"); BlinkerNumber TEMP("temp"); BlinkerNumber HEAT("heat"); BlinkerNumber Kong("kong"); // Download Adafruit DHT-sensor-library library here: // https://github.com/adafruit/DHT-sensor-library #include <DHT.h>#define DHTPIN 2 int kong = A0;#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301)DHT dht(DHTPIN, DHTTYPE);uint32_t read_time = 0;float humi_read, temp_read, heat_read, kong_read;void dataRead(const String & data) { BLINKER_LOG("Blinker readString: ", data); Blinker.vibrate(); uint32_t BlinkerTime = millis(); Blinker.print(BlinkerTime); Blinker.print("millis", BlinkerTime); }void heartbeat() { HUMI.print(humi_read); TEMP.print(temp_read); HEAT.print(heat_read); Kong.print(kong_read); }void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(Serial); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); pinMode(kong,INPUT); Blinker.begin(auth, ssid, pswd); Blinker.attachData(dataRead); Blinker.attachHeartbeat(heartbeat); dht.begin(); }void loop() { Blinker.run(); if (read_time == 0 || (millis() - read_time) >= 2000) { read_time = millis(); float h = dht.readHumidity(); float t = dht.readTemperature(); float c = dht.computeHeatIndex(t, h, false); float k = analogRead(A0); if (isnan(h) || isnan(t)) { BLINKER_LOG("Failed to read from DHT sensor!"); return; humi_read = h; temp_read = t; heat_read = c; kong_read = k; BLINKER_LOG("Humidity: ", h, " %"); BLINKER_LOG("Temperature: ", t, " *C"); BLINKER_LOG("Heat index: ", c, " *C"); BLINKER_LOG("Kong Qi: ", k, " /1024"); } } } 不显示数值 本帖最后由 ecstart 于 2019-2-22 11:35 编辑
把你刷进去的代码复制给我看看 你就是改了开头嘛? 还有你要接DHT11的,不然是不显示的 因为程序卡在读取DHT11 错误那里了
#define BLINKER_WIFI#include <Blinker.h>char auth[] = "XXXXXXX"; char ssid[] = "XXXXXXX"; char pswd[] = "XXXXX";BlinkerNumber HUMI("humi"); BlinkerNumber TEMP("temp"); BlinkerNumber HEAT("heat"); BlinkerNumber Kong("kong"); // Download Adafruit DHT-sensor-library library here: // https://github.com/adafruit/DHT-sensor-library #include <DHT.h>#define DHTPIN 2 int kong = A0;#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22(AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301)DHT dht(DHTPIN, DHTTYPE);uint32_t read_time = 0;float humi_read, temp_read, heat_read, kong_read;void dataRead(const String & data) { BLINKER_LOG("Blinker readString: ", data); Blinker.vibrate(); uint32_t BlinkerTime = millis(); Blinker.print(BlinkerTime); Blinker.print("millis", BlinkerTime); }void heartbeat() { HUMI.print(humi_read); TEMP.print(temp_read); HEAT.print(heat_read); Kong.print(kong_read); }void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(Serial); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); pinMode(kong,INPUT); Blinker.begin(auth, ssid, pswd); Blinker.attachData(dataRead); Blinker.attachHeartbeat(heartbeat); dht.begin(); }void loop() { Blinker.run(); if (read_time == 0 || (millis() - read_time) >= 2000) { read_time = millis(); float h = dht.readHumidity(); float t = dht.readTemperature(); float c = dht.computeHeatIndex(t, h, false); float k = analogRead(A0); if (isnan(h) || isnan(t)) { BLINKER_LOG("Failed to read from DHT sensor!"); return; humi_read = h; temp_read = t; heat_read = c; kong_read = k; BLINKER_LOG("Humidity: ", h, " %"); BLINKER_LOG("Temperature: ", t, " *C"); BLINKER_LOG("Heat index: ", c, " *C"); BLINKER_LOG("Kong Qi: ", k, " /1024"); } } }