Help with Thermostat Control for 12V Fridge

Hi friends; I built a Thermostat for a beer cooler using a Pro-Mini with a thermistor as temperature sensor and mosfet relay to power the Peltier Thermoelectric Module. When I bench test the circuit with the attached code the serial printed out the correct temperature, even when I added an Lower/Upper limit at room temperature and hand heated the thermistor the serial graph showed a good response. However when installed in the cooler programmed to 3C low & 5C high the serial displays 23.8C and the circuit does not shut off after running for 7hrs. The thermistor sensor is at the top of the cooler (inside). I wonder if there is a problem in the sketch??

// SKETCH: FRIDGE_TEMERATURE_MOSFET_CONTROL_CIRCUIT.ino
// This project is to control a 12VDC Refrigerator between 3 and 5 degrees Celcius
// using Thermistor (SEN-054) with Arduino Pro-mini and control for hysteresis
// Best Fridge Temperature Range is 1.7-3.3 degrees Celcius (35-38 Fahrenheit)
// **** May need to add SIMPLE_KALMAN_FILTER.ino to stabilize readings for final sketch?

/* The circuit:
                      Analog pin A2
                           |
     5.0V |-----/\/\/\-----+-----/\/\/\-----| GND
                  ^                ^
           10K thermistor     10K resistor */

const long SERIAL_REFRESH_TIME = 100;  // Fred added for serial display 8AUG21, default = 100
long refresh_time;                     // Fred added for serial display 8AUG21

const int MOSFET = 9;  // Mosfet connected to pin D9 (Mosfet changed to Relay module)
const int LED = 13;    // LED connected to pin 13, NOT USED!
int state = 0;
// The state of pin D9 where 0=LOW (Fridge off) & 1=HIGH (Fridge ON)

const int LIMIT_LOW = 5;   // Low temperature limit before the fridge turns off. default 3C
const int LIMIT_HIGH = 7;  // High temperature limit before the fridge turns on. default 5C

int ThermistorPin = 2;  // Input pin A2
int Vo = 0;  // Variable used to store the value coming from the themistor
float R1 = 10000;  // Resistor size used in the voltage divider circuit
// (R1 should be reasonably matched to the thermstor R)
float logR2, R2, T;  // Variables for the themerature math
// Constants for temperature math
float c1 = 1.125308852122e-03, c2 = 2.34711863267e-04, c3 = 8.5663516e-08;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting....");
  pinMode(MOSFET, OUTPUT);  // Sets digital pin D9 as output
  pinMode(LED, OUTPUT);     // Sets digital pin D13 as output
}

void loop() {
  Vo = analogRead(ThermistorPin);  // Read the value from the thermistor
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  // Note that in Arduino programming, "log" is natural log
  // (verses log10 in common log in base 10)
  T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
  T = T - 273.15;

  if ((T > LIMIT_HIGH) && (state == 0))
  {
    digitalWrite(MOSFET, HIGH);  // Turns the MOSFET on (Fridge ON)
    digitalWrite(LED, HIGH);     // Turns the LED on
    state = 1;                   // Fridge is now running
  }

  if ((T < LIMIT_LOW) && (state == 1))
  {
    digitalWrite(MOSFET, LOW);  // Turns the MOSFET off (Fridge OFF)
    digitalWrite(LED, LOW);     // Turns the LED off
    state = 0;                  // Fridge is now off
  }

  // send to Serial output every 100ms               // Fred added for serial display 8AUG21
  // use the Serial Ploter for a good visualization  // Fred added for serial display 8AUG21
  if (millis() > refresh_time) {                     // Fred added for serial display 8AUG21

    Serial.print("Celcius: ");
    Serial.println(T);

    refresh_time = millis() + SERIAL_REFRESH_TIME;   // Fred added for serial display 8AUG21
  }                                                  // Fred added for serial display 8AUG21

    // delay(100);  // Wait 2 minutes between each serial output send. **** Default 120000 ****
    // This also introduces a delay between each temperature reading just in case of brief spikes.

  }  // End of sketch

So, what is the actual temperature using a separate thermometer?
Paul

5C using a mercury thermometer in a glass of water.

Inside the enclosure?
Paul

Yes inside, along with an Accu-Temp regular metal fridge unit which registers about 40F.

Good check!
Guess I would test the NTC thermister and code for it only for room temp, which was ok, and then again in a real refridg. Was the thermister touching something?
Guess a real circuit diagram of the thermister circuit would be useful.
Paul

Temp changed good at room temp, but I never put circuit in real fridge. Thermistor was & is, just hanging free. The temp circuit is at the top of the code. Just a 10k NTC unit with 10k to ground and junction to A0. Maybe that simple circuit only works at room temp? I wonder if I screwed up the code by adding the Millis?

What is connected to the other end of the NTC?
Paul

VCC 5V out from Pro-Mini. Mini is power by a 7V voltage dropdown module from 13.8vdc. I dumped the Millis which did not fix it.

Just a guess....
My experience with a Peltier cooler is that it does not cool the air, only the can or bottle in contact with it.

This Peltier cooler is made by MobiCool with inside and outside Heat Sinks with fans, so the items are cooled by air. The Peltier unit is in the top so nothing touches the milk/food items.

Your 2 x 10k are too high for the analog input perhaps....????

https://forum.arduino.cc/t/input-impedance-of-a0-a5/64820/2

Hello
Check o.m. calculation for the need of brackets.

bluejets:
I've seen 10k's used with a NTC 10k thermistors before in books, but this is first time used by me. Most circuits use 3.3 volts instead of 5V, but the Pro-Mini does not have a 3.3v VCC output.

paulpaulson:
Hackster.io uses ```
T = (1.0 / (c1 + c2logR2 + c3logR2logR2logR2));
in their code and the only difference is the spacing from mine which should not make much difference. T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2)); See: https://www.hackster.io/Arnov_Sharma_makes/temperature-meter-thermometer-with-ntc-and-oled-display-83faa7
I did notice that they taped the thermistor to a Metal Plate, so I'll try that!

Add a print out of the thermistorPin to troubleshoot → see if that's changing.

  Vo = analogRead(ThermistorPin);  // Read the value from the thermistor
  Serial.print("NTC = ");   // Added
  Serial.println(Vo);       // Added
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);

[/quote]

runaway_pancake
Yes, it changes. The Vo reading goes lower when I touch it. I will be mounting the thermistor to a metal plate and check again. Thanks for the hint.

Added the thermistor to a 3" X 9" thin aluminum metal plate. The temperature has been dropping steadily, and is now down to 10.9C. So far it looks like the Thermistor needed to be mounted to cold conducting material. We'll see...

NTC elements are none linear. In a commercial product we used them and a 3 step approximation that promised a maximum error of 3 degrees C ranging up to some 120 C.
If the target temperature doesn't need to be selected just calibrate the controller readings for the targets You want. Don't bother about any conversion to degrees. Remember that the ADC has a range of 0 - 1023 and decimals are not meaningful.

1 Like

Railroader:
I did suppose they were non-linear, but because I'm only working between 3 and 5 degrees Celsius I thought the linearity would not cause a problem. The accuracy of the sketch temps is not important, as long as I can adjust them to achieve the actual mercury thermometer readings. I never thought of just using the Vo to switch the relay on/off. The Vo for 10.9C was 352.