Arduino PID Library

Brett,

I am building a simple temperature controller and I'm attempting to use your PID library. The arduino reads the temperature from an LM35 and then outputs a slow PWM pulse to a solid state relay which will switch a standard electrical output. I figure I'll plug in either a water bath heater or an electric smoker to the outlet, it seems like it should work just as well for either application. Anyhow, I don't have much of the hardware yet (it's all on order), but I put together the code and I wanted to make sure I was utilizing the PID library correctly. As you can see, I'm using the Timer1 library to run a 1 second PWM pulse. I wouldn't think a heating element would need anything faster than that. The PID output adjusts the duty cycle of the pulse:

#include <TimerOne.h>      
#include <PID_Beta6.h>

double Input, Output;                                  //PID variables
double Setpoint = 140;                               //PID setpoint in Farenheit
 
int thermPin = 0;                                    //input read pin for LM35 is Analog Pin 0
int controlPin = 9;                                           //Output PWM pin to Solid State Relay
                             
int val;

PID pid(&Input, &Output, &Setpoint, 3,4,1);            //Setup the PID calculation

void setup()
{

         pinMode(controlPin, OUTPUT);              //Setup the pin to control the relay

         pid.SetOutputLimits(0,1023);             //tell the PID to range the output from 0 to 1023 
         Output = 1023;                                     //start the output at its max  and let the PID adjust it from there
         pid.SetMode(AUTO);                               //turn on the PID

      Timer1.initialize();                              //turn on the Timer, default 1 second frequency
      Timer1.pwm(controlPin, (int)Output);      //start PWM on pin 9 with a 100% duty cycle
   
}

void loop()
{
    
         val = analogRead(thermPin);                                                        //read the value of LM35
         Input = ((5.0 * val * 100.0 / 1023.0) * 9.0 / 5.0) + 32.0;       //convert voltage to temperature(F)

         pid.Compute();                                                      //give the PID the opportunity to compute if needed

      Timer1.setPwmDuty(controlPin, (int)Output);            //Set the duty cycle of the PWM according to the PID output

}

Any comments or tips would be very much appreciated.

-zv