x かころぐみよ
参考
結果
/*
/* Grove - Temperature Sensor demo v1.0
* This sensor detects the environment temperature,
* Connect the signal of this sensor to A0, use the
* Serial monitor to get the result.
* By: https://www.seeedstudio.com
*/
#include <math.h>
int a;
float temperature;
int B=3975; //B value of the thermistor
float resistance;
void setup()
{
Serial.begin(9600);
}
void loop()
{
//a=analogRead(0);
//a=analogRead(15);
a=analogRead(1);
//resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
float v1,a1,o1;
v1 = ((float)a) * 0.001; //電圧を求める
a1 = v1 / 10000.0; //電流を求める
o1 = 5.0 / a1; //全体の抵抗を求める
resistance = o1 - 10000.0; //全体の抵抗から検出抵抗を引く
//Serial.println(v1); //debug
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
delay(1000);
Serial.print("Current temperature is ");
Serial.println(temperature);
}