Hi. My project aims to implement a PID temperature control to run a heating element, using a thermistor (NTC 100k) for sensing in A0. The heating element is controled by Arduino's pin 13 using a D4184 MOSFET module to command its connection to a power supply. I'm using two libraries for the code: ArduPID and SmoothThermistor. The problem is that I can't get a control loop going, the heating element temperature just shoots straight up.
I have tried other code as well, replacing the "SmoothThermistor" library by various Steinhart-Hart calculation codes I found on the internet. But same outcome as before.
I'm aware that there are other PID libraries as well, but the one I'm using seems the most user-friendly of them all.
I've seen posts on this forum about PID "troubles" but didn't help.
This problem arises from the PID k values? Tried many. Or is something else going on? I can't get around this. Please help.
Thanks for your time.
Libraries:
Thermistor wiring (100k Thermistor and 100k Resistor):
Your input variable is PID_input but you never update the value so why do you think the output will change?
The same is true for PID_output which never gets applied to your- output. Also, Pin 13 does not support PWM so analogWrite() does not work on that pin.
#include "ArduPID.h"
ArduPID myController;
double **input**;
double output;
// Arbitrary setpoint and gains - adjust these as fit for your project:
double setpoint = 512;
double p = 10;
double i = 1;
double d = 0.5;
void setup()
{
Serial.begin(115200);
myController.begin(&**input**, &output, &setpoint, p, i, d);
// myController.reverse() // Uncomment if controller output is "reversed"
// myController.setSampleTime(10); // OPTIONAL - will ensure at least 10ms have past between successful compute() calls
myController.setOutputLimits(0, 255);
myController.setBias(255.0 / 2.0);
myController.setWindUpLimits(-10, 10); // Groth bounds for the integral term to prevent integral wind-up
myController.start();
// myController.reset(); // Used for resetting the I and D terms - only use this if you know what you're doing
// myController.stop(); // Turn off the PID controller (compute() will not do anything until start() is called)
}
void loop()
{
**input** = analogRead(A0); // Replace with sensor feedback
myController.compute();
myController.debug(&Serial, "myController", PRINT_INPUT | // Can include or comment out any of these terms to print
PRINT_OUTPUT | // in the Serial plotter
PRINT_SETPOINT |
PRINT_BIAS |
PRINT_P |
PRINT_I |
PRINT_D);
analogWrite(3, output); // Replace with plant control signal
}
Thanks for your feedback. You are right pointing out that mistake, I made a clumsy job pasting the code here (fixed it). The code used by my Arduino didn't have that error.