-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSubniSimpleNTC.cpp
More file actions
62 lines (49 loc) · 1.17 KB
/
SubniSimpleNTC.cpp
File metadata and controls
62 lines (49 loc) · 1.17 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* SimpleNTC.cpp - Library for interacting with NTC thermistors
*
*/
#include "SubniSimpleNTC.h"
/**
* Returns the temperature in kelvin for the given resistance value
* using the Steinhart-Hart polynom.
*/
double SubniSimpleNTC::simpleNTC(double r)
{
double kelvin;
kelvin = log(r);
kelvin /= _beta;
kelvin += 1.0 / ROOMTEMPK;
kelvin = 1.0 / kelvin;
return kelvin;
}
double SubniSimpleNTC::getKelvin()
{
uint16_t adc_read;
double adc_raw, voltage, resistance;
/*
adc_read =0;
for(int i = 0; i < 16; i++)
{
adc_read += analogRead(_reading_pin);
delay(10);
}
adc_read = adc_read >> 4;
adc_raw = (double)adc_read;
*/
adc_raw = (double)AnalogTools.read(_reading_pin);
voltage = (adc_raw / 1024) * V_IN;
//resistance = ((1024 * _resistance / adc_raw) - _resistance);
adc_raw = (1023 / adc_raw) - 1;
adc_raw = _resistance / adc_raw;
resistance = adc_raw / THERMISTOR;
// Account for dissipation factor K
return (simpleNTC(resistance) - ((voltage * voltage) / (_k * _resistance)));
}
double SubniSimpleNTC::getCelsius()
{
return getKelvin() - 273.15;
}
double SubniSimpleNTC::getFahrenheit()
{
return getCelsius() * 9/5 + 32;
}