BBQ temp controller help

Dear all,

I’m working on a project to control the temperature in my BBQ a Webber and or a reverse flow smoker.

With a max6675, PID, PWM output on a fan and U8glib driver for the display ssd 1306.

Ive managed to compile a sketch and so far it shows me the temperature reading and through the plotter i can see that my PID is doing something.
when i attach my fan, the darn thing is going full speed and when reaching the setpoint it is still going 100% of the speed.

Also the PID is like a PWM signal giong up and down, see pic.

Can somebody help me on this project? The sketch is taking approx 80% of memory.

Also please find attached a picture of the plotter and of course the sketch.

Thanks in advance…

sketch_jul12_BBQ_TEMP_CONTROL_PID.ino (3.24 KB)

The attached code where everyone can see it. You’re welcome.

// Add libraries
  #include "U8glib.h"
  #include <SPI.h>
  #include <Wire.h>
  #include "max6675.h"
  #include <PID_v1.h>

  #define FAN 3           // Output pin for fan      
  boolean centigrade = true; //Un REM this for Centigrade and REM out line below

//Setup PID
  double Setpoint, Input, Output;                                          //I/O for PID
  double aggKp=20, aggKi=0.2, aggKd=1;                                      //original: aggKp=4, aggKi=0.2, aggKd=1, Aggressive Turning,50,20,20
  double consKp=10, consKi=0.1, consKd=0.25;                                    //original consKp=1, consKi=0.05, consKd=0.25, Conservative Turning,20,10,10
  PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);  //Initialize PID

//setup u8g object
  U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);  // I2C 
  double max = 215; // maximum temperature
  double min = -215; // minimum temperature
  float currentTemp = 0.00;
  String thisTemp = "";
  int maxTemp = 0; // maximum temperature reached
  int minTemp = 0; // minimum temperature reached
  int pad = 0;

// Thermocouple MAX 6675
  int thermoDO = 8;
  int thermoCS = 9;
  int thermoCLK = 10;
  MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

void draw(void) {
  u8g.drawStr(20,10, "BBQ TEMP");
  if(currentTemp > 99){pad = 2;}
  if(currentTemp > 9 && currentTemp < 100){pad = 10;}
  if(currentTemp < 10){pad = 18;}  
  thisTemp = String(currentTemp);
    thisTemp = thisTemp + "\260C";
    thisTemp = thisTemp + "\260F";    
  const char* newDispC = (const char*) thisTemp.c_str(); 
  u8g.drawStr(pad,50, newDispC);

void setup(void) {
  //Temperature Setup  
  currentTemp = thermocouple.readCelsius();
  minTemp = int(thermocouple.readCelsius());
  maxTemp = int(thermocouple.readCelsius());    
  Setpoint = 124;                          //Inintialize desired Temperature in Deg C
  //PID Setup
  //TCCR2B = TCCR2B & 0b11111000 | 0x02;  //adjust the PWM Frequency, note: this changes timing like delay() Gerd, dit is de PWM timer. Kun jij checken of deze goed is voor 21Khz-25Khz voor een fan?

  void loop(void) {
  currentTemp = 0;
  for(int f = 0; f <25; f++){
     currentTemp = thermocouple.readCelsius() + currentTemp; 
  //Get temperature and give it to the PID input
  //Compute PID value
  double gap = abs(Setpoint-Input); //distance away from setpoint
  if(gap < 15)
    //Close to Setpoint, be conservative
    myPID.SetTunings(consKp, consKi, consKd);
     //Far from Setpoint, be aggresive
     myPID.SetTunings(aggKp, aggKi, aggKd);
  Serial.print(" ");
  Serial.print(" ");
  currentTemp = currentTemp/25;  // averages out 25 readings
  // picture loop
  do {
  } while( u8g.nextPage() );
  // rebuild the picture after some delay

Thanks! :slight_smile: