I have developed a computer controlled BBQ smoker, using a raspberry pi and car throttle valve damper, driven by a stepper motor, the temperature pick up is a thermocouple.

I have a python PID class to control the system and am struggling to tune it. When the set point temperature is reached (rising temp) the damper closes as expected, then re-opens once the temperature passes the set point (falling) but by this point the charcoal fire has gone out. I have tried different kP values to get a steady oscillation about the set point but I am plagued with it fully undershooting, ie going out. I need the damper to start re-opening as soon as the temperature starts falling, not once the system is in falling overshoot. I feel it is something to do with kI and kD. Please can I have some advice before spanking another kilo of charcoal! Many thanks people.

  • \$\begingroup\$ I'd use a binary search. At, say, 20 degrees below the target, close the throttle half way. The temperature will probably still rise, but more slowly. Continue to monitor 'til it reaches 10 degrees below target. If it's still rising fairly quickly, close it half the remaining distance. Continue closing half the remaining opening until the temperature steadies. You should quickly find a couple of points where it 1) rises slowly, and 2) drops slowly. You can then basically just shift between those. \$\endgroup\$ Oct 14, 2017 at 23:27
  • \$\begingroup\$ seeing as it has been bumped, there are other control responses to the usual quarter amplitude decay, in your case you would be deliberately winding up the P and D terms to make the circuit oscillate with just slightly less than a gain of 1, this way the circuit is constantly oscillating around your set point, and will have the fastest response at the cost of constantly over and undershooting by a small amount. \$\endgroup\$
    – Reroute
    Aug 31, 2019 at 13:41
  • \$\begingroup\$ Id drill a small hole in the butterfly so it cant fully shut just a trickle of air. \$\endgroup\$ Feb 11, 2021 at 9:54
  • \$\begingroup\$ @DarrenSmith This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review \$\endgroup\$
    – awjlogan
    Feb 11, 2021 at 10:47
  • \$\begingroup\$ That's probably a sensible thing to try :-). It's not really an answer to the question - but is a suggestion to addressing the problem :-). I'll convert this to a comment. You will be able to add comments when your 'reputation' score gets slightly higher. \$\endgroup\$
    – Russell McMahon
    Feb 11, 2021 at 11:06

2 Answers 2


There are several methodologies to tune a PID, some can be fully automated and rely on some level of system identification. But most of them are just rules of thumb.

For temperature control, you want to avoid the integral term as much as you can. It is necessary to remove steady state error, but any time spent far from the set point is time that the I term is increasing, and once you reach the desired temperature you need to spend the same error area in the opposite direction to decrease it back to where the other terms take control.

Work with a pure PD control, and if that is not good enough then introduce a small amount of an I term, making sure that the integral of the temperature ramp-up time error times the I gain does not overwhelm the contribution of the PD terms. The more I you introduce, the more D you are likely to need to accelerate the response. This is not likely to be steady-state optimal, but it would ensure the least controller overshoot.

Think of I as the history of the system while D is the prediction of its future trend.

You can start with a pure proportional control, set a proportional gain that provides 100% air when the error is 5°C below the target and 0% when it is 5°C above the target. This might be enough for your purposes and could result in a stable system if the system inertia is low enough. Increase the gain to reduce the error (this is likely to result in oscillations) and add a derivative term to keep the system stable. Only add an integral term is the resulting steady-state error of the stable system is too large for your application.

  • 1
    \$\begingroup\$ Since it is a programming API, it is likely that OP can cap the integral term to avoid windup. The steady state compensation is probably important to account for variable conditions such as the weather. \$\endgroup\$
    – Tormod
    Nov 22, 2021 at 15:47

The general rule of thumb when tuning a PID is to do it in that order. Turn all factors to 0.0f . First the Proportional should be increased in magnitude until it minimizes the error rate as much as it can. Then the integral, then the derivative. Of course it depends on the exact PID equation. is it P+I+D (the most common), P+I/D, P*I/D, etc. There are numerous forms, and I have seen people buy the wrong one.

I don't really use PID as much as I used to, neural networks are better and can adapt to system changes over time, while a PID has to be retuned occasionally.

  • \$\begingroup\$ It is a P+I+D. I've seen one which seems a lot more complicated with a logarithmic (base e) element to it but this one seems understandable by me!! I tested it on a flywheel, then went onto the BBQ. I like the idea of a neural network, there is a lot of high level information in the net, can you point me in the direction of an introduction? Tvm. \$\endgroup\$ Oct 15, 2017 at 20:03
  • \$\begingroup\$ I use FANN for just about everything. github.com/libfann/fann As for an introduction, it depends on your level of math. The standard is Neural networks by Simon S. Haykin, but that one is very heavy in math and deals with theoretical neural networks, which have arbitrary precision (i.e. unlimited precision). I recommend Neural networks for pattern recognition by Christopher Bishop. It is a little more approachable, but it does focus on pattern recognition, not so much controls. \$\endgroup\$ Dec 18, 2018 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.