NOTICE: This forum has been archived (i.e. registration and posting is disabled).

Please go to the new forum at https://forum.kylegabriel.com

Would you please take a look at my PID setting as that may be the problem. I am trying to use set point sine wave tracking for humidity + or - 10% around a core value of 89%

PID settings:

Input: Humidity InputDirection: BothPeriod: 120Setpoint: 95Band: 1Kp: 100Ki: 0.5Kd: 0.5Integrator Min: -100Integrator Max: 100

Output Raise: Humidifier OutputMin On Duration: 300Max On Duration: 0Min Off Duration: 0

Output Lower: Dehumidifier OutputMin On Duration: 240Max On Duration: 0Min Off Duration: 0

Setpoint Tracking method: Sine Method

Let me first explain how the output value is calculated, then how the settings can be improved.

This equation is how the PID calculates the output value:

P + I + D = output value

Where,

P = Kp * e

I = Ki * ∫(e*dt)

D = Kd * d(e)/dt

e = error

It's usually good to turn the I and D gains off for initial testing to get an idea of how the output will be generated based solely on P, which would be the product of the Kp gain and the error (e).

P = output value

Kp * e = output value

If the desired humidity is 95 and the actual humidity is 55, the error, or difference, will be 40. If the I and D gains are turned off (set to 0), and Kp = 100, this is our output:

(100 * 40) + (0) + (0) = 4000

This would turn the output on for 4000 seconds.

Now let's analyze this tuning using a Period of 120 seconds. The Period is how long the duration between the PID controller acquiring a new measurement (to determine the error) and calculating the proper output value. Let's go through a few iterations to demonstrate how the PID controller will respond with these settings.

Period 1 (second 000): Humidity: 55, Error: 40, Output: 40 * 100 = 4000 seconds

Period 2 (second 120): Humidity: 60, Error: 35, Output: 35 * 100 = 3500 seconds

Period 3 (second 240): Humidity: 65, Error: 30, Output: 30 * 100 = 3000 seconds

Period 4 (second 360): Humidity: 70, Error: 25, Output: 25 * 100 = 2500 seconds

Period 5 (second 480): Humidity: 80, Error: 15, Output: 15 * 100 = 1500 seconds

Period 6 (second 600): Humidity: 90, Error: 5, Output: 5 * 100 = 500 seconds

Period 7 (second 720): Humidity: 95, Error: 0, Output: 0 * 100 = 0 seconds

Period 1 turned the output on for 4000 seconds. 120 seconds later, at Period 2, the output is instructed to turn on for 3500 seconds. Sine the output is still on from Period 1, it merely keeps the output on and updates the on time to 3500 seconds. This continues until the humidity reaches 95%, when the error is 0 and the output is instructed to turn on for 0 seconds (off).

The PID is essentially just on for the majority of the time. While this is common for some PIDs that are attempting to affect a large, slowly changing environmental condition, the durations the PID is outputting are incredibly larger than the period, which may make the system unstable or erratic when the measured value is near the setpoint. My suggestion is to reduce the Kp gain significantly in order to bring the output within a smaller range, closer to the 120 second Period. This will dampen erratic output changes by reducing the amount the output can change each period.

There are a few details I would need to now before being able to suggest a good initial tuning to start from. Most important is what type of humidification system is being used, however each system is different and there are other factors that should. Be considered. The best approach is to test your system. If there is a limitation to the output device (humidifier), we need to take that into consideration. For instance, I see the Min On Duration is set to 300. I'm not sure why, but perhaps the humidification system cannot tolerate switching at a period faster than this. My following tuning will be based on a humidification system that doesn't have this limitation. If it is the case that there is a limitation. , we can retune considering that limitation.

This is how I would generally create an initial tuning:

We want our maximum calculated output to be at least as high as our Period (120 seconds) but not much higher (less than twice as much), when our humidity is very low, we can calculate that with a low humidity (20%), our equation would be (Kp * error) = output, and substituting our known values, we get: P = Kp * e = 120; Kp * 75 = 120; Kp = 120/75 = 1.6. I would first run the PID controller with only Kp set to this value (Ki = 0 and Kd = 0) and see how the system responds.

We will probably want to reduce persistent error, so we will introduce the I value. The Ki gain typically is a small value, and incrementing it during tuning should be performed very conservatively. With a Integrator Max of 100, we can consider how much the I value can possibly be influencing the output value when there is no error (measured value = setpoint) with I = Ki * 100. Therefore, if Ki is 0.6, the maximum I value can be 60 when the measured value is near the setpoint. Therefore, if Ki is 0.6, the maximum I value can be is 60, half the period (a moderate initial Ki tuning). Let's now calculate the I value using this Ki gain, when the error is large. With a Ki = 0.6, if the error is 40, the first period I = 0.6 * 40 = 24 seconds output. This is a rather large amount the I value can potentially contribute to the final output, so reducing it some for the initial tuning could be beneficial. I would suggest reducing this at least by half. If we bring it down to 1/6th, we start with Ki = 0.1.

Using these values, our new tuning parameters are:

*Input: Humidity Input**Direction: Both**Period: 120**Setpoint: 95**Band: 0**Kp: 1.6**Ki: 0.1**Kd: 0**Integrator Min: -100**Integrator Max: 100*

*Output Raise: Humidifier Output**Min On Duration: 0**Max On Duration: 0**Min Off Duration: 0*

Using these parameters I would let the system run until stabilization occurs or a steady oscillation results. From there, depending how the system responds, further tuning can proceed. Very rarely does the first tuning produce exceptional results. Using the graphs, a lot of information can be determined about how to proceed with the second tuning. I would highly recommend creating a graph with these data series: Input measurement (for the humidity), Output humidification (increasing the humidity), PID Setpoint, and PID Output (duration). You could add PID P-Value and PID I-Value to see how these change as the PID controller progresses through cycles. If you can provide screenshots of how particular tunings affect the system starting from a calm state (low humidity), I can help further tune your PID to be more efficient.

Let me know if this helped and what other questions you may have or information you can provide about your system.

Mycodo Developer

Thanks for the great explanation on PID settings. I will produce a daily chart using your recommended setting as soon at the actual outside humidity returns to normal...now 89%. I’m sure the current relative humidity outside the grow room room is a factor in setting up PID for the first time.

One thing I have noticed while using the BME280 is that the PID cycles about 6% points below the desired set point? I can easily compensate for this by setting my desired set point higher by 6%, but wonder if anyone else has seen this or can offer a fix.

Farmer

The persistent error you describe is likely due to the high Min On Duration you have set (300 seconds). When the error is great (the measured humidity is far from the setpoint), the output duration is so great it easily exceeds this 300 minimum. However, as the humidity approaches the setpoint, the PID output drops below 300, so the output device isn't allowed to turn on. This is the reason I was curious if your humidification device needs a 300 minimum duration to be set. If there is a legitimate limitation of the device with its switching interval, I can work with that to design another set of tuning parameters, but if we can reduce the minimum on duration, then the tuning I described should alleviate a steady state error when the humidity approaches the setpoint, and the PID controller should be able to regulate to the setpoint without having to manually adjust for a persistent negative error (the PID controller will do that automatically).

From my own experience, I typically set Min On Durations when I use mechanical relays, to extend the life of the relays, and also to reduce those annoying clicks I could hear in my house. Solid state relays (SSRs), with their increased life span and silent operation, removed these concerns and allowed me to significantly reduce the Min On Time. With SSRs, I then had to determine if the device itself could handle fast switching (< 10 or < 1 second, for instance). If it's a high pressure water/mist system, I would not recommend allowing a low Min On Duration, due to many pumps not being designed for fast cycle (on/off) rates. However, with ultrasonic transducers that produce mist, I found I could set the Min On Duration to 0 without negative side effects. Finding a low Min On Duration that enables tight regulation around the setpoint while also not stressing your equipment is a balancing act.

If the Min On Duration can't be reduced, the next option is to increase the Period substantially, but this will necessitate calculating higher Kp and Ki gains to account for the higher Period.

Mycodo Developer

Kyle, Thanks again for the great explanation of the PID settings to control humidity in my grow room. I have eliminated the 300 minute “on” duration and my set point tracking has improved. I had set it high to make sure the BME 280 had time to read the new input of moisture from the humidifier, but that’s probably more of a function of interval time. I am trying your suggested PID settings now and am using the dashboard graphs to evaluate the changes being made.

Farmer