Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *-----------------------------------------------------------------------------
- * Temperature measurement with NTC thermistors and the Teensy 3.2 board.
- * This is the schema how the NTC is connected to the Teensy.
- *
- * <AREF (3.3V)>-----[Series Resistor]-----+-----[NTC]-------<Ground>
- * |
- * |
- * {Analog Pin A11}
- *
- * Author: huebi
- *-----------------------------------------------------------------------------
- */
- #include <math.h>
- // Enumerating the three major temperature scales
- enum {
- T_KELVIN=0,
- T_CELSIUS,
- T_FAHRENHEIT
- };
- // manufacturer data for the thermistor
- const float B = 3470.0; // Thermistor "B" parameter.
- const float T0 = 298.15; // nominal temperature in K. In most cases 25 Celsius
- const float R0 = 5000.0; // nominal resistance in Ohm at the nominal temperature
- // settings for the electric schema
- const int AnalogPin = 11; // Analog Pin 10 is connected to the NTC
- const int RS = 4990; // Series resistor of the NTC in Ohm
- #define NTCM_HP_5k AnalogPin,B,T0,R0,RS // B,T0,R0
- const float AbsZero = -273.15; // Absolute zero point of temperature in Celsius
- const int ADresBits = 14; // The resolution of the A/D converter to 14 bits
- const int ADsamples = 16; // Number of samples approximated for each mesurement
- float ADmaxRead; // The resolution of the A/D converter in steps
- float Temperature(int OutputUnit,int AnalogPin,float B,float T0,float R0,float RS)
- {
- float R; // Actuall NTC resistance
- float T; // Actuall NTC temperature
- int ADread; // A/D Converter input
- ADread = analogRead(AnalogPin);
- R = RS * ADread / ADmaxRead / (1 - ADread / ADmaxRead);
- T = T0 * B / (B + T0 * log(R / R0));
- switch(OutputUnit) {
- case T_CELSIUS :
- T = T + AbsZero;
- break;
- case T_FAHRENHEIT :
- T=9.0f*(T + AbsZero)/5.0f+32.0f;
- break;
- default: // T_KELVIN
- break;
- };
- return T;
- }
- void setup() {
- ADmaxRead=pow(2,ADresBits)-1;
- Serial.begin(115200);
- while (!Serial); // Wait for the serial monitor to open to continue
- analogReadRes(ADresBits);
- analogReadAveraging(ADsamples);
- }
- void loop() {
- Serial.print("Temperature: ");
- Serial.print(Temperature(T_CELSIUS,NTCM_HP_5k));
- Serial.println(" Celsius");
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement