Very simple library for reading temperature from NTC thermistors

Dependents:   lightweight-weather-station

Committer:
programy1
Date:
Sun May 17 18:18:29 2020 +0000
Revision:
1:424e85f62cd8
Parent:
0:5459d9074b70
added comment for function documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
programy1 0:5459d9074b70 1 /** Measuring temperature with thermistor
programy1 0:5459d9074b70 2 *
programy1 0:5459d9074b70 3 * Example of use:
programy1 0:5459d9074b70 4 * @code
programy1 0:5459d9074b70 5 * #include "mbed.h"
programy1 0:5459d9074b70 6 * #include "thermistor.h"
programy1 0:5459d9074b70 7 *
programy1 0:5459d9074b70 8 * Serial pc(USBTX, USBRX); // serial communication
programy1 0:5459d9074b70 9 *
programy1 0:5459d9074b70 10 * int main() {
programy1 0:5459d9074b70 11 * Thermistor my_thermistor(A5, 10000, 3950, 4700); // instantiate the sensor object (on pin A5, nominal resistance is 10kOhms, beta coefficient is 3950 and value of the sacond resistor is 4,7kOhms
programy1 0:5459d9074b70 12 * while(1) {
programy1 0:5459d9074b70 13 * pc.printf("Temperature: %5.1f celsius degrees\r", my_thermistor.temperature());
programy1 0:5459d9074b70 14 * pc.printf("Resistance: %5.1f ohms\r", my_thermistor.resistance());
programy1 0:5459d9074b70 15 * wait_ms(1000);
programy1 0:5459d9074b70 16 * }
programy1 0:5459d9074b70 17 * }
programy1 0:5459d9074b70 18 * @endcode
programy1 0:5459d9074b70 19 */
programy1 0:5459d9074b70 20 class Thermistor
programy1 0:5459d9074b70 21 {
programy1 0:5459d9074b70 22
programy1 0:5459d9074b70 23 public:
programy1 0:5459d9074b70 24
programy1 0:5459d9074b70 25 /**
programy1 0:5459d9074b70 26 * @param thermistorpin mbed analog pin to which the thermistor is connected to
programy1 0:5459d9074b70 27 * @param nominalres resistance of thermistor at 25 celsius degrees
programy1 0:5459d9074b70 28 * @param beta beta coefficient of thermistor
programy1 0:5459d9074b70 29 * @param seriesresistor value of the resistor connecter with thermistor
programy1 0:5459d9074b70 30 */
programy1 0:5459d9074b70 31 Thermistor(PinName thermistorpin, int nominalres, int beta, int seriesresistor);
programy1 0:5459d9074b70 32
programy1 0:5459d9074b70 33 /**
programy1 0:5459d9074b70 34 * @returns temperature in celsius degrees
programy1 0:5459d9074b70 35 */
programy1 0:5459d9074b70 36 float temperature();
programy1 0:5459d9074b70 37 void get_temperature();
programy1 1:424e85f62cd8 38 /**
programy1 1:424e85f62cd8 39 * @returns resistance of thermistor
programy1 1:424e85f62cd8 40 */
programy1 0:5459d9074b70 41 float resistance();
programy1 0:5459d9074b70 42 void init();
programy1 0:5459d9074b70 43
programy1 0:5459d9074b70 44 private:
programy1 0:5459d9074b70 45
programy1 0:5459d9074b70 46 int temperaturenominal;
programy1 0:5459d9074b70 47 AnalogIn thermistorpin;
programy1 0:5459d9074b70 48 int nominalres;
programy1 0:5459d9074b70 49 int beta;
programy1 0:5459d9074b70 50 int seriesresistor;
programy1 0:5459d9074b70 51 float temp;
programy1 0:5459d9074b70 52 float res;
programy1 0:5459d9074b70 53 float steinhart;
programy1 0:5459d9074b70 54 int a;
programy1 0:5459d9074b70 55
programy1 0:5459d9074b70 56 };