Hi, I am new to the forum and pretty new to arduino as well.
I have spent a few days researching the forum and google to solve the issue I am having, but I haven’t been able to figure out a solution.
I am working on some rough ideas for a project and I am trying to get the general concept down before I move onto some more complicated aspects.
I would like to monitor a thermocouple and print the value if the previous temperature was greater than 30 degrees and the current temperature is less than or equal to 30 degrees.
I have tried this a few different ways, but to no avail.
The first method I tried was to use a boolean that became true if the temperature dropped below 30 degrees.
I tried to create logic that would print the temperature value if the boolean flag was previously false, and was now true.
I think the part that I am having problems with is establishing a way to store the previous value.
The code that I am posting now was written after I referenced another thread in the forum where someone was trying to store pressure values.
I can easily get the temperature value to print if it drops below a threshold, but when I introduce the logic to reference the previous value it does not work.
Any help would be greatly appreciated.
#include <Adafruit_MAX31856.h>
// Use software SPI: CS, DI, DO, CLK
// Defines pins as D10, D11, D12, D13
Adafruit_MAX31856 max = Adafruit_MAX31856(10, 11, 12, 13);
void setup()
{
Serial.begin(115200);
max.begin(); //Initializes sensor
max.setThermocoupleType(MAX31856_TCTYPE_K);// Sets as a K Type Thermocouple
max.readThermocoupleTemperature();
}
void loop()
{
float temp = max.readThermocoupleTemperature();
float current_temp = temp;
float prev_temp = current_temp;
if((current_temp<= 30)&&(prev_temp>30))
{
Serial.print("Oil Temp: ");
Serial.println(max.readThermocoupleTemperature());
}
else {
}
// If Oil Temp is not less than 30 degrees check for Thermocouple faults
uint8_t fault = max.readFault();
{
if((fault & MAX31856_FAULT_TCRANGE) ||(fault & MAX31856_FAULT_TCHIGH)||(fault & MAX31856_FAULT_TCLOW)||(fault & MAX31856_FAULT_OPEN))
if(fault=true) // If any of the above fault conditions are present fault = true
{
Serial.println("Thermocouple Fault Detected"); // if fault = true display "Thermocouple Fault Detected" on Serial Monitor
// If fault is present print fault type in display
}
else{}
delay(500); // else if no fault is present do nothing and wait for pre-determined amount of time
}
}