com.raspoid.additionalcomponents

## Class Thermistor

• All Implemented Interfaces:
Component
Direct Known Subclasses:
ThermistorNTCLE203E3103SB0

```public class Thermistor
extends AnalogComponent```
An NTC (negative temperature coefficient) thermistor changes its effective resistance with regard to temperature. To measure a temperature, we then need to measure the value of this resistance.

To do this, we use a an ADC (Anolog to Digital Converter) to measure the voltage value around the thermistor. We then calculate the value of the thermistor resistance, using the voltage divider in place with a resistor in serie with the thermistor.

We can then convert the resistance value with the Steinhart-Hart equation.

`1/T = a + b ln(R) + c ln(R)^3`
As we don't know all the requested parameters (A, B and C), we will use the B-parameter equation, which is essentially the Steinhart-Hart equation with
```  a = (1/T0) - (1/B) ln(R0)
b = 1/B
c = 0
```

Note: with our observations, we can observe an error of about 1.4% in temperature measurements (using the Kelvin scale). A temperature of 24°C should correspond to a real temperature of 20°C. Different factors can be at the origin of this problem. It's important to keep this in mind, and use a thermistor for appropriate use. As an example, a thermistor can be used as a trigger to track a temperature exceeding a fixed threshold: alert when the tap water is too hot. It is less appropriate to precisely define the room temperature.

Formulas from: https://en.wikipedia.org/wiki/Thermistor

• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `K_TO_C`
Temperature in °C is temperature in K - K_TO_C.
`static double` `T0`
T0 coefficient from the B-parameter equalition, in K.
• ### Fields inherited from class com.raspoid.AnalogComponent

`adc`
• ### Constructor Summary

Constructors
Constructor and Description
```Thermistor(ADC adc, ADCChannel thermistorChannel, double serieResistor, double r0, double b)```
Constructor for a thermistor using a specific ADC instance, a specific channel on this ADC, and specific parameters regarding the thermistor characteristics.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `getTemperature()`
Return the measured temperature, in °C.
• ### Methods inherited from class com.raspoid.AnalogComponent

`getADC, getType`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### T0

`public static final double T0`
T0 coefficient from the B-parameter equalition, in K.

298.15K = 25°C.

See Also:
Constant Field Values
• #### K_TO_C

`public static final double K_TO_C`
Temperature in °C is temperature in K - K_TO_C.
See Also:
Constant Field Values
• ### Constructor Detail

• #### Thermistor

```public Thermistor(ADC adc,
ADCChannel thermistorChannel,
double serieResistor,
double r0,
double b)```
Constructor for a thermistor using a specific ADC instance, a specific channel on this ADC, and specific parameters regarding the thermistor characteristics.
Parameters:
`adc` - the ADC to use to decode analog voltage values around the thermistor.
`thermistorChannel` - the channel used on the ADC to read voltage values around the thermistor.
`serieResistor` - the value of the resistance placed in serie with the thermistor.
`r0` - the resistance of the thermistor, at 25 degrees Celsius (cfr thermistor datasheet).
`b` - the B-parameter equation coefficient (cfr thermistor datasheet).
• ### Method Detail

• #### getTemperature

`public double getTemperature()`
Return the measured temperature, in °C.

Keep in mind the note presented in this class header: `Thermistor`

Returns:
the measured temperature, in °C.