Heating Foil temperature regulation project

Hi,
I have this project where I need to keep a small heating pad (10x10cm) at 37° Celsius.

I have set up a DS18B20 to check ambient temperature and an NTC temperature sensor to check the heating pad temperature.

Chatgpt tried helping me but I havent been successful with the temperature regulation, it turns on and increases temperature steadily but never regulates or goes down. My idea is to control the heating pad with a mosfet P55NF06L, turning the heat off once it reaches 37.5 and turn it on at 36.
I have 2 power sources, a barrel jack in my breadboard providing 12v to heating pad and 5v from arduino for temp sensors.

I'd appreciate any help, I'm completely lost.

Which one? I assume you mean an NTC thermistor.

In general you connect the thermistor in a potential divider, and read the analog value. There are several ways to convert to temperature: use a lookup table, use the beta formula, or for a more accurate result use the Steinhart-Hart formula. You may also want to compensate for self-heating. Whatever method, it is a good to idea to calibrate the result against known temperature points.

Probably to start I would use the beta formula. You may find a simple off-on approach does not provide good regulation, typically you will get swings around the set up. A more precise approach would use PWM control and a PID controller.

Post your code here (inside "<CODE/>" tags please) and add a schematic diagram for helping us understand what's going on (even a photo of a pen and paper schematic would be helpful).

Use a logic level N channel MOSFET. Ordinary MOSFET will not work.

Which arduino are you using?
Forget the NTC and use a digital temperature sensor.

Hi! Thank you for your help. Yes, I'm using an NTC thermistor. I cant get the mosfet to turn off the heating pad, no matter what I try.
Here is the circuit:

And this is the code I have right now:

// Include necessary libraries
#include <OneWire.h>
#include <DallasTemperature.h>

// Pin definitions
#define NTC_PIN A0          // Analog pin for NTC thermistor
#define HEATER_PIN 9        // MOSFET control pin (PWM)
#define ONE_WIRE_BUS 2      // DS18B20 data pin

// Temperature control settings
#define TEMP_SETPOINT 37.0  // Target temperature (°C)
#define HYSTERESIS 0.25      // Prevent rapid switching

// NTC Thermistor properties
#define SERIES_RESISTOR 10000.0 // 10kΩ pull-down resistor
#define NOMINAL_RESISTANCE 10000.0 // NTC resistance at 25°C
#define NOMINAL_TEMPERATURE 25.0 // Reference temperature (°C)
#define BETA_COEFFICIENT 3950.0 // Beta coefficient

// Initialize DS18B20 sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature dsSensor(&oneWire);

void setup() {
    Serial.begin(9600);
    pinMode(HEATER_PIN, OUTPUT);
    dsSensor.begin(); // Start DS18B20 sensor
}

// Function to read NTC thermistor temperature
float readNTC() {
    int rawValue = analogRead(NTC_PIN);
    float voltage = rawValue * (5.0 / 1023.0);

    // Adjust resistance calculation
    float resistance = SERIES_RESISTOR * ((5.0 - voltage) / voltage);


    // Steinhart-Hart equation
    float steinhart;
    steinhart = log(resistance / SERIES_RESISTOR) / BETA_COEFFICIENT;
    steinhart += 1.0 / (NOMINAL_TEMPERATURE + 273.15);  // 25°C reference
    steinhart = 1.0 / steinhart - 273.15; // Convert to Celsius

    // Print results **before** returning the value
    Serial.print("Raw ADC: "); Serial.print(rawValue);
    Serial.print(" | Voltage: "); Serial.print(voltage, 3);
    Serial.print("V | Resistance: "); Serial.print(resistance, 1);
    Serial.print("Ω | Temp: "); Serial.print(steinhart, 2);
    Serial.println("°C");

    return steinhart;  // Return the calculated temperature
}

void loop() {
    // Read DS18B20 sensor
    dsSensor.requestTemperatures();
    float ds18b20Temp = dsSensor.getTempCByIndex(0);

    // Read NTC thermistor
    float ntcTemp = readNTC();

    // Display sensor values
    Serial.print("DS18B20 Temp: "); Serial.print(ds18b20Temp);
    Serial.print(" | NTC Temp: "); Serial.print(ntcTemp);
    
    // Use NTC temperature for control
    if (ntcTemp < TEMP_SETPOINT - HYSTERESIS) {
        Serial.println(" | Heater ON");
        digitalWrite(HEATER_PIN, HIGH);
    } 
    else if (ntcTemp > TEMP_SETPOINT + HYSTERESIS) {
        Serial.println(" | Heater OFF");
        digitalWrite(HEATER_PIN, LOW);
    }
    
    delay(1000); // Update every second
}

What does the serial output show? Can you post a relevant snip in code tags. Relevant would be the condition that should turn the heating pad off, because you say it never turns off.
[Edit. Which mosfet are you really using? ...]

It appears you may have the MOSFET connected wrongly. Source should be connected to ground.

Note if you have damaged the MOSFET, it might be always on.

Your schematic is wrong: it shows the DS18B20 data pin connected to 5v and the Vcc pin connected to pin D2

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.