-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermistor.ino
39 lines (36 loc) · 1.01 KB
/
thermistor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//www.elegoo.com
//2016.12.9
#include <LiquidCrystal.h>
int tempPin = 0;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
int tempReading = analogRead(tempPin);
// This is OK
double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
/* replaced
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 10.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
*/
// Display Temperature in C
lcd.setCursor(0, 0);
lcd.print("Temp C");
lcd.setCursor(6,0);
lcd.print(tempC);
lcd.setCursor(0, 1);
lcd.print("Temp F");
lcd.setCursor(6,1);
lcd.print(tempF);
Serial.println(tempF);
delay(200);
}