PID Thermal Control System

122 views
Skip to first unread message

E Rosenfeld

unread,
Jun 23, 2023, 3:11:33 PM6/23/23
to DIY PID Control
Hi, I am new to PID controllers. I am creating a thermal control system that involves a resistive heater in series with a transistor. I have a thermistor in a Wheatstone bridge to measure the temperature of a flat plate on top of the heater. I have adapted the Basic PID code to allow for the input to be the output of the Wheatstone bridge. I started with the Ziegler-Nichols Method to tune the controller, but no matter how high I set Kp (I have gone up to 100,000), I still get zero response in the system. The power supply I am using shows that there is zero current flowing, so the transistor is not being turned on. I know that it is not a hardware issue because I coded an open loop system and when I run that code the system operates perfectly fine. If anyone could help me solve this problem that would be greatly appreciated. Here is my code:

#include <PID_v1.h>

#define PIN_INPUT 5
#define IN_CONST 0
#define PIN_OUTPUT 3

// Thermistor Setup
unsigned long rd = 50;
unsigned long ptrd = 0;

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp=200, Ki=0, Kd=0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(PIN_INPUT)-analogRead(IN_CONST);
  Setpoint = 321;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);

  Serial.begin(115200);
}

void loop()
{
  Input = analogRead(PIN_INPUT)-analogRead(IN_CONST);
  myPID.Compute();
  analogWrite(PIN_OUTPUT, Output);

  unsigned long currentTime = millis();
 
  if((currentTime-ptrd)>=rd){
    ptrd = currentTime;    
    Serial.print(ptrd);
    Serial.print('\t');
    Serial.println(Input);
  }
}

Thank you for any help!
Ethan

Steve Edmonds

unread,
Jun 23, 2023, 3:46:32 PM6/23/23
to diy-pid...@googlegroups.com
If you monitor with Serial.print(Input); Serial.print(Output); are you getting sensible values.
By an open loop system, did you mean something like https://www.geeksforgeeks.org/analog-write-and-working-of-pwm-in-arduino/ which will test variable power to the heater and check the input range for different temperatures.
--
You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/cec9e74c-8f84-4094-84ee-a0d1e7e4e136n%40googlegroups.com.

Pieter S

unread,
Jun 25, 2023, 3:01:42 AM6/25/23
to diy-pid...@googlegroups.com
Hi Ethan

Care to share a schematic of your set up?

Are you able to test the different component on own?

Regards,

E Rosenfeld

unread,
Jun 25, 2023, 8:24:13 PM6/25/23
to diy-pid...@googlegroups.com
Thank you Pieter and Steve for your responses. For Steve, my code is outputting input values to serial, so I can see that the input values are definitely sensible. I have not tried serial writing the output but I am not sure that this would be much help because I can see that not much is happening. For the open loop system, it was coded to preheat at full power for a set period of time and then it changed to a trial and error based PWM duty cycle to keep the heater at a constant temperature. From what I am reading from the link you provided, I do not think my open loop system is similar to that system.

Pieter, I have attached a screenshot of my schematic. I can test the different components on their own, but I do know that they are all working properly because my open loop code still works well. 

Thank you for any help you can provide with this additional information.
Ethan

image.png

You received this message because you are subscribed to a topic in the Google Groups "DIY PID Control" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/diy-pid-control/3W7aA1dkvKY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/CAL-R9VaBMKx4sg8g2OypYZuhO9DU6qbVzeRJkVMUE59oQ_QnRQ%40mail.gmail.com.

Steve Edmonds

unread,
Jun 25, 2023, 11:43:56 PM6/25/23
to diy-pid...@googlegroups.com
Hi Ethan.
I've been running that library successfully so it is probably something simple. Logging Output will show if anything is happening, May be it is say 0 to 5 or some low value but calculating. I think default range is 0-255.
I also tend to convert input to degrees for ease of reading, plotting and comparison against setpoint.

What board are you using, on my UNO analogue input would be pins A1, A5 not 1 and 5.
Steve

Pieter S

unread,
Jun 26, 2023, 8:35:01 AM6/26/23
to diy-pid...@googlegroups.com
Yes, as Steve mentioned - look at how you assign Analog pins, as well as declaring in setup()


It's not stated if your thermistor is NTC or PTC - but you probably need to match/map your feedback value with set point value (same type variable, units)


Regards,

P


On Fri, 23 Jun 2023, 21:46 Steve Edmonds, <st...@edmondsfamily.co.nz> wrote:

John Schindler

unread,
Jun 26, 2023, 8:36:13 AM6/26/23
to DIY PID Control
Steve,

Definitely print out the input, output, and setpoint. With just proportional control, you can do the calculation easily and see if it is behaving.

John

Reply all
Reply to author
Forward
0 new messages