电子工程师技术服务社区
- 社区首页
- 下载
- Dht11.zip
资料描述
本次继续分享如何通过dfrobot获取micokit扩展板上的温湿度传感器的数据。
micokit扩展板设计了常用的温湿度传感器dht11,该传感器是一款含有已校准数字信号输出的温湿度复合传感器。它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。传感器包括一个电阻式感湿元件和一个ntc测温元件,并与一个高性能mcu连接。因此该产品具有品质卓越、抗干扰能力强、性价比极高等优点。每个dht11传感器都在极为精确的湿度校验室中进行校准。校准系数以程序的形式储存在otp内存中,传感器内部在检测信号的处理过程中要调用这些校准系数。单线制串行接口,使系统集成变得简易快捷。超小的体积、极低的功耗,信号传输距离可达20米以上,使其成为各类应用甚至最为苛刻的应用场合的最佳选择。产品为4针单排引脚封装。连接方便,特殊封装形式可根据用户需求而提供。详细参考手册, 下载库文件,解压在arduino的ide下libraries文件下
dht11数据采用单线制串行接口,电路连接比较简单,如下图所示。
完整代码如下:
/*
purpose:
get the temperature and humidity from the sensor on the ext board via the apk.
cmd:“getht”
2015/10/19 12:30
*/
#include
dht11 dht11;
typedef enum {start, rcving, end} state_type;
state_type readstatus = start;
const int dht11pin = 8;
string cmddata = "";
void setup()
{
serial.begin(115200); //initiate the serial comm
readstatus = start;
}
void loop()
{
if(readcmd())
{
handlecmd();
}
}
boolean readcmd()
{
boolean ret = false;
switch(readstatus)
{
case start:
if(s