サーミスタで温度測定
抵抗にかかる電圧をアナログリードで調べてそれからサーミスタの抵抗を求めます。
温度を求める式は難しくて意味がわかりませんでした。
ほぼネットからのコピペですいません・・・
#include <math.h>
int analog = 0; //アナログpin 生値
int V_0 = 5000; //回路電源[mV]
double V_R0 =1; //部分電圧[mV]
int circuit_R0 =10000; //回路内抵抗[Ω]
int thermo_B = 3435; //サーミスタB定数103-AT2
int thermo_R0 = 10000; //サーミスタ基準抵抗値[Ω]
int thermo_T0 = 298; //サーミスタ基準温度[K]
double thermo_R = 1; //サーミスタ抵抗値[Ω]
double temp = 25.00; //測定温度[℃]
void setup () {
Serial.begin(9600); /* 9600 bpsで接続 */
Serial.println("READ_START"); /* 最初に1度だけ Start を表示 */
}
void loop () {
analog=analogRead(0);
V_R0 = analog*5/ 1.024; //回路内抵抗の消費電圧を算出
thermo_R=V_0/V_R0* circuit_R0 - circuit_R0; //サーミスタの抵抗値を算出
//Serial.println( thermo_R); //サーミスタの抵抗値を表示
temp=(1000/(1/(0.001*thermo_T0)+log(thermo_R/thermo_R0)*1000/thermo_B)-273); //温度の計算
Serial.println(temp,1); //温度の表示
delay(500); // 0.5s 待つ
}