-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThermistorComparison.ino
72 lines (52 loc) · 1.68 KB
/
ThermistorComparison.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Comparison between B3950 and Generic NTC 10K Thermistor using B3950 Library
// Partha Pratim Ray
// September 8, 2023
/*
* Put the Generic Themristor to Analog Pin 1
* Put the B3950 Thermistor to Analog Pin 0
*
* 5V----> Thermistor---->10K Resistor------>GND
* |
* |
* Analog Pin
*/
#include "B3950Thermistor.h"
B3950Thermistor thermistor(A0, 10000.0, 5.0);
// ordinary 10K Thermistor
int ThermistorPin = 1;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
//B3950 NTC 10K Theristor calculation
float resistance = thermistor.readResistanceKOhms();
float temperatureCelsius = thermistor.readTemperatureCelsius();
float temperatureFahrenheit = thermistor.readTemperatureFahrenheit();
Serial.print("B3950 Thermistor Resistance: ");
Serial.print(resistance);
Serial.print(" kOhms\tTemperature: ");
Serial.print(temperatureCelsius);
Serial.print(" °C\t");
Serial.print(temperatureFahrenheit);
Serial.println(" °F");
//Ordinary NTC 10K Theristor calculation
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;
Serial.print("Generic Thermistor Resistance: ");
Serial.print(R2/1000); //Convert to KOhms
Serial.print(" kOhms\tTemperature: ");
Serial.print(Tc);
Serial.print(" °C\t");
Serial.print(Tf);
Serial.println(" °F");
delay(500);
}