Digital Thermostat Problems

Hi All, and thanks for looking.

I replaced two mechanical thermostats in a dual commercial cooler with an Uno, two relay boards (one controls each compressor), a i2c 4 line display and two onewire ds18b20 probes.

The problem I am having is that the ds18b20 sensors occasionally are falling out of calibration, and the only way to recalibrate is to manually hit the reset button. This is less than ideal because it is a commercial unit and you have to grab a ladder to get on top of the machine and push the reset button. Also, one went off so bad that it read as 37 degrees F, then after the manual reset it read as -7 degrees F. Everything in that section of the cooler was frozen as of this morning.The other cooler read as 38 degrees F and after the reset it showed as 43 degrees F.

I think I need to find a way to reset everything maybe once every 24 hours? Or maybe something in my code is sloppy? Big time noob but willing to learn if anyone has any advice. Here's my code:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h> 
int relPin1 = 7;
int relPin2 = 8;
int relPin1In = 7;
int relPin2In = 8;
int relPin1Val;
int relPin2Val;

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal_I2C lcd(0x27, 20, 4); 
DallasTemperature sensors(&oneWire);
 
void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
  lcd.init();
  lcd.backlight();
  Serial.println("Dallas Temperature IC Control");
  pinMode(relPin1, OUTPUT);
  pinMode(relPin2, OUTPUT); 
}
void loop(void)
{
  
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); 
  float x=sensors.getTempFByIndex(0);
  float y=sensors.getTempFByIndex(1);
  Serial.println("DONE");

  Serial.print("Temperature 1: ");
  Serial.print(x); 
  Serial.print("Temperature 2: ");
  Serial.print(y); 
  lcd.setCursor(0,0);
  lcd.print("Top Cooler: "); 
  lcd.print(x);
  lcd.print("F");
  lcd.setCursor(0,2);
  lcd.print("Bottom: ");
  lcd.print(y); 
  lcd.print("F");        

if(x >= 38)
    {
      relPin1Val = HIGH;
      lcd.setCursor(0, 1);
      lcd.print("Compressor: ON ");
     }
    else if(x <= 37)
    {
      relPin1Val = LOW;
      lcd.setCursor(0, 1);
      lcd.print("Compressor: OFF");
      } 

    if(y >= 38)
    {
      relPin2Val = HIGH;
      lcd.setCursor(0, 3);
      lcd.print("Compressor: ON ");    
    }
    else if(y <= 37)
    {
      relPin2Val = LOW;
      lcd.setCursor(0, 3);
      lcd.print("Compressor: OFF");
     } 
{
  digitalWrite(relPin1, relPin1Val);
  digitalWrite(relPin2, relPin2Val);
    
}}

Is wiring not interesting, lenght of cables etc?

Not sure what you mean when you say "is wire not interesting".

The ds probes I ordered are 3 meters long. One goes directly down into the top cooler and the other snakes down the back of the cooler and into the bottom section, appx 2 meters.

Wiring, not wire. Show the wiring diagram of the entire unit, controller, wires, sensors, power supply.
The trouble You describe are not normal.

Im searching all over trying to find the best way to draw it out. Any recommendations on that?

If it's not in digital format You can use pen and paper to make a drawing. That usually works well.

cjizzle:
Im searching all over trying to find the best way to draw it out. Any recommendations on that?

have a look at TinyCAD

Saw the tinycad comment after using paint to draw a hugely crude representation. Apologies, but it represents exactly how my wiring went.

Jpg attached.

EDIT - powered by a 9v 1A wall wart

Thanks. I can't se how the UNO is powered and that can be very interesting. Both relay boards and both sensors are powered from the 5 volt pin of the UNO. That might be okey but there are severe exceptions.

As stated in the edit in my above post, I am using a 9v1A wall wart plugged directly into the UNO.

This project is only 1 week old and just now noticed the huge temp differences. Nothing was that far off until this morning (as far as we know anyways). Something either glitched, or it was such a gradual change that it wasn't noticed. Hence my original question...

Is it possible to code a reset every 24 hours? The first few days everything worked perfectly.

There we surely have the problem, needing to reset the controller. You can't feed both the UNO, the relay boards and the sensors that way! That 5 volt converter on the UNO board is very poor, just has the capacity of feeding the UNO and maybe a very light load on the 5 volt pin. I'm pretty sure that it overheats and cuts down. Get Yourself a 5 volt supply and connect it to the 5 volt pin.

Flyback or snubbing diodes on the relays would be a good idea to control voltage spike

saildude:
Flyback or snubbing diodes on the relays would be a good idea to control voltage spike

Relay boards already have that.

According to the datasheet, the UNO can supply up to 0.8A on the 5v pin. Each ds18b20 draws appx 1mA and each relay module 70mA. Combined that is less than 150mA, well below what the UNO provides. What am I missing here?

Hi,
Ops circuit,


Why have you got the "5K" resistor between DS18B20 gnd and signal?
It should be between signal and 5V.

Can you post a picture of your project please?
What relay assembly are you using?
What are your relays switching? If mains power have you got the mains wiring well away from the DS18B20 and other low voltage wiring?

Tom... :slight_smile:

cjizzle:
According to the datasheet, the UNO can supply up to 0.8A on the 5v pin. Each ds18b20 draws appx 1mA and each relay module 70mA. Combined that is less than 150mA, well below what the UNO provides. What am I missing here?

800 mA from the 5 volt? You are mistaken some way. Recheck the terms for that. Remember that the UNO itself draws current.

The voltage regulator for the 5V on the UNO is the NCP1117 which can provide in excess of 1A.
EDIT: The datasheet for that chip shows 800mA @ 5v.

The UNO itself draws appx 30mA with no load right? I'm not drawing the power from the digital pins, I know the limit is 40mA each with a max of 200mA across all.

I have also seen numerous projects with the UNO using even more than what I have connected in this project. And when I initially verified it worked when it was on the breadboard I was powering with the computer's 500mA USB. Now its being powered by a 9v1A supply.

So add it all up and even with USB power Im still way under the limit. That is, if I am reading all these datasheets and other posts on this forum correctly. Power was certainly a thought initially but every bit of research I have done, hours upon hours of searching and reading, pulling 142mA from the 5v pin on the UNO should be a non-issue.

@Tom Sorry I didnt see your post on the last page til just now!!

Pics attached, the orange hued pic is when I prototyped it using usb power, the other two are installed in the cooling unit.

The 5k resistor to ground is what I saw in a different users schematic that seemingly worked (very different project but the temp taking was what I was after). After I had already soldered it I saw others said it needed to go to 5v, then I saw multiples that said it didnt matter which side it was on as long as it was there...maybe thats the issue?

The relays are these: https://www.amazon.com/gp/product/B07L6J6FHH/ref=ppx_od_dt_b_asin_title_s01?ie=UTF8&psc=1

In the pic of the installed unit, I 3d printed a base for all 4 pieces. The yellow/blue/green 3 connector wire coming out of the pcb is connected to the bottom cooler sensor and the orange/red/brown is going to the top cooler sensor.

Yes the relays are connected to mains that run each of the compressors you see in the other pic. The fans for the compressors pull air from the UNO side so no heat is hitting the UNO.

EDIT AGAIN: OMG...I messed up the first PCB I made so decided to make another, clean it up and add those black headers for a more stable board. Looking at the pics I don't see my pull-up resistor anywhere. Did I seriously forget to put it on there? The unit is an hour drive away. Oh man...am I that dumb... It worked without it though...baffling. I read somewhere you no longer need it since you can call resistance in the UNO in code, but I didn't code it that way. Ugh... smh in shame...

(9V - 5V) x 0.142A = heat dissipated in the regulator = 568mW. You may notice it getting warm to hot.

Why not use use a 5V1A supply and keep the regulator out if it?

Excellent idea. Can you recommend any specific supply?

Would this work?