Arduino 教程--第三十五课 Arduino 湿度传感器.doc_第1页
Arduino 教程--第三十五课 Arduino 湿度传感器.doc_第2页
Arduino 教程--第三十五课 Arduino 湿度传感器.doc_第3页
Arduino 教程--第三十五课 Arduino 湿度传感器.doc_第4页
Arduino 教程--第三十五课 Arduino 湿度传感器.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第三十五课 Arduino 湿度传感器在本节中,我们将学习如何使用不同的传感器连接我们的Arduino板。我们将讨论以下传感器: 湿度传感器(DHT22) 温度传感器(LM35) 水位检测传感器(简单水触发器) PIR传感器 超声波传感器 GPS湿度传感器(DHT22)DHT-22(也称为AM2302)是一个数字输出,相对湿度和温度传感器。它使用电容式湿度传感器和热敏电阻来测量周围空气,并在数据引脚上发送数字信号。在本例中,你将学习如何将此传感器与Arduino UNO一起使用。室温和湿度将打印到串口监视器上。DHT-22传感器连接很简单。左边的第一个引脚为3-5V电源,第二个引脚连接到数据输入引脚,最右边的引脚接地。技术细节 电源- 3-5V 最大电流- 2.5mA 湿度- 0-100,精确度为2-5 温度- 40至80C,精确度为0.5C必需的组件你将需要以下组件: 1 Breadboard 面包板 1 Arduino Uno R3 1 DHT22 1 10K欧姆电阻程序按照电路图连接面包板上的组件,如下图所示。草图在计算机上打开Arduino IDE软件。使用Arduino语言进行编码控制你的电路。通过单击“New”打开一个新的草图文件。Arduino代码/ Example testing sketch for various DHT humidity/temperature sensors#include DHT.h#define DHTPIN 2 / what digital pin were connected to/ Uncomment whatever type youre using!/#define DHTTYPE DHT11 / DHT 11#define DHTTYPE DHT22 / DHT 22 (AM2302), AM2321/#define DHTTYPE DHT21 / DHT 21 (AM2301)/ Connect pin 1 (on the left) of the sensor to +5V/ NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1/ to 3.3V instead of 5V!/ Connect pin 2 of the sensor to whatever your DHTPIN is/ Connect pin 4 (on the right) of the sensor to GROUND/ Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor/ Initialize DHT sensor./ Note that older versions of this library took an optional third parameter to/ tweak the timings for faster processors. This parameter is no longer needed/ as the current DHT reading algorithm adjusts itself to work on faster procs.DHT dht(DHTPIN, DHTTYPE);void setup() Serial.begin(9600); Serial.println(DHTxx test!); dht.begin();void loop() delay(2000); / Wait a few seconds between measurements float h = dht.readHumidity(); / Reading temperature or humidity takes about 250 milliseconds! float t = dht.readTemperature(); / Read temperature as Celsius (the default) float f = dht.readTemperature(true); / Read temperature as Fahrenheit (isFahrenheit = true) / Check if any reads failed and exit early (to try again). if (isnan(h) | isnan(t) | isnan(f) Serial.println(Failed to read from DHT sensor!); return; / Compute heat index in Fahrenheit (the default) float hif = puteHeatIndex(f, h); / Compute heat index in Celsius (isFahreheit = false) float hic = puteHeatIndex(t, h, false); Serial.print (Humidity: ); Serial.print (h); Serial.print ( %t); Serial.print (Temperature: ); Serial.print (t); Serial.print ( *C ); Serial.print (f); Serial.print ( *Ft); Serial.print (Heat index: ); Serial.print (hic); Serial.print ( *C ); Serial.print (hif); Serial.println ( *F);代码说明DHT22传感器具有四个端子连接到电路板的端子(Vcc,DATA,NC,GND),如下: DATA引脚连接到Arduino的2号引脚号 Vcc引脚连接到

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论