2017/03/04

Arduino LM35DZ 取得溫度

以圓點為正面從左開始定義為Pin1
1 GND
2 A0
3 5V



執行結果:










程式碼:
/*
 Name:  LM35DZ.ino
 Created: 2017/3/3 下午 10:33:13
 Author: C.Y.Fang
*/

static int val;

// the setup function runs once when you press reset or power the board
void setup() {
 Serial.begin(9600);
}

// the loop function runs over and over again until power down or reset
void loop() {
 val = analogRead(A0);
 Serial.print(getTempToDoubleC());
 Serial.print(",");
 Serial.println(getTempToIntC());
 delay(1000);
}


double getTempToDoubleC() {
 return (5.0 * val * 100.0) / 1024.0;
}

double getTempToIntC() {
 return  (125 * val) >> 8;
}

參考資料:
http://designer.mech.yzu.edu.tw/articlesystem/article/compressedfile/(2003-10-20)%20%E6%BA%AB%E5%BA%A6%E6%84%9F%E6%B8%AC%E5%99%A8LM35%E4%BB%8B%E7%B4%B9.aspx?ArchID=546
http://playground.arduino.cc/Main/LM35HigherResolution
http://alex9ufoexploer.blogspot.tw/2013/04/arduino-lm35.html