[英]Connecting two sensors dht11 and dht22 the same nodemcu module esp-12e
我有一个项目,我需要将两个传感器 DHT11 和 DHT22 连接到模块 nodemcu esp-12e。 有什么办法可以同时使用同一个模块中的两个传感器?
如果您想要一个实现示例,请使用以下步骤:
使用下面的代码片段,但不要忘记设置您的引脚:
#include "DHT.h" #define DHT11PIN 2 #define DHT22PIN 3 DHT dht11(DHT11PIN, DHT11 ); DHT dht22(DHT22PIN, DHT22 ); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht11.begin(); dht22.begin(); } void loop() { delay(2000); float h11 = dht11.readHumidity(); float t11 = dht11.readTemperature(); float f11 = dht11.readTemperature(true); float h22 = dht22.readHumidity(); float t22 = dht22.readTemperature(); float f22 = dht22.readTemperature(true); //do print them.. }
当然,有。
两个传感器都是数字式的。 所以,只要你有足够多的数字引脚,而 ESP12e 确实有,那么获取两个不同的传感器数据就不会有问题。
只需为每个数字 IO 引脚选择一个数据输入,并将其编程为输入。 你需要有相关的数据通信库。 基本上,在 arduino 中,您可以执行以下操作:
#include <DHT.h>
检查以下链接以跟进:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.