资源简介
温湿度传感器 DHT11 与Arduino通讯所需要的库文件 里面附有示例代码
代码片段和文件信息
/* DHT library
MIT license
written by Adafruit Industries
*/
#include “DHT.h“
#define MIN_INTERVAL 2000
DHT::DHT(uint8_t pin uint8_t type uint8_t count)
{
_pin = pin;
_type = type;
#ifdef __AVR
_bit = digitalPinToBitMask(pin);
_port = digitalPinToPort(pin);
#endif
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
// reading pulses from DHT sensor.
// Note that count is now ignored as the DHT reading algorithm adjusts itself
// basd on the speed of the processor.
}
void DHT::begin(void)
{
// set up the pins!
pinMode(_pin INPUT_PULLUP);
// Using this value makes sure that millis() - lastreadtime will be
// >= MIN_INTERVAL right away. Note that this assignment wraps around
// but so will the subtraction.
_lastreadtime = -MIN_INTERVAL;
DEBUG_PRINT(“Max clock cycles: “);
DEBUG_PRINTLN(_maxcycles DEC);
}
//boolean S == Scale. True == Fahrenheit; False == Celcius
float DHT::readTemperature(bool S bool force)
{
float f = NAN;
if (read(force))
{
switch (_type)
{
case DHT11:
f = data[2];
if(S)
{
f = convertCtoF(f);
}
break;
case DHT22:
case DHT21:
f = data[2] & 0x7F;
f *= 256;
f += data[3];
f *= 0.1;
if (data[2] & 0x80)
{
f *= -1;
}
if(S)
{
f = convertCtoF(f);
}
break;
}
}
return f;
}
float DHT::convertCtoF(float c)
{
return c * 1.8 + 32;
}
float DHT::convertFtoC(float f)
{
return (f - 32) * 0.55555;
}
float DHT::readHumidity(bool force)
{
float f = NAN;
if (read())
{
switch (_type)
{
case DHT11:
f = data[0];
break;
case DHT22:
case DHT21:
f = data[0];
f *= 256;
f += data[1];
f *= 0.1;
break;
}
}
return f;
}
//boolean isFahrenheit: True == Fahrenheit; False == Celcius
float DHT::computeHeatIndex(float temperature float percentHumidity bool isFahrenheit)
{
// Using both Rothfusz and Steadman‘s equations
// http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
float hi;
if (!isFahrenheit)
temperature = convertCtoF(temperature);
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
if (hi > 79)
{
hi = -42.379 +
2.04901523 * temperature +
10.14333127 * percentHumidity +
-0.22475541 * temperature*percentHumidity +
-0.00683783 * pow(temperature 2) +
-0.05481717 * pow(percentHumidity 2) +
0.00122874 * pow(temperature 2) * percentHumidity +
0.00085282 * temperature*pow(percentHumidity 2) +
-0.00000199 * pow(temperature 2) * pow(percentHumidity 2);
if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);
else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
}
return isFahrenheit ? hi : convertFtoC(hi);
}
boolean DHT::read(bool force)
{
// Check if sens
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-01-24 09:19 DHT_sensor_library\
文件 8087 2018-01-24 20:33 DHT_sensor_library\DHT.cpp
文件 1531 2018-01-24 21:04 DHT_sensor_library\DHT.h
文件 5740 1980-01-01 00:00 DHT_sensor_library\DHT_U.cpp
文件 2297 1980-01-01 00:00 DHT_sensor_library\DHT_U.h
目录 0 2018-01-24 09:19 DHT_sensor_library\examples\
目录 0 2018-01-24 09:19 DHT_sensor_library\examples\DHT_Unified_Sensor\
文件 3174 1980-01-01 00:00 DHT_sensor_library\examples\DHT_Unified_Sensor\DHT_Unified_Sensor.ino
目录 0 2018-01-24 09:19 DHT_sensor_library\examples\DHTtester\
文件 2219 1980-01-01 00:00 DHT_sensor_library\examples\DHTtester\DHTtester.ino
文件 529 1980-01-01 00:00 DHT_sensor_library\keywords.txt
文件 321 1980-01-01 00:00 DHT_sensor_library\library.properties
文件 957 1980-01-01 00:00 DHT_sensor_library\README.md
- 上一篇:室内定位wknn代码
- 下一篇:Arduino红外传感器库文件
相关资源
- Arduino红外传感器库文件
- DHT11基于msp430
- arduino pid 调节 平衡小车代码
- Arduino全地形小车代码
- Arduino红外循迹小车
- 基于Arduino的温湿度系统设计
- arduino使用红外传感器实现循迹适合新
- Arduboy2库技术文档.pdf
- Arduino LiquidCrystal_I2C库
- arduino使用串口语音模块,解决汉子编
- Arduino并行控制多个舵机
- Arduino 自动水阀控制
- arduino可调速度电机程序TB6612FNG驱动
- PPT控制器—源程序
- STC15F2K60S2读取DHT11温湿度传感器数据串
- DHT11温湿度传感器MSP430F149)
- stc12单片驱动DHT11温湿度传感器
- 树莓派+OpenCV+Arduino实现二维码颜色识
- 用于jz2440的dht11驱动
- 基于Zigbee协议栈的DHT11串口实验
- Arduino uno 控制42步进电机TB6560驱动模块
- DHT11 温湿度传感器1602显示 可用程序
- ZY刷单版
- Arduino UNO 控制全彩RGB点阵条屏单元板
- 51单片机DHT11程序
- EESkill LCD2004液晶模块ARDUINO连接应用
- u8glib_arduino
- Arduino DHT11
- dht11头文件
- arduino 定时器库
评论
共有 条评论