美文网首页
mbed嵌入式编程(四) 用热敏电阻测量温度

mbed嵌入式编程(四) 用热敏电阻测量温度

作者: 光均 | 来源:发表于2020-04-27 13:15 被阅读0次

mbed嵌入式编程(四) 用热敏电阻测量温度

热敏电阻是可变电阻元件,其电阻随温度变化而变化。测量变化后的电阻值可以计算出温度。
热敏电阻分为PTC(正温度系数)或NTC(负温度系数)。
它们可用作电流限制器,温度传感器,过电流保护器等。

一般我们拿到的热敏电阻有一个阻值,是25度时侯的阻值.还会附带一个B值,比如3950


gif.gif

所有温度均为开氏温度,比如室温摄氏25度下的开氏温度为273.15+25
式子中:
T -当前温度开氏
T0 –室温,即25ºC= 298.15 K
B –热敏电阻系数(厂家在型号中就会提供,比如MF52A-103F-3950 1% NTC热敏电阻)
R0 –室温下的电阻。上例中=10k
10K NTC在室温下具有10K电阻。
R –当前电阻值

电路接线:

捕获.PNG

程序

#include "mbed.h"
#include "math.h"
#include "platform/mbed_thread.h"


Serial pc(USBTX, USBRX); // tx, rx
DigitalOut led1(LED1); //LED1
AnalogIn thr(PA_0);
float thr_val=0, thr_res=0, ln_res=0, temperature=0;

int main()
{
pc.printf("Hello World!\n\r");
while (true) {
led1 = !led1;
thr_val = thr.read();
//thr_val = 0.333333;
thr_res = (10/thr_val-10);//串联电阻=10
ln_res=log(thr_res/10);  //热敏电阻R0=10
temperature =1/(ln_res/3950+1/298.15)-273.15;
printf("Temperature = %3.3f\r\n", temperature);
printf("Resistance = %3.3f\r\n", thr_res);
thread_sleep_for(1000);
    
}
}

相关文章

网友评论

      本文标题:mbed嵌入式编程(四) 用热敏电阻测量温度

      本文链接:https://www.haomeiwen.com/subject/ljqywhtx.html