dht22数字温湿度传感器am2302温湿度模块(带说明)

合集下载

温湿度数字传感器AM2302.pdf

温湿度数字传感器AM2302.pdf
Free Datasheet
数字温湿度传感器 AM2302
注: AM2302 也叫 DHT22
数字温湿度传感器 AM2302
小体积 AM2302 ►相对湿度和温度测量 ►全部校准,数字输出 ►卓越的长期稳定性 ►无需额外部件 ►超长的信号传输距离 ►超低能耗 ►4 引脚安装 ►完全互换
湿度数据
温度数据
校验和
湿度高8位+湿度低8位+温度高8位+温度低8位=的末8位=校验和
例如:0000 0010+1000 1100+0000 0001+0101 1111=1110 1110
湿度=65.2%RH 温度=35.1℃
当温度低于0℃时温度数据的最高位置1。
例如:-10.1℃表示为1000 0000 0110 0101
Free Datasheet
数字温湿度传感器 AM2302
注: AM2302 也叫 DHT22
3、 电源引脚 AM2302的供电电压为3.3-6V。传感器上电后,要等待 1s 以越过不稳定状态在此期
间无需发送任何指令。电源引脚(VDD,GND)之间可增加一个100nF 的电容,用以去耦 滤波。 4、单总线接口

16
Bit
重复性
±0.2

精度
<±0.5

量程范围
-40
80

响应时间
1/e(63%)
6
20
S
2、 采样周期不得低于最小值,否则会引起错误
3、 接口说明
建议连接线长度短于20米时用5K上拉电阻,大于20米时根据实际情况使
用合适的上拉电阻
AM2302的接线图如下图所示。

DHT22(AM2302)数字温湿度传感器

DHT22(AM2302)数字温湿度传感器

温湿度模块AM2302 产品手册一、产品概述AM2302湿敏电容数字温湿度模块是一款含有己校准数字信号输出的温湿度复合传感器。

它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。

传感器包括一个电容式感湿元件和一个高精度测温元件,并与一个高性能8位单片机相连接。

因此该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。

每个传感器都在极为精确的湿度校验室中进行校准。

校准系数以程序的形式储存在单片机中,传感器内部在检测信号的处理过程中要调用这些校准系数。

标准单总线接口,使系统集成变得简易快捷。

超小的体积、极低的功耗,信号传输距离可达20米以上,使其成为各类应用甚至最为苛刻的应用场合的最佳选择。

产品为3引线(单总线接口)连接方便。

特殊封装形式可根据用户需求而提供。

实物图外形尺寸(单位:mm)二、应用范围暖通空调、除湿器、测试及检测设备、消费品、汽车、自动控制、数据记录器、家电、湿度调节器、医疗、气象站、及其他相关湿度检测控制等。

三、产品亮点超低能耗、传输距离远、全部自动化校准、采用电容式湿敏元件、完全互换、标准数字单总线输出、卓越的长期稳定性、采用高精度测温元件。

四、单总线接口定义4.1 AM2302引脚分配表1:AM2302引脚分配图1:AM2302引脚分配图4.2 引脚说明(VDD SDA GND)AM2302的供电电压范围为3.3V - 5.5V,建议供电电压为5V。

数据线SDA引脚为三态结构,用于读写传感器数据。

详细见单总线的通信协议说明。

五、传感器性能 5.1 相对湿度表2: AM2302相对湿度性能表图2: 25℃时AM2302的相对湿度最大误差 图3:温度传感器的温度最大误差六、电气特性电气特性,如能耗,高、低电平,输入、输出电压等,都取决于电源。

表4详细说明了AM2302的电气特性,若没有标明,则表示供电电压为5V 。

若想与传感器获得最佳效果,请设计时严格遵照表4的条件设计。

DHT22 AM2302

DHT22 AM2302

数字温湿度传感器AM2302小体积AM2302大体积AM2302►相对湿度和温度测量►全部校准,数字输出►卓越的长期稳定性►无需额外部件►超长的信号传输距离►超低能耗►4引脚安装►完全互换AM2302产品概述AM2302数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器。

它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。

传感器包括一个电容式感湿元件和一个NTC 测温元件,并与一个高性能8位单片机相连接。

因此该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。

每个AM2302传感器都在极为精确的湿度校验室中进行校准。

校准系数以程序的形式储存在OTP内存中,传感器内部在检测信号的处理过程中要调用这些校准系数。

单线制串行接口,使系统集成变得简易快捷。

超小的体积、极低的功耗,信号传输距离可达20米以上,使其成为各类应用甚至最为苛刻的应用场合的最佳选则。

产品为4针单排引脚封装。

连接方便,特殊封装形式可根据用户需求而提供。

应用领域►暖通空调►测试及检测设备►汽车►数据记录器►消费品►自动控制►气象站►家电►湿度调节器►医疗1、传感器性能说明2、采样周期不得低于最小值,否则会引起错误3、接口说明建议连接线长度短于20米时用5K 上拉电阻,大于20米时根据实际情况使用合适的上拉电阻AM2302的接线图如下图所示。

参数条件Min Typ Max 单位湿度分辨率0.1%RH 16Bit 重复性±0.3%RH 精度25℃±2%RH -2-200-80℃±2%RH 互换性可完全互换采样周期2S 响应时间1/e(63%)25℃,1m/s 空气<5S 迟滞<±0.3%RH 长期稳定性典型值<±0.5%RH/yr温度分辨率0.1℃16Bit重复性±0.0.22℃精度<±0.5℃量程范围-4080℃响应时间1/e(63%)620S3、电源引脚AM2302的供电电压为3.3-6V。

DHT22使用范例

DHT22使用范例

/****************************************************************/ /// DHT22使用范例//单片机:AT89S52或STC89C52RC//功能:串口发送温湿度数据波特率9600//公司:**********//**************************************************************** //#include <reg51.h>#include <intrins.h>//typedef unsigned char U8; /* defined for unsigned 8-bits integer variable无符号8位整型变量*/typedef signed char S8; /* defined for signed 8-bits integer variable有符号8位整型变量*/typedef unsigned int U16; /* defined for unsigned 16-bits integer variable无符号16位整型变量*/typedef signed int S16; /* defined for signed 16-bits integer variable有符号16位整型变量*/typedef unsigned long U32; /* defined for unsigned 32-bits integer variable 无符号32位整型变量*/typedef signed long S32; /* defined for signed 32-bits integer variable有符号32位整型变量*/typedef float F32; /* single precision floating point variable(32bits)单精度浮点数(32位长度)*/typedef double F64; /* double precision floating point variable(64bits)双精度浮点数(64位长度)*///#define uchar unsigned char#define uint unsigned int#define Data_0_time 4//----------------------------------------------////----------------IO口定义区--------------------////----------------------------------------------//sbit P2_0 = P2^0 ;sbit P2_1 = P2^1 ;sbit P2_2 = P2^2 ;sbit P2_3 = P2^3 ;//----------------------------------------------//济南联诚创发科技有限公司电子部Page 13 of 18数字温湿度传感器AM2302//----------------定义区--------------------////----------------------------------------------//U8 U8FLAG,k;U8 U8count,U8temp;U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;U8U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp ,U8checkdata_t emp;U8 outdata[5]; //定义发送的字节数U8 indata[5];U8 count, count_r=0;U8 str[5]={"RS232"};U16 U16temp1,U16temp2;SendData(U8 *a){outdata[0] = a[0];outdata[1] = a[1];outdata[2] = a[2];outdata[3] = a[3];outdata[4] = a[4];count = 1;SBUF=outdata[0];}void Delay(U16 j){ U8 i;for(;j>0;j--){for(i=0;i<27;i++);}}void Delay_10us(void){U8 i;i--;i--;i--;i--;i--;i--;}void COM(void)济南联诚创发科技有限公司电子部Page 14 of 18 数字温湿度传感器AM2302{U8 i;for(i=0;i<8;i++){U8FLAG=2;while((!P2_0)&&U8FLAG++);Delay_10us();Delay_10us();Delay_10us();U8temp=0;if(P2_0)U8temp=1;U8FLAG=2;while((P2_0)&&U8FLAG++);//超时则跳出for循环if(U8FLAG==1)break;//判断数据位是0还是1//如果高电平高过预定0高电平值则数据位为1}//rof}//--------------------------------//-----湿度读取子程序------------//--------------------------------//----以下变量均为全局变量--------//----温度高8位== U8T_data_H------//----温度低8位== U8T_data_L------//----湿度高8位== U8RH_data_H-----//----湿度低8位== U8RH_data_L-----//----校验8位== U8checkdata-----//----调用相关子程序如下----------//---- Delay();, Delay_10us();,COM();//--------------------------------void RH(void){//主机拉低18msP2_0=0;济南联诚创发科技有限公司电子部Page 15 of 18 数字温湿度传感器AM2302Delay(5);P2_0=1;//总线由上拉电阻拉高主机延时20usDelay_10us();Delay_10us();Delay_10us();Delay_10us();//主机设为输入判断从机响应信号P2_0=1;//判断从机是否有低电平响应信号如不响应则跳出,响应则向下运行if(!P2_0)//T !{U8FLAG=2;//判断从机是否发出80us的低电平响应信号是否结束while((!P2_0)&&U8FLAG++);U8FLAG=2;//判断从机是否发出80us的高电平,如发出则进入数据接收状态while((P2_0)&&U8FLAG++);//数据接收状态COM();COM();COM();COM();COM();P2_0=1;//数据校验U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_d ata_L_temp);if(U8temp==U8checkdata_temp)if(1){U8RH_data_H=U8RH_data_H_temp;U8RH_data_L=U8RH_data_L_temp;U8T_data_H=U8T_data_H_temp;U8T_data_L=U8T_data_L_temp;U8checkdata=U8checkdata_temp;}//fi}//fi济南联诚创发科技有限公司电子部Page 16 of 18数字温湿度传感器AM2302}//----------------------//P2_1=0 ; //T//P2_1=1 ; //T//----------------------//----------------------//P2_1=0 ; //T//P2_1=1 ; //T//----------------------//----------------------------------------------//main()功能描述:AT89C51 11.0592MHz 串口发//送温湿度数据,波特率9600//----------------------------------------------void main(){U8 i,j;//uchar str[6]={"RS232"};/*系统初始化*/TMOD = 0x20;//定时器T1使用工作方式2TH1 = 253; //设置初值TL1 = 253;TR1 = 1; //开始计时SCON = 0x50;//工作方式1,波特率9600bps,允许接收ES = 1;EA = 1; //打开所以中断TI = 0;RI = 0;SendData(str) ; //发送到串口Delay(1); //延时100US(12M晶振)while(1){//------------------------//调用温湿度读取子程序RH();//串口显示程序//--------------------------str[0]=U8RH_data_H;str[1]=U8RH_data_L;str[2]=U8T_data_H;str[3]=U8T_data_L;济南联诚创发科技有限公司电子部Page 17 of 18 数字温湿度传感器AM2302str[4]=U8checkdata;SendData(str) ; //发送到串口//读取模块数据周期不易小于2SDelay(200);}//elihw}// mainvoid RSINTR() interrupt 4 using 2{U8 InPut3;if(TI==1) //发送中断{TI=0;if(count!=5) //发送完5位数据{SBUF= outdata[count];count++;}}if(RI==1)//接收中断{InPut3=SBUF;indata[count_r]=InPut3;count_r++;RI=0;if (count_r==5)//接收完4位数据{//数据接收完毕处理。

DHT22(AM2302)数字温湿度传感器

DHT22(AM2302)数字温湿度传感器

温湿度模块AM2302 产品手册一、产品概述AM2302湿敏电容数字温湿度模块是一款含有己校准数字信号输出的温湿度复合传感器。

它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。

传感器包括一个电容式感湿元件和一个高精度测温元件,并与一个高性能8位单片机相连接。

因此该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。

每个传感器都在极为精确的湿度校验室中进行校准。

校准系数以程序的形式储存在单片机中,传感器内部在检测信号的处理过程中要调用这些校准系数。

标准单总线接口,使系统集成变得简易快捷。

超小的体积、极低的功耗,信号传输距离可达20米以上,使其成为各类应用甚至最为苛刻的应用场合的最佳选择。

产品为3引线(单总线接口)连接方便。

特殊封装形式可根据用户需求而提供。

实物图外形尺寸(单位:mm)二、应用范围暖通空调、除湿器、测试及检测设备、消费品、汽车、自动控制、数据记录器、家电、湿度调节器、医疗、气象站、及其他相关湿度检测控制等。

三、产品亮点超低能耗、传输距离远、全部自动化校准、采用电容式湿敏元件、完全互换、标准数字单总线输出、卓越的长期稳定性、采用高精度测温元件。

四、单总线接口定义4.1 AM2302引脚分配表1:AM2302引脚分配图1:AM2302引脚分配图4.2 引脚说明(VDD SDA GND)AM2302的供电电压范围为3.3V - 5.5V,建议供电电压为5V。

数据线SDA引脚为三态结构,用于读写传感器数据。

详细见单总线的通信协议说明。

五、传感器性能 5.1 相对湿度表2: AM2302相对湿度性能表图2: 25℃时AM2302的相对湿度最大误差 图3:温度传感器的温度最大误差六、电气特性电气特性,如能耗,高、低电平,输入、输出电压等,都取决于电源。

表4详细说明了AM2302的电气特性,若没有标明,则表示供电电压为5V 。

若想与传感器获得最佳效果,请设计时严格遵照表4的条件设计。

DHT11, DHT22 and AM2302 Sensors说明书

DHT11, DHT22 and AM2302 Sensors说明书

DHT11, DHT22 and AM2302 SensorsCreated by lady adahttps:///dhtLast updated on 2022-12-01 01:49:21 PM EST34681213Table of ContentsOverview• DHT11 vs DHT22Connecting to a DHTxx Sensor Using a DHTxx Sensor DHT CircuitPython Code• Adafruit CircuitPython Module Install• Wiring• Usage• Example CodePython DocsDownloads• SimulatorOverviewThis tutorial covers the low cost DHT temperature & humidity sensors (). These sensors are very basic and slow, but are great for hobbyists who want to do some basic data logging. The DHT sensors are made of two parts, a capacitive humidity sensor and a thermistor (). There is also a very basic chip inside that does some analog to digital conversion and spits out a digital signal with the temperature and humidity. The digital signal is fairly easy to read using any microcontroller.DHT11 vs DHT22We have two versions of the DHT sensor, they look a bit similar and have the same pinout, but have different characteristics. Here are the specs:DHT11 (http://adafru.it/386)Ultra low cost3 to 5V power and I/O2.5mA max current use during conversion (while requesting data)Good for 20-80% humidity readings with 5% accuracyGood for 0-50°C temperature readings ±2°C accuracyNo more than 1 Hz sampling rate (once every second)Body size 15.5mm x 12mm x 5.5mm4 pins with 0.1" spacing• • • • • • • •DHT22 (http://adafru.it/385)/ AM2302 () (Wired version)Low cost3 to 5V power and I/O2.5mA max current use during conversion (while requesting data)Good for 0-100% humidity readings with 2-5% accuracyGood for -40 to 80°C temperature readings ±0.5°C accuracyNo more than 0.5 Hz sampling rate (once every 2 seconds)Body size 15.1mm x 25mm x 7.7mm4 pins with 0.1" spacingAs you can see, the DHT22 (http://adafru.it/385) / AM2302 () is a little more accurate and good over a slightly larger range. Both use a single digital pin and are 'sluggish'in that you can't query them more than once every second or two.You can pick up both the DHT11 (http://adafru.it/386) and DHT22 (http://adafru.it/385)or AM2302 () from the adafruit shop!Connecting to a DHTxx SensorLuckily it is trivial to connect to these sensors, they have fairly long 0.1"-pitch pins so you can plug them into any breadboard, perfboard or similar.• • • • • • ••AM2302 (wired DHT22) temperature-humidity sensorDiscontinued - you can grab AM2301B -Wired Enclosed AHT20 - Temperature andHumidity Sensor instead!The...https:///product/393Likewise, it is fairly easy to connect up to the DHT sensors. They have four pinsVCC - red wire Connect to 3.3 - 5V power. Sometime 3.3V power isn't enough in which case try 5V power.Data out - white or yellow wireNot connectedGround - black wireSimply ignore pin 3, its not used. You will want to place a 10 Kohm resistor between VCC and the data pin, to act as a medium-strength pull up on the data line. The Arduino has built in pullups you can turn on but they're very weak, about 20-50K This diagram shows how we will connect for the testing sketch. Connect data to pin 2,you can change it later to any pin.1. 2. 3. 4. another one!If you have an AM2302Using a DHTxx SensorTo test the sketch, we'll use an Arduino. You can use any micrcontroller that can do microsecond timing, but since its a little tricky to code it up, we suggest verifying the wiring and sensor work with an Arduino to start.You should have the Arduino IDE () software running at this time. Next it’s necessary to install our DHT library, which can be done though the Arduino Library Manager:Sketch →Include Library →Manage Libraries…Enter “dht” in the search field and look through the list for “DHT sensor library by Ada fruit.” Click the “Install” button, or “Update” from an earlier version.IMPORTANT: As of version 1.3.0 of the DHT library you will also need to install the Ada fruit Unified Sensor library, which is also available in the Arduino Library Manager:Now load up the Examples→DHT→DHTtester sketch ArrayIf you're using a DHT11 sensor, comment out the line that sets the type://#define DHTTYPE DHT22 // DHT 22 (AM2302)and uncomment the line that says:#define DHTTYPE DHT11 // DHT 11This will make the data appear correctly for the correct sensor. Upload the sketch!You should see the temperature and humidity. You can see changes by breathing onto the sensor (like you would to fog up a window) which should increase the humidity.You can add as many DHT sensors as you line on individual pins, just add new lines such asDHT dht2 = DHT(pin, type);below the declaration for the initial dht object, and you can reference the new dht2whenever you like.DHT CircuitPython CodeAdafruit CircuitPython Module InstallTo use the DHT sensor with your Adafruit CircuitPython board you'll need to install the Adafruit_CircuitPython_DHT () module on your board.This library uses the pulseio module in CircuitPython. As of CircuitPython 7.0.0, pulseio is no longer available on the smallest CircuitPython builds, such as the Trinket M0, Gemma M0, and Feather M0 Basic boards. You can substitute a more modern sensor, which will work better as well. See the guide ModernReplacements for DHT11 and DHT22 Sensors (https:///modern-replacements-for-dht11-dht22-sensors) for suggestions.First make sure you are running the latest version of Adafruit CircuitPython () for your board.Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle(). Our introduction guide has a great page on how to install the library bundle () for both express and non-express boards.Remember for non-express boards like the, you'll need to manually install the necessary libraries from the bundle:adafruit_dht.mpyYou can also download the adafruit_dht.mpy from its releases page on Github ().Before continuing make sure your board's lib folder or root filesystem has the adafruit _dht.mpy module copied over.WiringDHT wiring is very simple:The left-most pin is power. We recommend powering from 5V (sometimes 3V is not enough) - this is OK even if you are using 3.3V logicThe second pin is data. Connect a 10K pullup resistor from this pin to 3.3V. If you are using a DHT11 it's required. If you're using a DHT22 or AM2302 you can sometimes leave this offSkip the third pinThe right-most pin is ground•• • • • For the DATA pin you must pick a pin that has PWM support (pulseio) - Check the board's guide for what pins have timers availableHere's an example using a Trinket M0 -you can use any CircuitPython board, justcheck that the Data pin is pulseio -capable.In this example we'll use a Feather M0 andDHT22 sensor connected to pin D6Fritzing Source UsageTo demonstrate the usage of the DHT sensor module you can connect to your board's serial REPL and run Python code to read the temperature and humidity.Next connect to the board's serial REPL ()so you are at the CircuitPython >>> prompt.Next import the board and adafruit_dht modules, these are necessary modules to initialize and access the sensor:import boardimport adafruit_dhtYou may also want to try powering the DHT sensor from 5V (we found sometimes it really needs more power) but still having the 10K pull-up resistor to 3.3V volts)Now create an instance of either the DHT11 or DHT22 class, depending on the type of sensor you're using (for the AM2302 sensor use the DHT22 class). You must pass in the pin which is connected to the signal line, for example a DHT22 or AM2302 sensor connected to board pin D6 would need this code:dht = adafruit_dht.DHT22(board.D6)Note for a DHT11 sensor you'd instead use adafruit_dht.DHT11 in place of the adafruit_ dht.DHT22 code above.At this point you're all set and ready to start reading the temperature and humidity! You can do this by reading the temperature property which returns temperature in degrees Celsius:dht.temperatureTo read the humidity grab the value of the humidity property, it will return the percent humidity as a floating point value from 0 to 100%:dht.humidityIn most cases you'll always get back a temperature or humidity value when requested, but sometimes if there's electrical noise or the signal was interrupted in some way you might see an exception thrown to try again. It's normal for these sensors to sometimes be hard to read and you might need to make your code retry a few times if it fails to read. However if you always get errors and can't ever read the sensor then double check your wiring (don't forget the pull-up resistor if needed!) and the power to the device.Example CodeHere's a full example sketch which also manages error-retry logic (which will happen once in a while.Don't forget to change the logic pin to whatever pin you're using! Then save this as main.py on your CircuitPython board# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries## SPDX-License-Identifier: MITimport timeimport adafruit_dht import boarddht = adafruit_dht.DHT22(board.D2)while True: try:temperature = dht.temperaturehumidity = dht.humidity# Print what we got to the REPLprint("Temp: {:.1f} *C \t Humidity: {}%".format(temperature, humidity)) except RuntimeError as e:# Reading doesn't always work! Just print error and we'll try again print("Reading from DHT failure: ", e.args)time.sleep(1)If you are using a DHT11, change the code to use a adafruit_dht.DHT11(board.D2) object.Open the REPL to see the output! Breathe on the sensor to see it move temperature and humidity up (unless you are a White Walker in which case the temperature will go down)Python DocsPython Docs ()DownloadsArduino library and example code for DHT sensors ()Adafruit_Sensor library () (required by the DHT library above)DHT11 datasheet ()(in chinese, so see the DHT22 datasheet too!)DHT22 datasheet ()K&R Smith calibration notes ()SimulatorYou can try out a DHT simulator by Wowki () here: https:///arduino/libraries/DHT-sensor-library ()• • • • •。

温湿度模块DHT22产品手册说明书

温湿度模块DHT22产品手册说明书

温湿度模块DHT22产品手册一、产品概述本产品是采用高稳定性电容式感湿元件作为传感元件,经过微处理器采集处理转化成数字信号输出。

每一个传感器都经过标定校准和测试。

具有长期稳定、可靠性高、精度高、低功耗等特点。

二、尺寸图单位:mm(±0.5)三、产品特点DHT22数字温湿度模块具有以下特点:1、数字输出,IIC协议;2、超低功耗;3、0-100%相对湿度测量范围;4、全标定、温漂校准。

5、使用独立感湿元器件,稳定性好,抗污染能力强四、性能特征相对湿度温度五、电气特性参数条件最小典型最大单位供电电压VDD 2.8 3.3 5.5V 供电电流休眠模式0.2uA 测量模式500uA 采样周期 2.0S低电平输出电压Io<4mA 0250mV 高电平输出电压Rp<25kΩ80%100%VDD 低电平输入电压下降沿0%20%VDD 高电平输入电压上升沿80%100%VDD 输出电流On 4mA 三态门(Off)1020μA表3Io 表示低电平输出电流Rp 代表上拉电阻参数条件最小典型最大单位分辨率0.1%RH 量程范围099.9%RH 精度25℃±3%RH重复性±0.1响应时间1/e(63%)<8S迟滞±0.5漂移典型值<3%RH/r 参数条件最小典型最大单位分辨率0.1℃工作范围-4080℃精度±0.5℃重复性±0.2℃响应时间1/e(63%)1S迟滞±0.1漂移典型值<0.2℃/r图1图2表1表2六、用户指南1、引脚分配引脚名称描述1VDD 电源2.8~5.5V 2SDA 串行数据,双向口3GND 地4SCK 时钟线表4:引脚分配1.1、电源引脚(VDD GND)本产品的供电电压为2.8~5.5V,建议供电电压为3.3V。

1.2、串行数据(SDA)SDA 为数据口,三态结构,SDA 在SCK 时钟下降沿之后改变状态,并仅在SCK 上升沿有效1.3、串行数据(SCK)SCK 用于微处理器与DHT22之间的通讯同步。

DHT11和DHT22(AM2302)温湿度传感器模块驱动程序的区别

DHT11和DHT22(AM2302)温湿度传感器模块驱动程序的区别

DHT11和DHT22(AM2302)温湿度传感器模块驱动程序的区别1.说明官⽅产品页显⽰ DHT11 模块和 DH22(AM2302)模块均已停产,推荐使⽤ DHT20 模块(DHT11升级款)。

2.技术参数对⽐DHT11 技术参数供电电压 DC:3.3-5.5V测量范围 T -20~+60℃测量范围 H 5~95%RH温度精度 ±2℃湿度精度 ±5%RH分辨率温度:0.1℃湿度:1%RH衰减值 T <0.1℃/年衰减值 H <1%RH/年传感器电容式湿度传感器输出信号单总线数字信号外壳材料 ABS塑料重量 1gDHT22(AM2302) 技术参数供电电压 DC:3.3-5.5V测量范围 T -40~+80℃测量范围 H 0~99.9%RH温度精度 ±0.5℃湿度精度 ±2%RH分辨率温度:0.1℃湿度:0.1%RH衰减值 T <0.1℃/年衰减值 H <0.5%RH/年传感器电容式湿度传感器输出信号单总线数字信号外壳材料 PC塑料3.驱动程序区别DHT11 模块和 DH22(AM2302)模块采⽤相同的单总线协议,区别在于读数:## DHT11 接收到的40位数据为:00110101 00000000 00011000 00000100 01010001湿度⾼8位湿度低8位温度⾼8位温度低8位校验位校验计算:00110101 + 00000000 + 00011000 + 00000100 = 01010001表⽰接收数据正确。

转换:湿度:00110101(整数) = 35H = 53%RH00000000(⼩数) = 00H = 0.0%RH=> 53%RH + 0.0%RH = 53.0%RH温度:00011000(整数) = 18H = 24℃00000100(⼩数) = 04H = 0.4℃=> 24℃ + 0.4℃ = 24.4℃## DHT22 接收到的40位数据为:00000010 10010010 00000001 00001101 1010010湿度⾼8位湿度低8位温度⾼8位温度低8位校验位校验计算:00000010 + 10010010 + 00000001 + 00001101 = 1010010表⽰接收数据正确。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

AM2302温湿度传感器C程序(测试可以用)
2017-8-13
说明:
DHT22与DHT11程序基本相同,DHT11起始信号拉低18ms, DHT22起始信号拉低是800us,用户主机(MCU)发送一次起始信号(把数据总线SDA拉低至少800卩9后,AM2302从休眠模式转换到高速模式。

待主机开始信号结束后,AM2302发送响应信号,从数据总线SDA串行送出40Bit的数据,先发送字
节的高位;发送的数据依次为湿度高位、湿度低位、温度高位、温度低位、校验位,发送数据结束触发一次信息采集,采集结束传感器自动转入休眠模式,直到下一次通信来临。

注意事项:
与DHT11相同,一次采集8个位数据,循环4次采集完成所有数据,40位采集完成后,校验数据,如果数
据正确,将高8位左移8位与低8位相或,再保存到一个16位变量中,就可以得到一个整数值。

默认采集的数据是实际值的10倍,例如当前实际温度是度,采集到的数据是327,目的是为了编程时方便
分离数据。

(详细见后面说明书)
0000 0010 1000 1100 0000 0001 0101 1111 1110 1110
湿度数据温度数据校验和
湿度高8位+湿度低8位+温度高8位+温度低8位=的末8位=校验和如果需要处理零下值,16位的最高位为1表示负数,温度最大量程:-20~80度,分辨率:度。

如果用数据码管显示且有中断,采集数据开始需要关中断,采集结束开中断,否则在采集数据过程中,中断会打断DHT22时序,造成采集数据不正确。

每次采集间隔大于1秒,否则采集数据不准确。

C程序:
为了方便程序阅读,其它器件的初始化及定义都删除掉了,以下代码纯DHT22代码,使用时直接调用
RH函数即可。

由于程序多次修改,可能有多余的变量,大家自己清理下。

RH函数调用后,以下四个变量会得相应的数据:
R_H R_L T_H T_L 湿度咼8位
湿度低8位(包含小数)温度咼8位
湿度低8位(包含小数)
如果采集的数据是:0000 0010 1000 1100 0000 0001 0101 1111
由上面四个变量是16位,采集数据是8位,分四次采完,8位放在16位里面应该是这样: R_H= 00000000 00000010
R_L= 00000000
所以R_H左移8个位或上R_L才是我们要的数据。

R_H =R_H & R_L
以上采集数据湿度为652,湿度为351,再除以10就是实际温湿度值。

#in elude
<>
#in elude
<>
typedef un sig ned char U8;
*/
typedef sig ned char S8;
*/
typedef un sig ned int U16;
量*/
typedef sig ned int S16;
typedef un sig ned long U32;
量*/
typedef sig ned long S32;
typedef float F32;
度)*/
typedef double F64
;
长度)*/
/* defined for unsigned 8-bits integer variable
/* defined for signed 8-bits integer variable
/* defined for unsigned 16-bits integer variable
/* defined for signed 16-bits integer variable
/* defined for unsigned 32-bits integer variable
/* defined for signed 32-bits integer variable
/* single precision floating point variable (32bits)
无符号8位整型变量
有符号8位整型变量
无符号16位整型变
有符号16位整型变量*/
无符号32位整型变
有符号32位整型变量*/
单精度浮点数(32位长
/* double precision floating point variable (64bits) 双精度浮点数(64 位
vcc
MCU
II
1
1
1
DHT22
Z
3
4-NC
<rNP
―Z IlLlU^ ——
I fiOlJE
—主枷拉咅
10-JOte
主机侑号PHTtr 号
7 Clij ST
倍号线说明:
主机伯号
rnrrf書

图5所

信号线说明:
主机倍号
DHT 倩号
图5
5、 测量分辨率
测量分辨率分别为16bit (温度)、16bit (湿度)。

6、 电气特性
VDD=5V T = 25c ,除非特殊标注
参数 条件
min typ
max 单位
供电
DC
6
V 供电电流 测量 1
mA 待机 40
50
uA
采样周期

2

注:采样周期间隔不得低于 2秒钟(建议2秒以上)。

7、应用信息
工作与贮存条件
超出建议的工作范围可能导致高达3%RH 勺临时性漂移信号。

返回正常工作条后,传感 器会缓慢地向校准状态恢复。

要加速恢复进程 /可参阅小节的恢复处理”。

在非正常工作条件 下长时间使用会加速产品的老化过程。

暴露在化学物质中
电容式湿度传感器的感湿层会受到化学蒸汽的干扰, 化学物质在感应层中的扩散可能导 致测量值漂移和灵敏度下降。

在一个纯净的环境中,污染物质会缓慢地释放出去。

下文所述 的恢复处理将加速实现这一过程。

高浓度的化学污染会导致传感器感应层的彻底损坏。

恢复处理
置于极限工作条件下或化学蒸汽中的传感器, 通过如下处理程序,可使其恢复到校准时 的状态。

在50-60C 和< 10%RH 勺湿度条件下保持2小时(烘干);随后在20-30C 和>70%RH 勺 湿度条件下保持5小时以上。

温度影响
气体的相对湿度,在很大程度上依赖于温度。

因此在测量湿度时,应尽可能保证湿度传 感器在同一温度下工作。

如果与释放热量的电子元件共用一个印刷线路板,在安装时应尽可 能将DHT22远离发热电子元件,并安装在热源下方,同时保持外壳的良好通风。

光线
长时间暴露在太阳光下或强烈的紫外线辐射中,会使性能降低。

配线注意事项
vcc - ONT>
I I 表示W
〔 ..
®
-
- - * --P r —
I MM 开始I
下——|>址开

DATA 言号线材质量会影响通讯距离和通讯质量 8、封装信息
①小体积圭寸装
引脚号:从左到右顺序为 1、2、3、4. DHT22小体积封装引脚说明
Pin
名称
注释
1 VDD 供电—6VDC
2 DATA 串行数据,单总线
3 NC 空脚,请悬空 4
GND
接地,电源负极
Q
HU i
___ 乓 ______________ L_L__ J
3. Sunn
| MAX -imia
t*十 DHT22带电
路板安装壳封装引脚说明,大封装:
Pin
名称 注释 1 VDD 供电 DC 2
DATA
串行数据,单总线
,推荐使用高质量屏蔽线。

②带电路板安装壳封装
28II mi
< ----------------- 22iuni ------------------- ►
12 3 4。

相关文档
最新文档