このLM61CIZセンサーは-30℃〜100℃を
---------------------------------------------------------------------
void setup() {
Serial.begin(9600) ; // パソコン(ArduinoIDE)とシリアル通信の準備を行う
}
void loop() {
int ans , temp , tv ;
ans = analogRead(0) ; // アナログ0番ピンからセンサー値を読込む
tv = map(ans,0,1023,0,5000) ; // センサー値を電圧に変換する
temp = map(tv,600,3200,-30,100) ; // 電圧から温度に変換する
Serial.println(temp) ; // 値をパソコン(IDE)に送る
delay(1000) ; // 1秒毎に繰り返す
}
---------------------------------------------------------------------
LM61CIZセンサーのみの出力では
---------------------------------------------------------------------
void setup() {
Serial.begin(9600) ; // パソコン(ArduinoIDE)とシリアル通信の準備を行う
}
void loop() {
int ans , tv ;
float temp ;
ans = analogRead(0) ; // アナログ0番ピンからセンサー値を読込む
tv = map(ans,0,1023,0,5000) ; // センサー値を電圧に変換する
temp = fmap(tv,900,4800,-30,100) ; // 電圧から温度に変換する
Serial.println(temp) ; // 値をパソコン(IDE)に送る
delay(1000) ; // 1秒毎に繰り返す
}
float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
---------------------------------------------------------------------
fmap()は、map()関数をコピーしてfloat(実数)で計算する様にしただけです。
もちろん3倍にしたので
【きむ茶工房ガレージハウス】
Copyright (C) 2006-2011 Shigehiro Kimura All Rights Reserved.