我正在尝试使用 D1 mini 和 NTC 来监控温度,它正在工作,但温度计算错误。在串行监视器上,我得到的温度约为 -300°C。
打印电阻时,我在 25°C 时得到的电阻值约为 10kOhm,而不是规格中预期的 10Ohm。 (25°C 时的零功率电阻(欧姆)= 10) 但在 Steinhart-Hart 方程中使用 10kOhm 而不是 10Ohm 并不能解决问题...
谁能告诉我我做错了什么?
热敏电阻像这样连接到我的 D1 Mini ESP8266:
3.3V
|
\
/ TCC103
\ (Thermistor)
|
|------ A0 (Analog Input)
|
\
/ R1 (10kΩ Resistor)
\
|
|
GND
规格:
Part No = TTC-103
Zero Power Resistance at 25ºC (Ohm) = 10
B-Value R25/R50 (K) = 4050
Max. Permissible Current at 25ºC (mA) = 20
Thermal Dissipation Constant (mW/mW/ºC) = 8
Thermal Time Constant (Sec.) = 21
Operating Temperature (ºC) = -30~+125
这是我的代码:
#include <Arduino.h>
// thermistor values
const int thermistorPin = A0;
const float seriesResistor = 10000;
void setup() {
// Initialize Serial communication
Serial.begin(9600);
}
float readTemperature() {
int rawADC = analogRead(thermistorPin);
// Convert ADC reading to resistance
float resistance = seriesResistor / ((1023.0 / rawADC) - 1.0);
// Calculate the temperature using the Steinhart-Hart equation
float steinhart;
steinhart = log(resistance / 10); // 10 Ohm resistance at 25ºC
steinhart /= 4050; // B-value (beta) = 4050
// Calculate the temperature in Kelvin
float kelvin = 1.0 / steinhart;
// Invert the temperature in Celsius
float temperature = 1 - (kelvin - 273.15);
return temperature;
}
void loop() {
float temperature = readTemperature();
// Log the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(500); // Delay before checking temperature again
}
我在计算开尔文温度之前添加了这一行:
steinhart += 1.0 / (25 + 273.15); //25°C
我将温度计算更改为
float temperature = kelvin - 273.15;
我还交换了电阻和热敏电阻的位置,所以热敏电阻连接到GND,电阻连接到3V3
我还必须将 25°C 时的电阻从 10Ohm 更改为 10kOhm。
在这里您可以看到完整答案