37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验五十五:DHT11 数字温湿度传感器 WiFi节点模块 mini数字温湿度传感器 高精度单总线
安装库:打开IDE—工具—管理库—搜索DHT—安装"DHT sensor library"
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验五十五:DHT11 数字温湿度传感器 WiFi节点模块 mini数字温湿度传感器 高精度单总线
Arduino参考开源代码
/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验五十五:DHT11 温湿度复合传感器模块(数字型单总线通信)
安装库:打开IDE—工具—管理库—搜索DHT—安装"DHT sensor library"
项目测试:读取DHT11的串口输出数据
模块接线:
DHT11 Arduino
VCC 5V
GND GND
DATA D2
*/
#include "DHT.h"
#define DHTPIN 2
// 取消注释您正在使用的任何类型!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
//初始化DHT传感器
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHT11现场测试!"));
dht.begin();
}
void loop() {
delay(2000);
//读取温度或湿度大约需要250毫秒!
//传感器读数也可能长达2秒“旧”(这是一个非常慢的传感器)
float h = dht.readHumidity();
// 读取温度为摄氏温度(默认)
float t = dht.readTemperature();
// 将温度读取为华氏度
float f = dht.readTemperature(true);
// 检查是否有任何读取失败并提早退出(重试)
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("无法从DHT传感器读取! "));
return;
}
// 计算华氏热量指数(默认值)
float hif = dht.computeHeatIndex(f, h);
// 计算摄氏温度指数
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("湿度: "));
Serial.print(h);
Serial.print(F("% 温度: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F 热量指数: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
实验串口返回情况
Arduino实验场景图
实验开源图形编程(Mixly、Mind+、编玩边学)以及实验串口返回情况
实验开源图形编程(Mixly、Mind+、编玩边学)
实验串口返回情况
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验五十五:DHT11 数字温湿度传感器 WiFi节点模块 mini数字温湿度传感器 高精度单总线
Arduino参考开源代码
/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验五十五:DHT11 温湿度复合传感器模块(数字型单总线通信)
安装库:打开IDE—工具—管理库—搜索DHT—安装"DHT sensor library"
项目测试:读取DHT11的串口输出数据
模块接线:
DHT11 Arduino
VCC 5V
GND GND
DATA D2
*/
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
// Initialize device.
dht.begin();
Serial.println(F("DHT11 Unified Sensor Example"));
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.println(F("Temperature Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
Serial.println(F("------------------------------------"));
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println(F("Humidity Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
Serial.println(F("------------------------------------"));
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
void loop() {
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
}
实验串口返回情况
实验开源仿真编程(Linkboy V5.33)