# Help with PID tuning!

**URL:** https://discourse.nodered.org/t/help-with-pid-tuning/1400
**Category:** General
**Created:** [6 July 2018 18:15 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400 "2018-07-06T18:15:10Z")
**Posts on this page:** 10
**Page:** 3

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 July 2018 12:36 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/41 "2018-07-17T12:36:31Z")

</div>

> [@krambriw](#):
>
> To avoid lagging behind, maybe the smoothing should not be a standard averaging (simple moving average) but one with weighting where later readings are given more weight (an exponential moving average it is called)

If you look back at the function I posted, which I said was a low pass RC filter you will see that it is the same as an Exponential Moving Average. So @Paul-Reed is already using that. I would never use anything else for smoothing.

Good luck with the suggestion of a two setpoint on/off controller. Proverbial hats would get eaten if that turned out to be better than PID.

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [17 July 2018 12:49 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/42 "2018-07-17T12:49:34Z")

</div>

🕶 🌞Yeah, maybe the hot weather has too much influence, not only on moisture levels

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [17 July 2018 12:55 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/43 "2018-07-17T12:55:26Z")

</div>

> [@Colin](#):
>
> I had assumed that the chart was showing the full range of the sensor. Is the full range 0 to 100 and you are seeing noise of +-1 in which case that is not bad?

Ah, maybe I looked at he latest chart where the value was already smoothed

Are those sensors expected to be so accurate? Or is the soil moisture really canhaging that rapidly +/- 1%?

Is this really a lot? I mean 1% in relation 62% (1.6%)

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [17 July 2018 12:58 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/44 "2018-07-17T12:58:16Z")

</div>

> [@Colin](#):
>
> @Paul-Reed I had assumed that the chart was showing the full range of the sensor. Is the full range 0 to 100 and you are seeing noise of +-1 in which case that is not bad?

The wemos D1 outputs the range 0 - 1024 from the ADC.  
I then use a range node to map the range 425 - 700 to 100 - 0 (because the ADC interprets a lower figure as being higher humidity, whereas I wanted the reverse, ie the higher the figure - the more humid).  
I chose 425 because that equates to saturated soil (cannot hold any more water)  
...and 700 because that is soil which is as dry as possible, so the operating range is between 425 - 700 out of a possible 0 - 1024.

> [@Colin](#):
>
> Proverbial hats would get eaten if that turned out to be better than PID.

I did initially use the ramp-thermostat node, but the results were nothing near as accurate as using the PID.

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [17 July 2018 13:47 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/45 "2018-07-17T13:47:58Z")

</div>

With the scale fixed (60 - 64), and the temperature chart added, this is the result.  
Holding a ruler against the charts, you can definitely see correlation between the peaks in temperature and the subsequent drop in humidity/PID output.

 ![pid5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e5c4182930435e68a509b4a20a84fe3766a5dbd9.PNG)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 July 2018 15:18 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/46 "2018-07-17T15:18:55Z")

</div>

So the noise is only +-1% of full scale reading which is probably not bad. Knowing what I now know I would suggest you are getting remarkably good control. Do the plants really need it anything like that consistent?

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [17 July 2018 15:45 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/47 "2018-07-17T15:45:07Z")

</div>

I think this looks very good!! And the tomatoes, beautiful, almost tempted to start growing...and Colin, great PID!!!

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [17 July 2018 18:07 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/48 "2018-07-17T18:07:00Z")

</div>

> [@Colin](#):
>
> Do the plants really need it anything like that consistent?

No, I'm well pleased with the results, and they are well within the targets that I mentioned earlier.

Thanks for the guidance Colin & Walter.

Paul

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [18 July 2018 01:45 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/49 "2018-07-18T01:45:29Z")

</div>

Wow Paul, that puts my plants to shame... just to put a nice bow on this project, and for posterity (and future farmers), what variety are they?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [18 July 2018 09:15 UTC](https://discourse.nodered.org/t/help-with-pid-tuning/1400/50 "2018-07-18T09:15:57Z")

</div>

Steve, they are Suttons 'f1 Sweet Million'.  
The grandkids eat them like sweets!!

[Previous page](https://discourse.nodered.org/t/help-with-pid-tuning/1400.md?page=2)
