# Use of the PID-controller node

**URL:** <https://forum.xod.io/t/use-of-the-pid-controller-node/4284>\
**Category:** XOD Programming Questions\
**Created:** [August 1, 2020, 8:35pm UTC](https://forum.xod.io/t/use-of-the-pid-controller-node/4284 "2020-08-01T20:35:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jh295](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jh295](https://forum.xod.io/u/jh295)\
**Post date:** [August 1, 2020, 8:35pm UTC](https://forum.xod.io/t/use-of-the-pid-controller-node/4284/1 "2020-08-01T20:35:32Z")

</div>

Hi - this might be a dumb question, but here goes…

I want to use the PID-controller node ([https://xod.io/libs/xod/core/pid-controller/](https://xod.io/libs/xod/core/pid-controller/)) for temperature control in a biological micro reactor ([https://www.hackster.io/jim-haseloff/airflow-microreactor-projects-327330](https://www.hackster.io/jim-haseloff/airflow-microreactor-projects-327330))…and I’m not convinced that I know how to use it properly.

I have 3D printed vessels that are heated by a fan-driven PTC heater (12V, 100W), switched on-off under arduino control, using a MOSFET. I’m using DS18b20 temperature sensors for feedback. All is good electrically/thermally - but I am keen to optimise speed and accuracy of the temperature control. So far, I have been mainly using a simple “bang-bang” software controller, using the target temperature(s) as threshold. I have also hooked up the output of the PID-controller to the MOSFET switch for the heater, and attempted to tune the controller - but I have a few questions, that I’m hoping that a proper engineer can help with!

I’m not sure of the proper use of the values from PID-controller output pin - when the heater device has just on-off states. As I understand it, the controller output will produce a numerical output that decreases to zero as the target is approached. Is there any more information about the range of values or code examples? I have used a standard digital output port, and also piped the PID-controller output through a pwm-node. Am I throwing away useful information by doing this? i.e. effectively clipping the values and reverting to something closer to a simple on-off switch around the set threshold?

I also have some doubts about using an Arduino PWM pin to drive the PTC heater? The normal ~500Hz switching frequency doesn’t seem sensible for a relatively slow responding air heated system (~1 Hz seems more likely, to avoid electrical issues, heating MOSFETs, etc.). I’ve seen (non-XOD) instances online where software is used to convert a PID output to generate a more slowly switching output - say, over 5 secs, instead of 2 ms.

Does anyone have any examples or advice to share? Any help would be much appreciated!

(I’ve attached a view of one of the patches used - the Arduino is hooked up to a 4D Systems touchscreen that is used for input and display)

 ![PID-controller1](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/4/4009d7705443cbd4b28ab426b6afed95beb31796.png)

bw, Jim.

---

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [August 2, 2020, 2:02am UTC](https://forum.xod.io/t/use-of-the-pid-controller-node/4284/2 "2020-08-02T02:02:36Z")

</div>

Which Arduino are you using? you can change the pwm frequency in a roundabout way depending on which arduino you have.

if its a mega 2560 you can change the frequency by injecting abit of code.  
Steps

1. click on Deploy\> show code for arduino
2. in the code find “Void Setup”
3. paste “TCCR2B = TCCR2B & B11111000 | B00000001; // last 3 digits determine PWM Freq” the link below will tell you what last 3 digits will get you for a PWM frequency  
([http://usethearduino.blogspot.com/2008/11/changing-pwm-frequency-on-arduino.html](http://usethearduino.blogspot.com/2008/11/changing-pwm-frequency-on-arduino.html))
4. open arduino IDE and upload, you’ll need to use a scope to verify pwm frequency has changed.

Unfortunately doing it this way will not allow you to run the XOD Debug feature.

---

<div class="post-metadata">

**Author:** ![jh295](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jh295](https://forum.xod.io/u/jh295)\
**Post date:** [August 2, 2020, 5:36pm UTC](https://forum.xod.io/t/use-of-the-pid-controller-node/4284/3 "2020-08-02T17:36:53Z")

</div>

Hi - thanks for the tip - could be useful for other things too…

I’m using a Totemduino - an UNO R3 compatible with a few tweaks for hardware control and prototyping - integrated into a custom prototyping device ([https://www.hackster.io/jim-haseloff/programmable-test-rig-d7df62](https://www.hackster.io/jim-haseloff/programmable-test-rig-d7df62)). An indistinguishable UNO clone, as far as I can tell.

Totem info at:

> **[TotemDuino | Totemmaker.net](https://totemmaker.net/product/totemduino-arduino/)**
>
> TotemDuino expands upon the great Arduino UNO platform idea. While it is kept fully backwards compatible with Arduino, lot of additional features included.

  

> **[Breadboard Friendly Extension to TotemDuino | Totemmaker.net](https://totemmaker.net/product/breadboard-friendly-extension-to-totemduino/)**
>
> Breadboard extension. Designed to keep tidy connections to breadboards without using-up any of the Arduino compatible shield connectors on the TotemDuino.

I’m starting play around with parameters for the PID controller, setting different target temperatures from 30ºC to 95ºC, and watching the output of the pid-controller node. At the moment, these feed directly into the pwm-load node - and look like they will only trigger pwm output between the values of 0 and 1. Even when the temperature controller is surfing around the setpoint, and a few degrees away from the target temperature, the pid-controller output can be over 1 or less than 0…so I might as well be using on-off control of the heater. I guess that’s not unusual for a PID controller, so maybe I shouild just live with this.

…just wondering if I’m missing something. Finer control of the heater would be useful.

Things are about to get more complicated, as I have connected intake and exhaust fans for cooling, and these need to be controlled too (for thermal cycling - very useful in molecular biology).

Thanks again for the help. J.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [September 1, 2020, 5:37pm UTC](https://forum.xod.io/t/use-of-the-pid-controller-node/4284/4 "2020-09-01T17:37:01Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
