Hey guys,
I have a small problem. I am making a heater that is controlled by a 100K NTC 3950 thermistor and it always measures well up to 200C, but when it exceeds this temperature it starts to measure strangely, for example it gets stuck at 215C and after a few seconds jumps to 260C and I need my heater to turn off at 220C and go fluently and stably to this temperature. I think the problem is somewhere in the code, but I'm not sure.
Thank you in advance for your reply. (and sorry for my English)
code:
#include <Wire.h>
#include <SPI.h><br>#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
//heater
int heater_out = 2;
float target = 220;
int thermistorPin = A0;
int Vo; // Holds the ADC Value
float R2, tKelvin, Tc;
const float Beta = 3950;
const float roomTemp = 298.15; // room temperature in Kelvin
const float Ro = 10000.0; // Resistance of the thermistor at roomTemp
const float R1 = 10000.0; // Resistnce of the known resistor
void setup() {
//display
Serial.begin(9600);
pinMode(0, INPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//heater
pinMode(heater_out, OUTPUT);
}
void loop() {
Vo = analogRead(thermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0); // Resistance of the Thermistor
tKelvin = (Beta * roomTemp) / (Beta + (roomTemp * log(R2 / Ro)));
Tc = tKelvin - 273.15;
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println(Tc);
display.println(" C");
display.display();
delay(200);
//heater
if (Tc >= target) {
digitalWrite(heater_out, HIGH);
} else {
//Turn ON heater_out
digitalWrite(heater_out, LOW);
}
}
Are you sure that the thermistor and probe construction is rated for such relatively high temperatures? Please post a link to the thermistor data sheet.
Most people use thermocouples for temperatures well over 100 degrees C.
If the thermistor is 100K nominal, what value is the other resistor in the voltage divider, and why does the code claim 10K?
On the e-shop where I bought it, unfortunately it is not written anywhere, only on google (what I was searching, its max temperature should be 300C), but the e-shop focuses on 3D printers, so it should be able to measure such high temperatures ( neither a datasheet, so at least I attach a similar one: datasheet (temperature)).
this is what my thermistor looks like:
Without a data sheet, and a trusted supplier, it is a mistake to assume that the thermistor and probe assembly is rated for those temperatures.
The thermistor resistance can be measured at various temperatures, and used to calibrate the beta value together with this calculator: SRS Thermistor Calculator
Look at the picture. Is that rubber mounting or heat shrink tubing. It is something that has been shrunk, likely by heat. Doesn't look like 300C material.
This will set digital pin 0 to input, not analog pin A0. Also, there is no need to set the analog pin to input mode when using for analog input.
Since you are switching the heater off at 220, I would suspect a glitch in the power is possibly resetting the arduino. Depending on what you are heating and the power of the heater, overshooting to 260C is a definite possibility, so that reading may be correct.
If the probe is intended for measuring the extruder temperature of a 3D printer then the sensing end should be easily capable of withstanding the temperatures.
If the power supply can't supply enough current for the project, the voltage will drop when it is overloaded. The solution is to use a power supply that can provide the required current.
I was speculating that the processor was resetting when you turned the heating element OFF, since you said the temperature reading gets stuck around 215C then jumps to 260C a few seconds later. If the OLED does not get an actual reset signal, it will retain the previous image while the processor is resetting, which takes a few seconds because of the delay caused by the bootloader.
This is just a wild guess and I haven't studied the formula but you might be in a range where a very small-normal change/variation in the raw reading makes a huge change in the logarithmic calculation...
ADC readings are quantized so they are never "perfectly smooth" and under some conditions you simply don't have enough resolution,
The output of a volage divider is also not linear with changes in resistance (which is why you need a log calculation). And the output gets "strange" when the thermistor changes and the two resistors are no longer similar.
You can also hit the analog limits of the ADC but that won't cause noise/instability in the readings.
P.S.
Since the thermistor is "calibrated" at room temperature you can probably get better results with a different series resistor, adjusting the formula accordingly.
...I don't know how to change the formula but it shouldn't be too difficult.