hi guys, i need a bit of help please, i have a thermocuple temp sensor in my pressure cooker and i am trying to control it with a timer what i need is for it to start the timer when it gets to 121 deg and to run for 3 houto run for 3 hours and shut off i have got the control to keep the cooker at 121 deg but can not figure out how to start the timer when it reaches 121 and shut itself down after 3 hours
#include <max6675.h>
#include "CountDown.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define COOKER 10
#define ON false
#define OFF true
CountDown CD;
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
// make a cute degree symbol
uint8_t degree[8] = {140, 146, 146, 140, 128, 128, 128, 128};
void setup() {
Serial.begin(9600);
Serial.println(__FILE__);
Serial.print("COUNTDOWN_LIB_VERSION: ");
Serial.println(COUNTDOWN_LIB_VERSION);
CD.start(0, 3, 0, 0);
pinMode(COOKER, OUTPUT);
void pauseCD();
lcd.begin(16, 2);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.createChar(0, degree);
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
delay (500);
static uint32_t last_remaining = 0;
if (last_remaining != CD.remaining() || CD.remaining() == 0 )
{
Serial.println();
last_remaining = CD.remaining();
}
Serial.print('\t');
Serial.print(CD.remaining());
delay(250);
lcd.setCursor(0, 0);
lcd.print ("COOKER");
lcd.setCursor(7, 0);
lcd.print( thermocouple.readCelsius(), 2);
lcd.setCursor(15, 0);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("TIME");
lcd.setCursor(6,1 );
lcd.print( CD.remaining());
if(thermocouple.readCelsius()> 121.00)
{
digitalWrite(COOKER, HIGH);}
else
{
digitalWrite(COOKER, LOW);
}
delay (1000);
}
thanks for the advice, i did look into it and tried it like this i know i making a novice mistake, it compiles and loads to the board but the cooker control works but not the timer control
#include <millisDelay.h>
#include <max6675.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define COOKER 10
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
#define ON false
#define OFF true
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
millisDelay COOKERDelay;
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
// make a cute degree symbol
uint8_t degree[8] = {140, 146, 146, 140, 128, 128,};
void setup() {
pinMode(COOKER, OUTPUT);
lcd.begin(16, 2);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.createChar(0, degree);
lcd.begin(16, 2);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.createChar(0, degree);
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
if (thermocouple.readCelsius() > 109.00)
{ COOKERDelay.start(10000);
}
if (COOKERDelay.justFinished()){
digitalWrite(COOKER, OFF);}
// wait for MAX chip to stabilize
delay(500); lcd.setCursor(0, 0);
lcd.print ("COOKER");
lcd.setCursor(7, 0);
lcd.print( thermocouple.readCelsius(), 2);
lcd.setCursor(15, 0);
lcd.print("C");
if (thermocouple.readCelsius() > 121.00)
{
digitalWrite(COOKER, OFF);
}
else
{
digitalWrite(COOKER, ON);
}
delay (1000);
}
if (thermocouple.readCelsius() > 109.00)
{
COOKERDelay.start(10000);
}
I have no idea how that mysterious millisDelay library work, but it looks from the snippet above that all the time that the temperature is above 109.00 the timer may restart on every iteration of loop()
You almost certainly need to detect when the temperature becomes greater than 109.00 rather than when it is greater than 109.00
Take a look at the StateChangeDetection example in the IDE
thanks for the advice i am however unable to figure out how to do this but i will keep trying
is there any way to run the call to start the timer only once in the loop once the variable of 109 deg has been met
Mushroom_man:
is there any way to run the call to start the timer only once in the loop once the variable of 109 deg has been met
Yes, of course
Control the call to start the timer with a boolean, let's name it okToTime, and only allow the call if okToTime is true. Set it to false when timing starts and false when timing ends
You could, of course, use boring old millis() timing in your sketch so that you can see and control what is really going on instead of it being hidden in a library, but that is your choice.
Using a library to allow for several named timers to be created may be an advantage if you have lots of independently timed events but in your case you don't
OK so I am quite new to using boolean so I put I boolean okToTime = false in the code above the setup and from there I am not sure how do I call it to start in the loop
UKHeliBob:
Yes, of course
Control the call to start the timer with a boolean, let's name it okToTime, and only allow the call if okToTime is true. Set it to false when timing starts and false when timing ends
You could, of course, use boring old millis() timing in your sketch so that you can see and control what is really going on instead of it being hidden in a library, but that is your choice.
Using a library to allow for several named timers to be created may be an advantage if you have lots of independently timed events but in your case you don't
UKHeliBob:
Yes, of course
Control the call to start the timer with a boolean, let's name it okToTime, and only allow the call if okToTime is true. Set it to false when timing starts and false when timing ends
You could, of course, use boring old millis() timing in your sketch so that you can see and control what is really going on instead of it being hidden in a library, but that is your choice.
Using a library to allow for several named timers to be created may be an advantage if you have lots of independently timed events but in your case you don't
how would you make a statement so it knows when it is true
Mushroom_man:
OK so I am quite new to using boolean so I put I boolean okToTime = false in the code above the setup and from there I am not sure how do I call it to start in the loop
Booleans are just like any other variable except that they can only have one of two values, true or false
Declare the boolean as a global as you have but set its value to true then in loop()
void loop() {
if (thermocouple.readCelsius() > 109.00 && okToTime == true) //prevent restart of timing
{
COOKERDelay.start(10000);
okToTime = false; //prevent triggering again until timing period has elapsed
}
if (COOKERDelay.justFinished())
{
digitalWrite(COOKER, OFF);
okToTime = true; //allow timing to start again if temperature above trigger level
}
UKHeliBob:
Booleans are just like any other variable except that they can only have one of two values, true or false
Declare the boolean as a global as you have but set its value to true then in loop()
void loop() {
if (thermocouple.readCelsius() > 109.00 && okToTime == true) //prevent restart of timing
{
COOKERDelay.start(10000);
okToTime = false; //prevent triggering again until timing period has elapsed
}
if (COOKERDelay.justFinished())
{
digitalWrite(COOKER, OFF);
okToTime = true; //allow timing to start again if temperature above trigger level
}
you are a super star thank you
UKHeliBob:
Did it work OK ?
hi no i could not get it to work
here is my current code
#include <millisDelay.h>
#include <max6675.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define COOKER 10
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
const unsigned long DELAY_TIME = 10000;
boolean okToTime = false;
#define ON false
#define OFF true
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
millisDelay COOKERDelay;
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
void setup() {
pinMode(COOKER, OUTPUT);
lcd.begin(16, 2);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.setCursor(0, 0);
lcd.print ("COOKER");
lcd.setCursor(0, 1);
lcd.print("TIME");
delay(500);
}
void loop() {
lcd.setCursor(7, 0);
lcd.print( thermocouple.readCelsius(), 2);
lcd.setCursor(15, 0);
lcd.print("C");
lcd.setCursor(6, 1);
lcd.print(COOKERDelay.remaining(), 8);
if (thermocouple.readCelsius() > 25.00 && okToTime == true) //prevent restart of timing
{
COOKERDelay.start(DELAY_TIME);
okToTime = false; //prevent triggering again until timing period has elapsed
}
if (COOKERDelay.justFinished())
{
digitalWrite(COOKER, OFF);
okToTime = true; //allow timing to start again if temperature above trigger level
}
delay (1000);
I suggested
Declare the boolean as a global as you have but set its value to true
You did
boolean okToTime = false;
lcd.print(COOKERDelay.remaining(), 8);
if (thermocouple.readCelsius() > 25.00 && okToTime == true) //prevent restart of timing
{
COOKERDelay.start(DELAY_TIME);
okToTime = false; //prevent triggering again until timing period has elapsed
}
Will the timer ever start do you think ?
Lol such a rookie mistake thank you I changed it to true and it's working I don't know how I missed it but yay thanks
UKHeliBob:
Did it work OK ?
thank you for all your help and patience, I am starting to understand arduino a lot better now