Benny Estes
Published © LGPL

Cloud Controlled Pellet Smoker

I decided to build something better so that I can monitor my smoker from the inside.

BeginnerWork in progress3 hours5,571
Cloud Controlled Pellet Smoker

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <WiFi101.h>
#include <CayenneMKR1000.h>
#include <Timer.h>
#include <PID_v1.h>
#include <SPI.h>
#include <MAX31855_SPI.h>

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

#define AugerPin 2

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,0.5,1,5, DIRECT);

int WindowSize = 30000;
unsigned long windowStartTime;
byte cs = 0; //chip select is DIO 0
double internal_temp;
double coupler_temp;
MAX31855_SPI *max31855;

int running = 0;

Timer t;

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
//char token[] = "";
// Your network name and password.
char ssid[] = "";
char password[] = "";

void setup()
{
  max31855 = new MAX31855_SPI(cs);
  SPI.begin();

  //relays
  pinMode(1,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  
  //setup the pid
  windowStartTime = millis();

  //initialize the variables we're linked to
  Setpoint = 100;

  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
}

void loop()
{
  internal_temp = max31855->readInternal();
  internal_temp = internal_temp * 9 / 5 + 32;
  coupler_temp = max31855->read();
  coupler_temp = coupler_temp * 9 / 5 + 32;
  
  Cayenne.run();
  
  t.update();

  if(running)
  {
    Input = coupler_temp;
    myPID.Compute();
  
    /************************************************
     * turn the output pin on/off based on pid output
     ************************************************/
    unsigned long now = millis();
    if(now - windowStartTime>WindowSize)
    { //time to shift the Relay Window
      windowStartTime += WindowSize;
    }
    if(Output > now - windowStartTime) digitalWrite(AugerPin,1);
    else digitalWrite(AugerPin,0);    
  } 
  else digitalWrite(AugerPin,0);    
}

//setpoint
CAYENNE_IN(V0)
{
  Setpoint = getValue.asInt()/1000;

  Serial.print("Setpoint:");
  Serial.println(Setpoint);
}

//cold junction temp
CAYENNE_OUT(V1)
{
  Cayenne.virtualWrite(V1,internal_temp);
}

//thermocouple temp
CAYENNE_OUT(V2)
{
  Cayenne.virtualWrite(V2,coupler_temp);
}

//start button
CAYENNE_IN(V3)
{
  if (getValue.asInt())
  {
    running = 1;    

    //indicate running
    Cayenne.virtualWrite(V8,1);

    //clear start button
    Cayenne.virtualWrite(V3,0);

    //start fan
    digitalWrite(3,1);

    //indicate fan running
    Cayenne.virtualWrite(V7,1);
    
    //start ignitor cycle
    ignite();           
  }
}

//shutdown button
CAYENNE_IN(V4)
{
  if (getValue.asInt())
  {
    running = 0;    

    //indicate shutting down
    Cayenne.virtualWrite(V8,0);
    Cayenne.virtualWrite(V9,1);

    //do some stuff
    
    t.after(5000,shutdown);

    //clear shutdown button
    Cayenne.virtualWrite(V4,0);
  
  }
}

//hopper low
CAYENNE_OUT(V6)
{
  Cayenne.virtualWrite(V6,digitalRead(2));
}

void shutdown()
{
  //check temp is cool
  //send error messages, etc.
  //turn off fan
  //clear internal variables

  //ignitor
  Cayenne.virtualWrite(V5,0);
  //auger
  Cayenne.virtualWrite(V6,0);
  //fan
  Cayenne.virtualWrite(V7,0);

  //indicate no longer running
  Cayenne.virtualWrite(V9,0);
  
}

void ignite()
{
  //indicate ignitor on
  Cayenne.virtualWrite(V5,1);

  //actually start the ignitor
  digitalWrite(1,1);

  //set callback timer
  t.after(10000,ignitor_off);
}

void ignitor_off()
{
  //turn off the ignitor
  digitalWrite(1,0);

  //check temperature
  //alert if not hot enough

  //indicate ignitor off
  Cayenne.virtualWrite(V5,0);
}

void auger_time()
{
  digitalWrite(AugerPin,1);
  Cayenne.virtualWrite(V6,1);
  delay(1000);
  digitalWrite(AugerPin,0);
  Cayenne.virtualWrite(V6,0);
}

Code snippet #2

Plain text
//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <WiFi101.h>
#include <CayenneMKR1000.h>
#include <Timer.h>
#include <PID_v1.h>
#include <SPI.h>
#include <MAX31855_SPI.h>

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

#define AugerPin 2

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,0.5,1,5, DIRECT);

int WindowSize = 30000;
unsigned long windowStartTime;
byte cs = 0; //chip select is DIO 0
double internal_temp;
double coupler_temp;
MAX31855_SPI *max31855;

int running = 0;

Timer t;

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
//char token[] = "";
// Your network name and password.
char ssid[] = "";
char password[] = "";

void setup()
{
  max31855 = new MAX31855_SPI(cs);
  SPI.begin();

  //relays
  pinMode(1,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  
  //setup the pid
  windowStartTime = millis();

  //initialize the variables we're linked to
  Setpoint = 100;

  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
}

void loop()
{
  internal_temp = max31855->readInternal();
  internal_temp = internal_temp * 9 / 5 + 32;
  coupler_temp = max31855->read();
  coupler_temp = coupler_temp * 9 / 5 + 32;
  
  Cayenne.run();
  
  t.update();

  if(running)
  {
    Input = coupler_temp;
    myPID.Compute();
  
    /************************************************
     * turn the output pin on/off based on pid output
     ************************************************/
    unsigned long now = millis();
    if(now - windowStartTime>WindowSize)
    { //time to shift the Relay Window
      windowStartTime += WindowSize;
    }
    if(Output > now - windowStartTime) digitalWrite(AugerPin,1);
    else digitalWrite(AugerPin,0);    
  } 
  else digitalWrite(AugerPin,0);    
}

//setpoint
CAYENNE_IN(V0)
{
  Setpoint = getValue.asInt()/1000;

  Serial.print("Setpoint:");
  Serial.println(Setpoint);
}

//cold junction temp
CAYENNE_OUT(V1)
{
  Cayenne.virtualWrite(V1,internal_temp);
}

//thermocouple temp
CAYENNE_OUT(V2)
{
  Cayenne.virtualWrite(V2,coupler_temp);
}

//start button
CAYENNE_IN(V3)
{
  if (getValue.asInt())
  {
    running = 1;    

    //indicate running
    Cayenne.virtualWrite(V8,1);

    //clear start button
    Cayenne.virtualWrite(V3,0);

    //start fan
    digitalWrite(3,1);

    //indicate fan running
    Cayenne.virtualWrite(V7,1);
    
    //start ignitor cycle
    ignite();           
  }
}

//shutdown button
CAYENNE_IN(V4)
{
  if (getValue.asInt())
  {
    running = 0;    

    //indicate shutting down
    Cayenne.virtualWrite(V8,0);
    Cayenne.virtualWrite(V9,1);

    //do some stuff
    
    t.after(5000,shutdown);

    //clear shutdown button
    Cayenne.virtualWrite(V4,0);
  
  }
}

//hopper low
CAYENNE_OUT(V6)
{
  Cayenne.virtualWrite(V6,digitalRead(2));
}

void shutdown()
{
  //check temp is cool
  //send error messages, etc.
  //turn off fan
  //clear internal variables

  //ignitor
  Cayenne.virtualWrite(V5,0);
  //auger
  Cayenne.virtualWrite(V6,0);
  //fan
  Cayenne.virtualWrite(V7,0);

  //indicate no longer running
  Cayenne.virtualWrite(V9,0);
  
}

void ignite()
{
  //indicate ignitor on
  Cayenne.virtualWrite(V5,1);

  //actually start the ignitor
  digitalWrite(1,1);

  //set callback timer
  t.after(10000,ignitor_off);
}

void ignitor_off()
{
  //turn off the ignitor
  digitalWrite(1,0);

  //check temperature
  //alert if not hot enough

  //indicate ignitor off
  Cayenne.virtualWrite(V5,0);
}

void auger_time()
{
  digitalWrite(AugerPin,1);
  Cayenne.virtualWrite(V6,1);
  delay(1000);
  digitalWrite(AugerPin,0);
  Cayenne.virtualWrite(V6,0);
}

Credits

kreggly

Posted by Benny Estes

Comments