Arduino使用模拟温度传感器

来源:互联网 发布:淘宝关于dns劫持的教程 编辑:程序博客网 时间:2024/05/01 05:53
这也是37款传感器套件中的一款,传感器的样式如下图所示:
Arduino使用模拟温度传感器 - gc_2299 - gc_2299的博客
 看到这个传感器的第一个印象是它是不是和我之前接触过的LM35是一样的。于是到百度上搜了一下。找到了参考文献1和2,从里面的介绍看LM35和模拟温度传感器不是一回事。商家给的资料中介绍的是模拟温度传感器用的是热敏电阻。
模拟温度传感器的电源引脚在两侧,中间的引脚输出温度相关的模拟量,所以中间的引脚需要接在Arduino的模拟引脚之上。下图是实物连线图:
Arduino使用模拟温度传感器 - gc_2299 - gc_2299的博客
 
测试代码如下:用的就是商家资料中提供的代码:

#include<math.h>

double Thermister(int rawADC)
{
double tmp;
tmp = log(((10240000 / rawADC) - 10000));
tmp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tmp * tmp)) * tmp);
tmp = tmp - 273.15;
return tmp;
}

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int raw = analogRead(A5);
Serial.print("raw:");
Serial.print(raw);
Serial.print(",");
Serial.print(Thermister(raw));
Serial.println("c");
delay(500);
}

代码本身比较简单,应该没有什么问题,但是实际串口监视器中输出的数据却没有变化,一直都是如下的数据
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
raw:1023,334.94c
通过查找资料,看到了参考文献3,里面有一个热敏电阻测温度的原理图,图片如下:
Arduino使用模拟温度传感器 - gc_2299 - gc_2299的博客
 
根据参考文献2和3,计算热敏电阻的温度值需要一系列的参数值,但是这个模拟温度传感器的热敏电阻不知道具体型号,其它的参数也一无所知,所以对它的使用也只能到这里了。


参考资料:
[1]http://blog.sina.com.cn/s/blog_5e3f971b0100j8h0.html
[2]http://oszine.com/arduino%E4%BC%A0%E6%84%9F%E5%99%A8%E8%BF%9E%E8%BD%BD%E4%B9%8B%E6%B8%A9%E5%BA%A6%E6%B5%8B%E9%87%8F%E7%AF%87/
[3]http://blog.csdn.net/al_shawn/article/details/51287759