PID with a constraint, or two inputs

I don't exactly know how to word this for a subject,

I have a lifepo4 battery I'm trying to keep warm enough to safely charge (via solar) this winter. It lives in a box that has an elevated aluminum (1/4" thick) floor and the battery sits atop that, separated by a thin silicone liner. The underside of the false floor features a 12v silicone heater stuck to the aluminum, which distributes the heat nicely.

I'm reading the temperature with the thermistor built in to the heat pad (these are for 3d printing) and I can hold whatever temp I want with PID, so that's great. But the floor temperature isn't really what I'm trying to control - more so the average of the two probes (on the battery monitoring system) which are several inches above.

Apologies for being long winded, but how would one go about targeting the average of the probe temperatures, while not making the floor a million degrees? I want the probe average to be like 47F, and the floor to be as hot as it needs to be to maintain 47F, without exceeding say 105*F. I could do some if-checkery but I feel like it'll result in the system just bouncing between writing off and on, negating the whole PID thing

Thanks for any direction

The smoothest solution were a state regulator, but it's very hard to find the right model and parameters.

Otherwise temperature regulators are bang-bang controllers, turning the heater fully on or off when temperature limits are reached. You can check both temperatures and switch heating whenever required.

It's a heater, it's by nature slow.

First of all: are you sure you heater gives off enough heat at your temperature limit of 105°F to keep the inside of your box at 47°F at the lowest outside temperature you expect to see? If not, you need a bigger heat pad or different way of heating.

It's quite common for heaters to be switched on and off seconds of even minutes at a time, with the actual time being done by PID type controls. But maybe simple on/off switching based on some if statements is good enough for your application, it does make it simpler. Switch on the heater when the average of the two drops below say 43°F, switch it off when it reaches 47°F. There'll be some overshoot before it drops down again. Do some testing to optimise this; I do assume it's powered by the battery itself so you will want to be frugal with energy.

It is indeed run by the battery, and it's a large heater - 120 watts. It can definitely keep the space warm, the plate can go from 60F to 120F in like a minute with the PID value capped to what equals about 90 watts. So warm in fact that it could be problematic for the battery cells on top of it, hence the plea for wisdom. These are large 205ah 3.2v cells by the way that fit together to form one giant block, no spacing like you'd find with cylindrical cells.

I very likely worded something incorrect here, but the objective is to heat an environment to suitable temperature from a fixed heating source that itself cannot get too hot in the process. Feels like trying to heat a bedroom with baseboard heat while not catching your bedding on fire.

I got that part :slight_smile:

One thing I would do is create an air gap between the heater and the batteries - as safety measure.

After that indeed a very simple on/off control. You’re not hatching eggs or so, making a perfectly stable temperature unnecessary.

So loop() may look a bit like this:

void loop() {
  float roomTemp = (readTempSensor1() + readTempSensor2()) / 2; // average temperature of the two.
  float padTemp = readPadSensor();
  if (padTemp < PAD_LIMIT) { // Pad is not too hot now.
    if (roomTemp < MIN_ROOM_TEMP) { // It's getting too cold.
      switchHeaterOn();
    }
    if (roomTemp > MAX_ROOM_TEMP) { // It's warm enough now.
      switchHeaterOff();
    }
  }
  else { // Pad is getting too hot - switch it off.
    switchHeaterOff();
  }
}

Good grief, thank you. Not as fascinating as PID (was fascinating having plate at 70 as long as i wanted no matter the weather) but that didn’t work for cell temps. Used your snippet more or less. Run plate at 100*f max and maintain 65 (will be dropped to 45 for temp maintaining) but it works fabulous. Still using MOSFET and just pwm writing a value of 60 (about 30 watts) or zero with logic level mosfet in to a 3d printer mosfet with large heatsink.

Thanks! Coulda saved a lot of time if I had just accepted the simple approach

Glad it works :slight_smile: Good luck surviving the upcoming winter. That's where the real test is.