Skip to content

Commit fd43485

Browse files
Mathieu Maurauser2684
authored andcommitted
Thermistor ( support for NTC and offset ) (#424)
1 parent b9951f4 commit fd43485

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sensors/SensorThermistor.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class SensorThermistor: public Sensor {
3030
int _b_coefficient = 3950;
3131
long _series_resistor = 10000;
3232
float _offset = 0;
33-
33+
bool _ntc = false;
34+
3435
public:
3536
SensorThermistor(int8_t pin, uint8_t child_id = 0): Sensor(pin) {
3637
_name = "THERMISTOR";
@@ -58,6 +59,10 @@ class SensorThermistor: public Sensor {
5859
void setOffset(float value) {
5960
_offset = value;
6061
};
62+
// [106] set type of thermistor 0 for PTC, 1 for NTC (default: 0)
63+
void setNtc(bool ntc){
64+
_ntc = ntc;
65+
};
6166

6267
// define what to do during setup
6368
void onSetup() {
@@ -71,7 +76,12 @@ class SensorThermistor: public Sensor {
7176
float adc = analogRead(_pin);
7277
// calculate the temperature
7378
float reading = (1023 / adc) - 1;
74-
reading = _series_resistor / reading;
79+
if(_ntc == false){
80+
reading = _series_resistor / reading;
81+
}
82+
else{
83+
reading = _series_resistor * reading;
84+
}
7585
float temperature;
7686
temperature = reading / _nominal_resistor; // (R/Ro)
7787
temperature = log(temperature); // ln(R/Ro)
@@ -80,6 +90,7 @@ class SensorThermistor: public Sensor {
8090
temperature = 1.0 / temperature; // Invert
8191
temperature -= 273.15; // convert to C
8292
temperature = nodeManager.celsiusToFahrenheit(temperature);
93+
temperature += _offset;
8394
// store the value
8495
child->setValue(temperature);
8596
};
@@ -93,6 +104,7 @@ class SensorThermistor: public Sensor {
93104
case 103: setBCoefficient(request->getValueInt()); break;
94105
case 104: setSeriesResistor((long)request->getValueInt()); break;
95106
case 105: setOffset(request->getValueFloat()); break;
107+
case 106: setNtc(request->getValueInt()); break;
96108
default: return;
97109
}
98110
};

0 commit comments

Comments
 (0)