Created
November 26, 2016 14:39
-
-
Save wakasann/44561810d7c3326d945e032ad07d01ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int potPin = 2; //定义模拟端口2连接LM35温度传感器 | |
void setup() | |
{ | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
int val; //存放读取的电压值 | |
int dat; //存放温度 | |
val = analogRead(potPin); | |
Serial.print("Val:"); | |
Serial.println(val); | |
//@link http://www.arduino.cn/forum.php?mod=viewthread&tid=7309 | |
//V=Vref*val/1024 | |
//10mV*T=Vref*val/1024,eg:Vref = 5000mV | |
//10mV * T = 5000mV * val / 1024 | |
//T = 500mV * val / 1024 | |
//T = 500mV * val / 256 * 4 | |
//T = 125 * val / 256 ,in C /256 eq >> 8 | |
//T = (125 * val) >> 8 | |
dat = (125 * val) >> 8; | |
Serial.print("Tep:"); | |
Serial.print(dat); | |
Serial.println("C"); | |
Serial.println("---------------------------------"); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment