Peltier with PWM: PID library problem

Hi everyone,
i'm using PID library(Author: Brett Beauregard) to control both healing and cooling of peltier.

I would like to realize the function: when the temperatur under the setpoint, peltier works as heater, the PID-output controls pwm so that it slowly reaches the setpoint. And when temperatur is over setpoint, peltier works as cooler.

Then i met the problem: I can only choose one direction for the calculation of the error. Either heater or cooler.

Can I still use this PID library in this case? How can I modify it? Or I'll have to write my own pid program?

You can also change the direction by changing the sign of the error term, which you can do at any time. However, when you do change the sign, accumulated terms like the integrated error must be reset to zero.

I can't find the reference right now, but my understanding is that direct PWM control is not recommended for Peltier control. It reduces efficiency and cooling capacity because of increased IR losses. The PWM signal needs to be filtered into a low-ripple DC level.

1 Like

PWM control is indeed less energy efficient than filtered DC, but it works fine.

Well, "less energy efficient" means that the lost energy is going to heat up the Peltier itself. That results in reduced cooling (heat transfer) capacity. Whether or not that's "fine" depends on if it still works for your application.

Correct. Keep in mind that PWM has been used to control Peltier heat transfer for decades (since the 1970s), despite the reduced efficiency. For a hobbyist, if it does the job, it is indeed fine, and a nonissue for the Arduino forum.

It is only rather recently that some manufacturers have decided not to produce and sell PWM controllers, one reason being that the smoothed DC controllers are quite a bit more expensive, and more profitable.

How are you switching the peltier polarity?

Thank you for your reply! So it won't work good with only changing the direction like this?

  if(Setpoint > Input ){

    analogWrite(peltiercooling,0);
    analogWrite(peltierhealing,Output);
    SetControllerDirection(DIRECT);
  }
  else if(Setpoint < Input){
    
    analogWrite(peltiercooling,Output);
    analogWrite(peltierhealing,0);
    SetControllerDirection(REVERSE);
  }

Sorry I didn't make myself clear, the peltier has two wires connected to it, the current input from the left wire is for heating mode and vice versa for cooling mode.

I'm also aware that the Peltier switches frequently between cooling and heating modes when the set temperature is reached, which can shorten the life of the peltier.
So I'm trying to figure out how to fix it. My current idea is to adjust the conditions for switching the peltier mode, e.g. to switch to cooling mode only when the temperature reaches the set temperature +0.5°.
But this method also leads to less precise control results. Do any experts have a greater idea?

I've have used these in the past

They also have other models

Based on my Peltier experience, please tell us more about the physical part of your project. Since you want to switch between heating and cooling do you have identical heat sinks and fans on each side of the Peltier? How much time do you allow for Peltier internal heat to be removed before switching from heat to cool? If not enough time(minutes) the Peltier will overheat and be destroyed.

I installed heat sink on the cooling side.I think I don't need particularly high temperatures (my peltier can withstand up to 80°C), and the current is low (3A, whereas the peltier can withstand up to 6.5A) so it's not easily damaged.

You did buy more than one, didn't you?

Of course...But my question is more relevant to the programm..

Sorry, this makes no sense. Nor does your code. Why are there separate analogWrite() calls for heating and cooling?

If you are switching the direction of heat transfer, either side can be "the cooling side". Please post a photo of your setup, and a wiring diagram.

How do you lower the current? By reducing the voltage! When you go below the voltage necessary for the internal diodes to conduct, there is no heat transfer, only heat build up in the diodes.

Sorry I can't provide a picture right now, i just call the side near the tank the heated side. When this side near the tank is used as the cooling side, the heat dissipation on the other side can work well.
And the peltier has two wires, one red and one black, I connected the red one to pin 1 of the H-bridge BTS7960 and the black one to pin 2 so that i can control peltier to change its mode.

Just be extra sure both sides can dissipate the same amount of heat in the time you are allotting.

Normally, heating & cooling systems simply switch on & off or between heat/off/cool. The temperature can't change instantly. This is assuming you have a temperature sensor in the feedback loop.

Some simple setups without a temperature sensor just have high/medium/low/off and you get a temperature difference from the ambient (the heater will be hotter on a hot day, etc.). My car doesn't have a thermostat so it has manually-variable controls like that.

With PWM (or similar) the delay can cause instability and/or it can take longer to reach the target.

Your home heating/cooling system, your oven, refrigerator, etc.

If you want to ramp-up or ramp-down, you simply ramp the target temperature and let it switch on & off as necessary.

And usually there is some hysteresis (or "swing") or time-delay, etc., so it doesn't toggle on & off multiple times in a second, and/or so relays don't "chatter". The LAST thing you want is to be rapidly & continuously switching between heating & cooling when you're at (or around) the target temperature.