Engduino v2.1
|
This is the driver code for reading temperature. More...
Files | |
file | EngduinoThermistor.cpp |
Engduino Thermistor driver. | |
file | EngduinoThermistor.h |
Engduino Thermistor driver. | |
Functions | |
EngduinoThermistorClass::EngduinoThermistorClass () | |
Constructor. | |
void | EngduinoThermistorClass::begin () |
begin function - must be called before using other functions | |
void | EngduinoThermistorClass::end () |
end function - switch off the LEDs | |
float | EngduinoThermistorClass::temperature (temperatureUnits units=CELSIUS) |
Get the temperature. | |
float | EngduinoThermistorClass::temperature (temperatureUnits units, float B, float T0, float R0, float R_Balance) |
Get the temperature. | |
uint16_t | EngduinoThermistorClass::temperatureRaw () |
Get the raw potential divider reading. |
This is the driver code for reading temperature.
This can equally well be done in a sketch file, but it is also here for completeness
The Engduino has a Murata NCP18WF104J03RB thermistor attached to analogue input A5. This thermistor has a resistance of 100K at 25C.
void EngduinoThermistorClass::begin | ( | ) |
begin function - must be called before using other functions
Nothing to be done.
Definition at line 45 of file EngduinoThermistor.cpp.
void EngduinoThermistorClass::end | ( | ) |
end function - switch off the LEDs
Nothing to be done.
Definition at line 56 of file EngduinoThermistor.cpp.
EngduinoThermistorClass::EngduinoThermistorClass | ( | ) |
Constructor.
C++ constructor for this class. Empty.
Definition at line 35 of file EngduinoThermistor.cpp.
float EngduinoThermistorClass::temperature | ( | temperatureUnits | units = CELSIUS | ) |
Get the temperature.
units | A choice between CELSIUS (default), KELVIN, or FAHRENHEIT |
This function makes a call to the function that actually works out what a particular resistance means.
For the Murata NCP18WF104J03RB, the thermistor has a resistance of 100K at 25C and a B value of 4250 and a 100K balance resistor.
Definition at line 73 of file EngduinoThermistor.cpp.
float EngduinoThermistorClass::temperature | ( | temperatureUnits | units, |
float | B, | ||
float | T0, | ||
float | R0, | ||
float | R_Balance | ||
) |
Get the temperature.
units | A choice between CELSIUS (default), KELVIN, or FAHRENHEIT |
B | Parameter in the B equation - see data sheet |
T0 | Temperature in Kelvin at which resistance is R0 - see data sheet |
R0 | Resistance at temperature T0 - see data sheet |
R_Balance | Value of the balance resistor in the potential divider (100K on Engduino v1.0) |
This function measures the voltage and, as a consequence, calculates the resistance of the thermistor. From this, we can figure out the actual temperature
NTC thermistors can be characterised with the B (or beta) parameter equation,
1/T = 1/T0 + 1/B*ln(R/R0)
Where the temperatures are in Kelvin and R0 is the resistance at temperature T0 (25 °C = 298.15 K).
So far as the resistance is concerned, we have a potential divider with a balance resistor of value R_Balance. Assuming that the resistance of the NTC is R and the voltage across it is V, then Ohms law gives: V/Vcc = R/(R + R_Balance)
Given that V/Vcc is just (analog in)/1024 for a 10 bit ADC, we can work out that: R = (R_Balance * analogIn) / (1024 - analogIn)
Definition at line 110 of file EngduinoThermistor.cpp.
uint16_t EngduinoThermistorClass::temperatureRaw | ( | ) |
Get the raw potential divider reading.
Raw voltage reading from NTC potential divider circuit
Definition at line 141 of file EngduinoThermistor.cpp.