PID Controller for Cooling - Looking for Help

Hi. I am trying to control a fan depending on the temperature I read from DS18B20. This is the PID node that I am using:

I am new to Node-Red, and I don't know about PID controllers. I read the example provided by the author of this node, but I couldn't get it working. It says "Integral Locked". The author also tells what that means, but I don't know how to fix it.

Also, author mentions about something like "for cooling, change the range from 1:0 to 0:1". I don't understand what to do about this part.

Can someone please guide me? Using Discord is better than forum questions for me, if that is okay for you too. Also, if you think that I gave too little explanation, please ask me questions about it. I am new, I don't really know what matters, or not.

Hi @oncdastan, welcome to the forum.

The PID node outputs a value in the range 0 to 1, 0 means output fully off, 1 means fully on. For cooling you need to invert that, do that with a Range node set to scale input range 0 to 1 to the output range 1 to 0.

For tuning the loop did you see the blog post linked from the node's help?
http://blog.clanlaw.org.uk/pid-loop-tuning.html

1 Like

I created the node in the way you (and the guide) told me to. Should I put the range node before PID node, or after?

I checked that post, tried similar values. I got "Integral Locked".

Can I talk to you on Discord, if that is okay for you?

@oncdastan If the PID node outputs a range of 0 -> 1 and you want it to be inverted to a range of 1 -> 0, then you would put the Range node after the PID node.

Just to avoid confusion, you mean Slack, not Discord.

Integral locked is normal when the process is a long way from the setpoint, it is purely for information. Have you gone through the tuning algorithm to determine appropriate settings for the node? It is very worth while starting by importing the simulation flow in the guide and going through the tuning guide with that first. That will show you what you can expect to see. Since you are working with cooling the graphs will be upside down on the real system but hopefully you can cope with that.
What is the process you are controlling?

Not really. I meant Discord. Slack is fine too, but I prefer Discord.

I put the range node in the way you said it. Looks like it is working, just needs some tuning.

I have another question. I am using GPIO2 as digital output. Should I change it to PWM output, or can PID make it act like PWM by turning it on and off? I know it does that, but are these two things kinda the same for my usage (controlling a fan for cooling)?

How are you converting the linear 0 to 1 output into a digital On/Off signal to drive the fan?
You can use node-red-contrib-timeprop to obtain a time proportioned On/Off output. If you do that you don't need the Range node as you can invert the signal in the timeprop node. That node will give you better control of the output than a PWM output.

I don't use Slack or Discord.

Hi. I had a busy weekend, now I'm back to working on the project.

I don't think I am converting anything. Not entirely sure what I am doing at the moment. I saw values between 0 and 1 on the output node, but the LED was off when it was below 1 (I am trying to see the effect with an LED. Also, maybe I did it, but LED is not a good tool to observe the results.). Not sure what I can do with those. I was thinking that maybe it could stay 0, when the condition has not met, and 1 when it has met. It could switch back and forth, 0 and 1, to keep it stable. If this is not a good approach, and I need to convert those values between 0 and 1, how can I do this?

I apologize, if these questions are too basic. I'm new to Node-Red, and PID controllers as I mentioned before. Never done anything similar to these.

Edit: I don't know how to use other people's flows. I'll look into that, and try to adjust it with the graphs in it. But, I still need an answer for the question above in this reply.

The PID node generates a value between 0 and 1. When it is 0 then that means no power should go to the process and when it is 1 that means full power. When it is 0.25 that means that 25% power is required. In your case I presume that it is a conventional refrigeration device of some sort so you have no way of telling your cooling device to work at 25% power. That is what node-red-contrib-timeprop is for. You can feed the output of the PID into it and it will generate an on/off signal such that when 25% power is requested it will switch it on for (say) 2.5 minutes then off for 7.5 minutes. The total cycle time (10 mins in that example) is configurable to suit the process. Also there is a setting there that allows you to say you don't want the freezer to switch on (or off) for less than (for example) 20 seconds and it will sort that out too. Also it has an Invert option which you can set so that it will cope with heating or cooling (and also which way you have to drive the output to switch the output on).

Having said all that, if you think that you just need a simple thermostat effect, where the freezer is on when it gets above an temperature and off when it goes below, then have a look at node-red-contrib-ramp-thermostat which will do that for you (you can just not use the ramp bit if you don't need it). That gives you a result where the temperature cycles up and down around the desired temperature as the cooler goes on and off, but it may well be perfectly good enough. If you need better control than that however then PID is the way to go. It might be a good idea for you to get your system going with the thermostat node first, which will let you sort out all the hardware (and learn about node-red) and see what the result is. By that time you will have a better understanding of node red and the hardware and can then improve the control with the PID node.
Whatever you do, make sure you have a chart showing the temperature, the setpoint (if it changes) and also the output to the device. That will let you see how it is all performing.

Thank you for the clear explanation.

My purpose is to constantly keep the object under setpoint temperature. PID controller is required by default in this project. Maybe a thermostat way could do it too, but I have to do it with PID controller.

System has some other features that I handled previously. Mainly, PID part is new to me.

I am using output pin as a digital output. Should I change it to PWM output?

What sort of cooler device is it? A motor driven compressor type or what?
Have you looked at node-red-contrib-timeprop? That is intended for exactly this sort to application, unless there is something unusual about your system.

I'm using peltiers with fans to cool down a liquid. Imagine a container filled with that liquid, and the top layer of peltiers are inside the container, touching the liquid. Using DS18B20, I'll be checking the temperature in that container, and 3 different spots where the liquid will be sent. According to those temperatures, I'll change the speed of the (motor driven) fans.

OK, so you don't want on/off control, you want a linear signal going to your fan speed controller. What signal does the speed controller need?

It is L298P. It needs PWM signal.

Well in that case, presumably you do need to set the output to PWM. You can check that is working by feeding it from a slider on the dashboard to make sure it works ok. Then you should be able to feed the PID output through the Range node mentioned earlier (so that when the PID output is zero the fan is on and when it is 1 the fan is off) and you should be good to go. Again, to test initially use a slider into the input of the range node and make sure it is doing what you expect.

Thanks a lot.

I will do that and try to tune it.

I am testing it with a water pump (I can hear the noise and understand if it is working correctly, or not). When I heat the sensor up above the setpoint, the pump vibrates just a little bit like a heartbeat. So weak that it doesn't make any noise. I don't know how to solve this problem.

Edit: I also changed the output range from 1 to 0, to 100 to 0. After doing this, I typed "msg.payload" into the Frequency of PWM output. Then, I was able to feel that weak heartbeat-like vibration.

Show me the chart showing the temperature and the pid output. You can't understand what is going on without that. Also tell me what settings you have put in the pid node.
Have you tested just with a slider (or similar) going direct to the output first though, to make sure that the drive is working?

It is working. I tried it before with an Arduino.

I am not using a chart for temperature. Gauge and values of it are as expected.

PID output (after the range node, when I changed it to 100 to 0) is 100 when it is above the setpoint. Then, it slowly decreases to 0 after it goes below the setpoint.

Setpoint: 30
Proportional band: 0.5
Integral time: 180
Derivative time: 3
Inıtial integral: 0.5
Max sample interval: 600
Derivative smoothing factor: 3
Enable state: 1
Output power when disabled: 0

What is required later is irrelevant, for tuning you need a chart showing temperature and pid output. It is trivial to add a chart so what is the problem?
Then you can follow the initial tuning technique in the blog to get starting values for the tuning constants.