Arduino-湿度传感器_第1页
Arduino-湿度传感器_第2页
Arduino-湿度传感器_第3页
Arduino-湿度传感器_第4页
Arduino-湿度传感器_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

1、Arduino - 湿度传感器在本节中,我们将学习如何使不同的传感器连接我们的 Arduino 板。 我们将讨论以 下传感器 -湿度传感器(DHT22温度传感器(LM35检测传感器(简单触发PIR 传感器超声波传感器GPS湿度传感器 (DHT22DHT-22(也称为 AM2302 是个数字输出,相对湿度和温度传感器。 它使电容式湿 度传感器和热敏电阻测量周围空,并在数据引脚上发送数字信号。在本例中,您将了解如何将此传感器与 Arduino UNO起使。 室温和湿度将打印到 串监视器上。DHT-22 传感器连接很简单。 左边的第个引脚为 3-5V 电源,第个引脚连接到数据输引脚,最右 边的引脚连

2、接到地。技术细节电源 - 3-5V最电流 - 2.5mA湿度 - 0-100%,精确度为 2-5%温度 - 40 80°C,精度为 ±0.5°C必需的组件您将需要以下组件 -1 × Breadboard 包板1 × Arduino Uno R31 × DHT221 × 10K欧姆电阻程序 按照电路图并挂接包板上的组件,如下图所。草图在计算机上打开 Arduino IDE软件。 在 Arduino 语编码将控制你的电路。 通过单击新 建打开个新的草图件。Arduino 代码/ Example testing sketch fo

3、r various DHT humidity/temperature sens #include "DHT.h"#define DHTPIN 2 / what digital pin we're connected to/ Uncomment whatever type you're using!/#define DHTTYPE DHT11 / DHT 11#define DHTTYPE DHT22 / DHT 22 (AM2302, AM2321/#define DHTTYPE DHT21 / DHT 21 (AM2301/ Connect pin 1 (

4、on the left of the sensor to +5V/ NOTE: If using a board with 3.3V logic like an Arduino Due conne / 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 / I

5、nitialize DHT sensor./ Note that older versions of this library took an optional third / tweak the timings for faster processors. This parameter is no lo / as the current DHT reading algorithm adjusts itself to work on f DHT dht(DHTPIN, DHTTYPE;void setup( Serial.begin(9600;Serial.println("DHTx

6、x test!"dht.begin(;void loop( delay(2000; / Wait a few seconds between measurementsfloat h = dht.readHumidity(;/ Reading temperature or humidity takes about 250 milliseconds! float t = dht.readTemperature(;/ Read temperature as Celsius (the defaultfloat f = dht.readTemperature(true;/ Read tempe

7、rature 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 defaultfloat hif = puteHeatIndex(f, h;/ Compute heat index in Ce

8、lsius (isFahreheit = falsefloat 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传感器具有四个端 (V cc, DATA , NC , GND ,它们连接到电路板,如下 : DATA 引脚连接到 Arduino 引脚号 2Vcc 引脚到 5伏的 Arduino 板GND 引脚连接到 Arduino 板的地我们需要在 DA

温馨提示

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

评论

0/150

提交评论