Monitoring for stall in temperature rise while heating

I am currently using an Arduino NANO v3.0 to monitor temperatures in increments of 0.25 deg C with a Type K thermocouple. That is working well. I need to identify a 0.5 deg C stall in the temperature rise that lasts for 0.5 seconds or longer. Our current data input rate is 18 temperature samples per second. I am looking for 8 consecutive samples all within 0.5 seconds. I then want to freeze my 4 digit-7 segment display and activate a relay.

By example with temperatures Degree C:
70.00,70.50,71.25,71.25,71.50,71.25,71.50,71.50,71.25,71.50,72.00,72.50,72.75,73.25,74.00 74.75

After weeks of research, attempting to write a program ourselves, we still cannot locate or create a software program that will perform these two tasks. We can input and display the actual temperature easily. We, however, cannot use the input data to identify the temperature stall.

Is this possible on an Arduino NANO v3.0? Can you reference a source we can use to develop this program?

Yes, of course that is possible, with any Arduino.

Please post your best programming attempt (using code tags), explain what your program is supposed to do, and describe what went wrong, with real data examples.

Please read and follow the instructions in the "How to use this forum" post, at the head of every forum topic.

Here is my first idea to approach the problem. You will need a state variable and perhaps a sample counter. (See Arduino State Machine example).

  1. Start a timer, set state to "not stalled"
  2. Get a data point
  3. Check for stall condition
  4. If not stalled, reset timer, set state variable to "not stalled", back to 2.
  5. If stall condition met and state is "stall", calculate elapsed time since timer start
  6. If state is "stall" and 0.5 seconds has elapsed, take stall actions
  7. if 0.5 seconds has not passed, set state to "stall", back to 2.

This is the current code that is in the Arduino right now.

#include <SPI.h>
#include <Wire.h>
#include "Adafruit_MAX31855.h"
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
#define MAXDO 3
#define MAXCS 4
#define MAXCLK 5
int counter = 0;
int currentState = 0;
int previousState = 0;
int ledPin = 11;
int noledPin = 10;
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);
Adafruit_7segment matrix = Adafruit_7segment();
void setup() {
#ifndef _AVR_ATtiny85_
pinMode(ledPin, OUTPUT);
void loop() {
double c = thermocouple.readCelsius();
previousState = c;
c = round(c * 100.0) / 100.0;
currentState = c;

if(currentState == previousState){
counter = counter + 1;
} else{
counter = 0;
digitalWrite(noledPin, HIGH); // this is tempeorary
delay(10); // this is tempeorary
digitalWrite(noledPin, LOW); // this is tempeorary
if(counter == 8) {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
counter = 0;


Currently the ledPin light is blinking every time the counter reaches 8, but the temperature is never stable.

Edit: added code tags

This is odd:

  double c = thermocouple.readCelsius();
  previousState = c;

You have set previousState to c. However, later, you check to see if they are the same.

I assume that you intended to do this after the comparison, not before.

If you intend to allow +/- 0.25 degree changes in the "stalled" state, as your example suggests, then the temperature cannot be the state variable.

Your code must take that variation into account with a separate state variable.

Please use code tags when posting code.