Blynk crockpot

Here is the working model of my crock pot.

6 Likes

Congratulation! Give us more details please.
Thanks

What you want to here? I am in Ethiopia so there is not a lot available.
-Node MCU
-Analog M35 temp sensor insulated with hot glue, coated in JB weld to form a probe.
-Relay

Basic on if below set and off when set point is reached.

I was going to suggest that you post some recipes, but not sure that the bush meat you get in Ethiopia is going to be available in our local supermarket :grinning:

Pete.

2 Likes

:joy::smirk: α‰ αŒŽ. αˆ‹αˆ

Updated:

-AC-DC 3v step down
-MAX6675 with K type probe
-1.3” LCD

4 Likes

@mikekgr you wanted some details

image

Alright I added two physical buttons for the OLED menu. Here’s the code. My knowledge is very basic so tear it apart but, I’m warning you, you will have to explain in detail so I can learn from it. (not just Mike, everyone out there)

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <Wire.h>  // Oled
#include "SH1106Wire.h" //Oled
SH1106Wire display(0x3c, D3, D7); // D7 -> SCL // D3 -> SDA  //Oled
#include "max6675.h"

char auth[] = β€œ";
char ssid[] = "";
char pass[] = "";

#define relayPin D8                                        //Relay pin
float temp = 0;                                            //Float to handle 2 decimal temp
#define thermoDO  D4                                       
#define thermoCS  D5                                       
#define thermoCLK  D6                                      
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);       

int ReCnctFlag;                                             //Blynk reconnection flag
int ReCnctCount = 0;                                        //Blynk reconnection counts
int menuPos = 0;                                            //Menu position for OLED
int oldMenu = 0;                                            //Stores previous menu position see menu change function
int menuSelect = 0;                                         //Used to test if item is selected
bool crockpotON;                                            //On/Off status for OLED

#define selectPin D0
#define menuPin D1
bool menuState = 0;                                         //menuState to read menu pin
int selectState = 0;

int setTemp = 33;                                           //Initial setTemp
int oldsetTemp;                                             //Variable to check if settemp has changed so the display does not time out while changing settemp

bool buttonONOFFstatus = 1;                                    //Set to true so works without Blynk
//bool tempType = 1;                                        //Used to toggle C and F for some reason didn't work well with poor internet connection
bool repeatNotify;                                          //Flag to turn off repeat notifications
bool subMenu = false;                                       //keeps track of submenu status (needed for 2 button navigation)
bool menuFlag = false;                                      //used to ensure menu will only advance by 1

WidgetLCD lcd (V0);                                         //Creates a Blynk LCD
WidgetLED StatusLED (V2);                                   //Blynk LED widget
WidgetTerminal terminal1(V25);                              //Blynk terminal for debug
WidgetRTC rtc;                                              //RTC for reconnect times

//used to create runtime
long t = 0;
int secs = 29;
int mins = 0;
int hours = 0;
int days = 0;
int weeks = 0;

BlynkTimer timer;

void setup(){
  Serial.begin(9600);
  WiFi.begin(ssid,pass);
  Blynk.config(auth);
  Blynk.connect();
  pinMode(relayPin,OUTPUT);
  pinMode(selectPin, INPUT);
  pinMode(menuPin, INPUT);
  rtc.begin();
  timer.setInterval(1000L, upTime);
  delay(10);
  timer.setInterval(5000L, menuChange);
  delay(10);
  timer.setInterval(600L, displayOLED);        //Refresh Oled display everysecond
  timer.setInterval(5000L, checkTemp);
  delay(10);
  ArduinoOTA.setHostname("CrockpotOLEDv4c");
  ArduinoOTA.begin();
  timer.setInterval(200L, checkBtns);
  display.init();  
  display.flipScreenVertically();
}

BLYNK_CONNECTED(){
  //Serial.println("Connected");
  ReCnctCount = 0;
  Blynk.virtualWrite(V1, setTemp);
}

void menuChange(){
  lcd.print(15,1, menuPos);
  lcd.print(15,0, oldMenu);
  if (oldMenu == menuPos && oldsetTemp == setTemp){
    menuPos = 0;
  }

  oldMenu = menuPos;
  oldsetTemp = setTemp;
}

void loop(){
  timer.run();
  ArduinoOTA.handle();                                                //run OTA every loop

  if (Blynk.connected()){                                              //If Blynk connected run as normal
    Blynk.run();
  }
  else if (ReCnctFlag == 0){                                          //test connection flag
    ReCnctFlag = 1;                                                   //set connection flag
    timer.setTimeout(30000L,[](){                                     //Lambda "Reconnection" timer function
      ReCnctFlag = 0;
      ReCnctCount++;                                                  //count up reconnection attempts
      display.clear();
      display.setTextAlignment(TEXT_ALIGN_LEFT);
      display.setFont(ArialMT_Plain_10);
      display.drawString(0, 0, "Attempting reconnect #" + String(ReCnctCount));
      display.display();
      secs += 9;
      Blynk.connect();                                                //try to connect again
    });
  }
}

void checkBtns(){
  menuState = digitalRead(menuPin);
  selectState = digitalRead(selectPin);
  
  if(menuState == HIGH && menuFlag == false){
    menuPos ++;
    menuFlag = true;
    if (menuPos >= 4 && subMenu == false){
    menuPos = 0;
  }
  timer.setTimeout(500L,[](){                                     //Lambda "Reconnection" timer function
      menuFlag = false;                                                //try to connect again
    });
  }
  if(selectState == HIGH){
    menuSelect = 1;
  }else{
    menuSelect = 0;
  }
  
}


void displayOLED(){
  display.clear();
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.setFont(ArialMT_Plain_10);
    char upTimebuf[25];
    sprintf(upTimebuf,"Up %00d:%01d:%02d:%02d:%02d",weeks,days,hours,mins,secs);  
  display.drawString(0, 0, upTimebuf);
  display.drawString(111,0,"v4c");
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.setFont(ArialMT_Plain_16);                             //Oled
  display.drawString(0, 14, "Set: " + String(setTemp));
  display.drawString(0, 30, "Temp: " + String(temp));
  
  if (crockpotON == 0 && buttonONOFFstatus == false){
     display.setFont(ArialMT_Plain_10);                             //Oled
     display.drawString(69, 16, "'System Off '");
     }
     else if (crockpotON == 0 && buttonONOFFstatus == true){
       display.setFont(ArialMT_Plain_10);                             //Oled
       display.drawString(72, 14, "'System On'");
     }
     else if (crockpotON == 1){
        display.setFont(ArialMT_Plain_10);                             //Oled
       display.drawString(86, 14, "'Heating'");
     }
     
  switch (menuPos){
    case 0:
      display.setFont(ArialMT_Plain_10);
      display.drawString(5, 50, "*Menu Red/Select Green*");
      break;
    case 1:
      display.setFont(ArialMT_Plain_10);
      if (buttonONOFFstatus == false){
      display.drawString(15, 50, "*ON/OFF*  SYS OFF" );
      }else{
        display.drawString(15, 50, "*ON/OFF*   SYS ON" );
      }
        if (menuSelect == 1){
          buttonONOFFstatus = !buttonONOFFstatus;
          if (buttonONOFFstatus == false){
            Blynk.virtualWrite(V11,HIGH);
          }else{
            Blynk.virtualWrite(V11,LOW);
          }
        }
      break;
    case 2:
      display.setFont(ArialMT_Plain_10);
      display.drawString(25, 50, "*Raise temp*");
        if (menuSelect == 1){
          menuPos = 4;
          subMenu = true;
        }
      break; 
    case 3:
      display.setFont(ArialMT_Plain_10);
      display.drawString(25, 50, "*Lower temp*");
        if (menuSelect ==1){
          menuPos = 6;
          subMenu = true;
        }
      break;
    case 4:
      display.setFont(ArialMT_Plain_10);
      display.drawString(25, 50, "***Set +10***");
      if (menuSelect == 1){
          setTemp = (setTemp + 10); 
          Blynk.virtualWrite(V1, setTemp);
        }
      break;
    case 5:
      display.setFont(ArialMT_Plain_10);
      display.drawString(27, 50, "***Set +1***");
      subMenu = false;
      if (menuSelect == 1){
          setTemp = (setTemp + 1);
          Blynk.virtualWrite(V1, setTemp);
        }
      break;
    case 6:
      display.setFont(ArialMT_Plain_10);
      display.drawString(25, 50, "***Set -10***");
      if (menuSelect == 1){
          setTemp = (setTemp - 10);
          Blynk.virtualWrite(V1, setTemp); 
        }
      break;
    case 7:
      display.setFont(ArialMT_Plain_10);
      display.drawString(25, 50, "***Set -1***");
      subMenu = false;
      if (menuSelect == 1){
          setTemp = (setTemp - 1);
          Blynk.virtualWrite(V1, setTemp);  
        }
      break;
  }
  display.display();
  Blynk.virtualWrite(V4,upTimebuf);
}

void upTime() {

    if ((millis() - t) >= 1000) {
        secs += 1;
        t = millis();  
    }
    if (secs >= 60) {
        mins += 1;
        secs = 0;
    }
    if  (mins>= 60) { 
        hours += 1;
        mins = 0;
    }
    if (hours >= 24) { 
        days += 1;
        hours = 0;
    }
    if (days >= 7){
        weeks += 1;
        days = 0;
    }

} 

BLYNK_WRITE(V9)
    {
      if (param.asInt())
      {
        repeatNotify=false;
      }
      else{
        repeatNotify=true;
      }
    }

BLYNK_WRITE(V11)
    {
      if (param.asInt())
      {
        buttonONOFFstatus=false;
        lcd.print(0,0, "Crockpot OFF");
        lcd.print(0,1, "Crockpot OFF");
      }
      else{
        buttonONOFFstatus=true;
      }
    }
void checkTemp() {                                              //some testing with C toggle F                    
   //if (tempType == 1){ 
   temp = thermocouple.readCelsius();   
   Blynk.setProperty(V5, "offBackColor", "#ffffff");
   //}else{
   // temp = thermocouple.readFahrenheit();
   // Blynk.setProperty(V5, "onBackColor", "#ffffff");
   //}
   
   lcd.print(0,0, "T " );                       
   lcd.print(2,0, temp);
   if (temp >= 99.9){
    lcd.print(9,0,"       ");
   }else{
    lcd.print(8,0,"       ");
   }
   lcd.print(0,1, "Set ");
   lcd.print(4,1, setTemp);               //LCD's blink if lcd.clear() so print spaces instead
   if (setTemp >= 100){                   //If statement to check if extra spaces needed on display
   lcd.print(7,1, "        ");            
   }else{
    lcd.print(6,1, "        ");
   }
   Blynk.virtualWrite(V0,temp);
   Blynk.virtualWrite(V3,temp);
   if (buttonONOFFstatus == true){
    Blynk.virtualWrite(V1,setTemp);
    Blynk.virtualWrite(V7,crockpotON);
    }
   if((temp <= setTemp) && (buttonONOFFstatus == 1)){
    StatusLED.on();
    digitalWrite(relayPin,LOW);
    crockpotON = 1;
        
    //terminal1.println(buttonONOFFstatus);
    //terminal1.flush();
   }
   else if((temp <= setTemp) && (buttonONOFFstatus == 0)){
    StatusLED.off();
    digitalWrite(relayPin,HIGH);
    crockpotON = 0;
    
    //terminal1.println(buttonONOFFstatus);
    //terminal1.flush();
   }
   else{
    StatusLED.off();
    digitalWrite(relayPin,HIGH);
    crockpotON = 0;
    if(repeatNotify == true)
    {
      Blynk.notify("Temperature reached");
    }
   }         
}

BLYNK_WRITE(V1)
{
  setTemp = param.asInt();
}

BLYNK_WRITE(V15)
{
  menuSelect = param.asInt();
  
}
BLYNK_WRITE(V16)
{
  if (param.asInt()){
    menuPos ++;
    if (menuPos >= 4 && subMenu == false){
    menuPos = 0;
  }
  }
}

BLYNK_WRITE(V5){
Blynk.setProperty(V5,"onBackColor","#212226");
Blynk.setProperty(V5,"offBackColor","#212226");
}
/*
{
  if ((param.asInt()) && tempType == 0){
    tempType = param.asInt();
    setTemp = ((setTemp - 32)*5/9);
    tempType = 1;
    Blynk.virtualWrite(V1,setTemp);
    }
    
    else {
    tempType = param.asInt(); 
    setTemp = ((setTemp * 9 / 5) +32);
    tempType = 0;
    Blynk.virtualWrite(V1,setTemp);
    }
  
}
*/
3 Likes