圣源电子制作

 找回密码
 立即注册
查看: 6910|回复: 0
打印 上一主题 下一主题

Arduino电子积木-SHT1X温湿度传感器 *

[复制链接]
跳转到指定楼层
楼主
发表于 2012-4-28 23:39:23 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
转载自互联网!!!仅供学习
Arduino电子积木传感器分为数字传感器和模拟传感器两类,数字传感器就接到数字口,模拟传感器就接到模拟口,两者绝对不能互换。

我们的数字传感器的线序是根据舵机的线序定义的(即信号、电源、地),由于数字传感器的电源在中间引脚上,所以就不怕被插接反而烧坏。而模拟传感器的线序是根据夏普GP2D12红外线的线序定义的(即信号、地、电源),由于电源不在中间,所以在使用时就需要注意线的方向。我们为2种传感器分别加工了数据线,在使用过程中,需要区分传感器的种类和传感器连接线的颜色。

数字传感器连接线(黑红绿

模拟传感器连接线(红黑蓝)

数字与模拟传感器端口有1,2,3的数字标记,定义分别如下:

数字传感器:

1脚-------------信号数输出(D)----对应数字传感器连接线绿色

2脚-------------电源正(VCC)----对应数字传感器连接线红色

3脚-------------电源负(GND)----对应数字传感器连接线黑色

模拟传感器:

1脚-------------信号数输出(S)----对应模拟传感器连接线蓝色

2脚-------------电源负(GND)----对应模拟传感器连接线黑色

3脚-------------电源正(VCC)----对应模拟传感器连接线红色

在使用我们的传感器时要注意,先判断该传感器是数字的还是模拟的,然后观察连接线的颜色是否是对应的连接线。

数字传感器-SHT1X温湿度传感器:

瑞士Sensirion公司推出了SHT1x单片数字温湿度集成传感器。采用CMOS过程微加工专利技术(CMOSens technology),确保产品具有极高的可靠性和出色的长期稳定性。该传感器由1个电容式聚合体测湿元件和1个能隙式测温元件组成,并与1个14位A/D转换器以及1个2-wire数字接口在单芯片中无缝结合,使得该产品具有功耗低、反应快、抗干扰能力强等优点。

在对环境温度与湿度测量要求高的情况下使用,该产品具有极高的可靠性和出色的稳定性。与Arduino专用传感器扩展板结合使用,可以非常容易地实现与温度和与湿度感知相关的互动效果。

SHT1X温湿度传感器使用2根数字传感器连接线与Arduino传感器扩展板连接,一根数据信号线(DATA)接数字口PIN10,一根时钟信号线(SCK)接数字口PIN11。


Arduino库文件下载

Arduino库文件.zip (4.76 KB, 下载次数: 4)


Arduino测试代码:
  1. <p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">#i nclude <SHT1x.h></font></span></p><p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">// Specify data and clock connections and instantiate SHT1x object
  2. #define dataPin  10
  3. #define clockPin 11
  4. SHT1x sht1x(dataPin, clockPin);</font></span></p><p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">void setup()
  5. {
  6.    Serial.begin(38400); // Open serial connection to report values to host
  7.    Serial.println("Starting up");
  8. }</font></span></p><p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">void loop()
  9. {
  10.   float temp_c;
  11.   float temp_f;
  12.   float humidity;</font></span></p><p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">  // Read values from the sensor
  13.   temp_c = sht1x.readTemperatureC();
  14.   temp_f = sht1x.readTemperatureF();
  15.   humidity = sht1x.readHumidity();</font></span></p><p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">  // Print the values to the serial port
  16.   Serial.print("Temperature: ");
  17.   Serial.print(temp_c, DEC);
  18.   Serial.print("C / ");
  19.   Serial.print(temp_f, DEC);
  20.   Serial.print("F. Humidity: ");
  21.   Serial.print(humidity);
  22.   Serial.println("%");</font></span></p><p align="left" style="color: rgb(51, 51, 51); font-family: serif; font-size: 13px; line-height: 20px; "><span style="line-height: 23px; font-size: small; background-color: white;"><font size="2">  delay(2000);
  23. }</font></span></p>
复制代码

测试结果可以在串口助手中看到。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|联系我们|闽公网安备 35012102000020号|闽ICP备11020110号-1|圣源电子

GMT+8, 2024-9-20 07:59 , Processed in 0.045037 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表