• Please visit and share your knowledge at our sister communities:
  • If you have not, please join our official Australia and New Zealand Homebrewers Facebook Group!

    Australia and New Zealand Homebrewers Facebook Group

Arduino Development Thread

Australia & New Zealand Homebrewing Forum

Help Support Australia & New Zealand Homebrewing Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Can any of you guys give me any hints on setting PID tuning parameters?

I'm building an arduino based controller, and I'm using the PID library for my HLT and MLT direct fired RIMS. I don't know where to start with the PID parameters, or how to use the PID autotune library - the doc and example for the latter are fairly light on.

I think Matho used Kp = 100, Ki = 20, Kd = 5 in the Braumiser. That may not suit my 3V system, but it's a starting point for the time being.

Cheers,

Jon
Tuning is the hardest part of the whole process in my opinion, and the lack of documentation on the autotune library makes it pretty well useless. Of the multiple iterations I've run it through, I can get a much better tune just by manually following the process in this article: http://www.embedded.com/design/embedded/42...D-without-a-PhD (link to the original pdf in the top of the article, or just read on for the html version)
 
Picked up a couple of I2C relay boards:

Relay board by auvortex, on Flickr

Small one has 8 relays, 10a@250v, I2C connection.


Relay board by auvortex, on Flickr

Big one has 8 relays, 30a @250v. I2C connection also. Likely to need a bloody big heatsink :)

Got them from http://www.ereshop.com/shop/i2cbus-boards-c-143.html ordered last thursday, arrived today. Not the cheapest boards around but should do the job! Documentation is a little thin on the ground, though :( Ti chip, so hoping it's common enough that there is plenty of doco around for it.
 
Picked up a couple of I2C relay boards:

(snipped)

Got them from http://www.ereshop.com/shop/i2cbus-boards-c-143.html ordered last thursday, arrived today. Not the cheapest boards around but should do the job! Documentation is a little thin on the ground, though :( Ti chip, so hoping it's common enough that there is plenty of doco around for it.

FWIW, they both use the PCF8574 I/O Expander chip as outlined on the link above, and documentation is fairly easy to come by. For example: http://garagelab.com/profiles/blogs/tutori...er-with-pcf8574
The work I'll be doing will be in C++ but shouldn't be hard to get it working (and there may already be a library, I haven't looked yet)
Edit: Well that was hard: http://arduino.cc/forum/index.php?topic=109340.0 :)

One of the boards will be used with Arduino, the other with BeagleBone or Raspberry Pi.
 
Tuning is the hardest part of the whole process in my opinion, and the lack of documentation on the autotune library makes it pretty well useless. Of the multiple iterations I've run it through, I can get a much better tune just by manually following the process in this article: http://www.embedded.com/design/embedded/42...D-without-a-PhD (link to the original pdf in the top of the article, or just read on for the html version)

Thanks guys.

Bonj, That's a good article. I'd be grateful if you would elaborate on your tuning process, just so I can make sure I'm on the right track. For example, did you start off with "set all gains to zero", and does that mean Kp, Ki, and Kd are all zero for the Arduino PID implementation, or have I misunderstood that and e.g. Kp != proportional gain?

Also, I think the Arduino PID library defaults to PI rather than PID. There's a command to set it to PID, but I don't see that in anybody's code. Are people happy just using PI? If so, that sounds like it makes the tuning process a little easier.

Cheers,

Jon
 
You won't be needing a heatsink as they are mechanical relays not Solid State Relays (SSR), what's the end application for them?
If it is turning a heating element on and off you might want to check the rated number of switching actions for the relays.
Looks like 100,000 on the smaller ones, can't find one on the larger ones.
 
You won't be needing a heatsink as they are mechanical relays not Solid State Relays (SSR), what's the end application for them?
If it is turning a heating element on and off you might want to check the rated number of switching actions for the relays.
Looks like 100,000 on the smaller ones, can't find one on the larger ones.

Oh, thanks for clearing that up :) Glad to hear it actually as I wasn't sure how I was going to handle mounting it to a heatsink.
The large ones will be as you thought, two of those at least will be for 240v elements (HLT and RIMS), two others at least for March pumps. One will also end up controlling a LBP for HLT recirc.
The 4 of the small ones will be used in a fermentation controller (really didn't need 8!) for switching heating and cooling circuits on; I can build in protection for excessive switching pretty easily into the software for both.
 
There's pros and cons for both types, obviously SSRs don't wear out, but being an electronic part they can still fail and can typically fail ON, they are also susceptible to mains voltage spikes although on a domestic supply these are less likely.

Mechanical relays wear out and contacts can weld shut if used on too high a power load or large inductive loads, compressor motors, things with a large inrush current, etc.

I'm not sure how often your heating elements will need to cycle on but at say twice a minute for an hour that is 120 actions which would give over 800 hours... perhaps not an issue but something to be aware of, should be fairly easy to change them if needed down the track anyway
 
Thanks guys.

Bonj, That's a good article. I'd be grateful if you would elaborate on your tuning process, just so I can make sure I'm on the right track. For example, did you start off with "set all gains to zero", and does that mean Kp, Ki, and Kd are all zero for the Arduino PID implementation, or have I misunderstood that and e.g. Kp != proportional gain?

Also, I think the Arduino PID library defaults to PI rather than PID. There's a command to set it to PID, but I don't see that in anybody's code. Are people happy just using PI? If so, that sounds like it makes the tuning process a little easier.

Cheers,

Jon
What I tend to do, is arbitrarily pick a P value, and then follow their instructions with regard to setting the I and D values. Following the very basic premise that the P gain sets to speed at which you approach your target and the I gain sets the rate at which you adjust for error over time (If the correction isn't correcting enough, it accumulates the I gain to correct faster... that can lead to over correction and instability if the accumulator has a chance to run away. This is why Matho only enables PID control within 5C of the target temperature and also why we experimented with clamping the accumulator (I use the modified library in my HERMS, but matho elected not to, in favour of the 5C method)). The D term attenuates (dampens) the speed at which you approach the target as you get closer, so as to hopefully avoid overshoot.

Apart from that, you basically have to run the system a number of times under similar to expected conditions in order to adjust the gains by trial and error. I played with mine in a 2.4KW kitchen jug which enabled me to check it was working and the tuning iterations were faster (albeit completely different from an actual system), but the jug is so over powered for the volume of water that it is very hard to tune.

The arduino PID algorithm, incidently doesn't disable the D term by default. Most people are happy with a PI system, or even a PD. The article I linked does a good job of explaning the benefits and drawbacks of the various configurations.
 
Bonj said:
What I tend to do, is arbitrarily pick a P value, and then follow their instructions with regard to setting the I and D values. Following the very basic premise that the P gain sets to speed at which you approach your target and the I gain sets the rate at which you adjust for error over time (If the correction isn't correcting enough, it accumulates the I gain to correct faster... that can lead to over correction and instability if the accumulator has a chance to run away. This is why Matho only enables PID control within 5�C of the target temperature and also why we experimented with clamping the accumulator (I use the modified library in my HERMS, but matho elected not to, in favour of the 5�C method)). The D term attenuates (dampens) the speed at which you approach the target as you get closer, so as to hopefully avoid overshoot.

Apart from that, you basically have to run the system a number of times under similar to expected conditions in order to adjust the gains by trial and error. I played with mine in a 2.4KW kitchen jug which enabled me to check it was working and the tuning iterations were faster (albeit completely different from an actual system), but the jug is so over powered for the volume of water that it is very hard to tune.

The arduino PID algorithm, incidently doesn't disable the D term by default. Most people are happy with a PI system, or even a PD. The article I linked does a good job of explaning the benefits and drawbacks of the various configurations.
Bonj, thanks. I'd got the PID library and PID autotune library confused - it's the latter that defaults to PI.

I've since looked through the PID library to see how the output is calculated, and it's a whole lot simpler than I'd thought. In the sort of scenario a PID's going to be used for in a home brewery, it seems to me that the D term is ineffective unless the gain (Kd) is very high. For example, in my HLT, I'm getting about 1 degree a minute temp rise. That's a small fraction of a degree per second. Unless Kd is several hundred, the impact of the D term is going to be insignificant. However, my DS18B20 measures at 12 bits, so increments in 0.0625 degree jumps every several seconds. I therefore get several seconds of D=0 followed by one of D=high, i.e. noise. I've therefore effectively disabled D by setting it to 1.

When I originally went through Matho's code, I didn't understand why (a) he'd disabled PID until within 5 degrees, and ( B) set the PID output to 100 when his PID window size is 5000ms (at least I think he's done that, now I'm not sure :)

I had my PID output set to 5000, as that's what my window size is. The trouble is the I term winds up to 5000 very quickly, and unless Ki is large, the accumulator takes ages to unwind and you get huge overshoot. I've now set my output to 100, and just use a multiplier to convert that to my window size (i.e. max output x 50 = window size.) With Ki limited to max output, it's a lot quicker to unwind with a smaller Ki. Here's the sort of response I'm getting on a test run of my HLT ~ 2/3 full with Kp = 100, Ki = 1.4, Kd = 1

HLT graph.jpg

I'm still getting some overshoot, but no oscillation, and it settles down to target temp within a few minutes. That's fine for the HLT. Next is the direct fired RIMS MLT which might be a bit more tricky to tune.

Cheers,

Jon
 
When I was testing with my electric jug, the best I could do was:

Kp=5, Ki=0.5, Kd=98. I also clamped the Ki to never go over 5 to prevent wind up.

With those values, I was getting around a 0.7°C overshoot, which isn't bad considering it is a 2.4KW element in a 1.7L vessel.
 
I have spent a lot of time playing with the pid library but I just went with the original one and turned it on 5 degs to go which reduces the amount of Ki wind-up but if you look at the PID beta 6 library http://code.google.com/p/arduino-dac/source/browse/DecaTest_v2/ArduinoCode/libs/PID_Beta6/?r=23 it does not intergrate unless the output is below maximum output which limits it from winding up. I have played with clamping Ki, which works well but can cause overshoot or undershoot depending on how much you clamp it to. I also have changed the standard library so that when kp is above max out Ki is 0 and if kP is negative then Ki is 0, that work OK but could be a bit notchy.

Iterm clamp library http://www.mediafire.com/?oo9e5b0t7g1l08w

Iterm clamp + no intergration when limits are exceeded http://www.mediafire.com/?4do6ld357286azp

Iterm clamp + Iterm set to 0 if outputs are exceeded http://www.mediafire.com/?4do6ld357286azp

the last one was made up for step mashing.

The PID figures in the brauduino code was a bit of a guess as don't know what system the unit is going to be used on.

Heating water takes a very long time so increase you sample time to reduce the number of times that Ki intergrates also if you make it long enough you will eliminate the problem you mentioned with the KD.

I'll upload a spreadsheet that I used to get my head around all this pid stuff

cheers steve
 
I haven't tried or even looked at the autotune so I don't know about it but the PID beta 6 library looks like a better library to me, the brewtroller uses it for its PID. here http://www.mediafire.com/view/?9ewpb6mib64nbvk is the spreadsheet that I put together to have a play with pids, its not very flash and it would take too long to explain how it works but have a play and a look and you should be able to work it out. I converted it from .ods to .xml so it might not work as well.

cheers steve
 
I skipped the autotune, but I do use the v102 library with the clamp, works a treat for me.
 
vortex said:
Picked up a couple of I2C relay boards:
[ ... ]
Small one has 8 relays, 10a@250v, I2C connection.
[ ... ]

Big one has 8 relays, 30a @250v. I2C connection also. Likely to need a bloody big heatsink :)

Got them from http://www.ereshop.com/shop/i2cbus-boards-c-143.html ordered last thursday, arrived today. Not the cheapest boards around but should do the job! Documentation is a little thin on the ground, though :( Ti chip, so hoping it's common enough that there is plenty of doco around for it.
These look nice, and I guess an 8-port board would mostly do a whole brewery.

I've been playing with these: http://arduino-direct.com/sunshop/index.php?l=product_detail&p=218
They're not I2C, but $3.95 is about my price point ;)

Once I finalise my design, I plan on buying a few of these, and when the mechanics wear out, just dropping in a new one.
They also have 4-port and 8-port relay boards.

cheers,
-kt
 
For the Arduino aficionados out there, I'm looking to try and build an automated brewery that will control:

2x 2400w elements in one vessel, a ~1000w element in another, a march pump, a klaixon pump, a brown pump, three temp probes, 12v atv winch, one or two 12v motors, probably two float switches.

Can I run all these things from one controller? If not can one controller be triggered from another? E.g- once mashout is completed can the main vessel controller trigger another to engage, with the other controller operating the winch, heating of sparge water, and pumping of the heated sparge water?

If it's not possible I will look to just make two controllers, and after a few runs overseeing the brewday manually, should have the temp ramp timing sussed enough to set both controllers independently but working together (if that makes sense).

Any insight/advice would be much welcomed as I have essentially zero knowledge on all things Arduino.


Cheers
 
So, two elements, means two relays from one output, another element relay from another output, three relays for three pumps (one is 12v but controlling is no different) a relay for the winch, relays for another two more 12v motors.

Two float switches on inputs. What about temp sensors for mash temps?

Anyway, I count at least 10 relays. That's a lot of relays.

You can buy I2C relay boards which have 8 relays, i have some of those, so in theory you can control enough relays.
Temp sensors the DS18B20 OneWire's are OK, they work with Arduino OK too.
Inputs for float switches should then have ample space available.

Programming logic should fit on the ROM of an Uno, so that might work OK but if the budget isn't too tight, have a look at the Arduino Mega, which has a lot more ROM space for sketches.

Or do what I did and use something like a BeagleBone/RaspberryPi, which are embedded linux platforms, way more powerful and way more flexible.
 
Cheers for the reply Vortex,

I'll look into the l2c relay board you mentioned, sounds like that might be the go.

I already have the DS18B20 sensors but they have three wires from memory.
The plan was to use two of them in the main vessel for the mashing (was thinking if possible to use the average temp between the two sensors-not sure if that's even possible and may be over complicating things) and use the other sensor in the sparge water vessel.

Float switches aren't a necessity-more just a piece of mind thing to ensure I've always got wort above the elements.

Definitely have some more reading/research to do! :icon_cheers:
 
Judanero said:
I already have the DS18B20 sensors but they have three wires from memory.
Yes they have 3 wires, they run on a one wire bus (one wire for data) and can be daisy chained, I'm sure one of the guru's will chime in and explain it better.
 
MastersBrewery said:
Yes they have 3 wires, they run on a one wire bus (one wire for data) and can be daisy chained, I'm sure one of the guru's will chime in and explain it better.
You can't explain it much better than that. Each sensor has its own address, and I think 7 can be run on the same bus (data wire).

I've just received the parts for more bonjuinos if that interests you. They require assembly and a separate programming cable (USB to serial cable with FTDI FT232RL chip) / breakout board (FT232RL basic breakout (usually a bit cheaper than the cable (around $12))), but are a bit more flexible than a standard arduino. You can see the differences here: http://www.bigfathooker.com/bfh/bonjuino.php

Arduino's can be configured to talk to each other either by I2C or serial, but as vortex said, with that many I/Os and associated code, you may want to think about an Arduino Mega.
 
vortex said:
I picked up two boards from here, 10amp x 8 for fermentation controller, and 30amp x 8 for the brewery.
http://www.ereshop.com/shop/i2cbus-boards-c-143.html
If your using relays to control Heating elements with PID you will need SSR's (solid state relay) due to high frequency of switching, those little ones will burn out. These would need one digial pin for each device (eg Kettle or HLT).
 
MastersBrewery said:
If your using relays to control Heating elements with PID you will need SSR's (solid state relay) due to high frequency of switching, those little ones will burn out. These would need one digial pin for each device (eg Kettle or HLT).
Not what I've been told. I was told they could have shorter service life, I can live with that, but I'm implementing the PID algorithm in software which I'm writing so I will have my own protections built in also.
 
vortex said:
Not what I've been told. I was told they could have shorter service life, I can live with that, but I'm implementing the PID algorithm in software which I'm writing so I will have my own protections built in also.
problem being if it goes pear shape they are know to fail in the closed position when over heated, so software won't turn it off. though as a fail safe you could use a second relay the remains closed constantly whilst device is in use.
 
Yep, the plan is to switch active and neutral, as I have more relays than I need anyway. To hopefully prevent those issues, but also for safety.
 
I would still recommend against mechanical relays for pid because of the electrical noise and associated glitches you will face. That is a lot of EMI and a Shitload of clicking noise!

Also if you are using 3x PID then you will use a lot more code space than the rest of us who use only one. I would go with the previous version of the mega, which you can source really cheaply these days. DX.com
 
Edak said:
I would still recommend against mechanical relays for pid because of the electrical noise and associated glitches you will face. That is a lot of EMI and a Shitload of clicking noise!

Also if you are using 3x PID then you will use a lot more code space than the rest of us who use only one. I would go with the previous version of the mega, which you can source really cheaply these days. DX.com
Thanks. My brewery will be using a BeagleBone so code size isn't an issue.
 
yes, but the clicking would drive you insane!

I have an expensive data logger which uses physical relays for all analog channels (to provide full channel-channel isolation), the clicking drives me crazy so I use digital sensors only.
 
Back
Top