Need assistance with my Code

Hello everyone!

I have already received some help on this to get things up and running, but now I need to clean this mess up! Also the last bit doesn't work as I want it to.

I will first explain what this code is supposed to do:

Setup():

  • User is asked to select (with poti) the amount of required "steps"
  • User pushes button
  • The selected amount of "steps" is saved to a variable
  • Depending on the amount of "steps" the user is asked to enter the Temperatures for these "steps"
  • They will get stored into an array
  • Next the user is asked to enter the Time for these "steps"
  • They will get stored into a different array

Loop():

We now have all the required information. Once the button is pushed the main programm will start.

Now here comes the tricky part. I have connected a DS18B20 Digital temperature sensor to monitor the temperature at all times.

  • Let´s say the temperature for "step" 1 is supposed to be 30°C but the actual temperature is 28°C...
    The container will be externally heated until it reaches the "step" 1 temperature.
  • As soon as this temperature is reached, a timer has to be started with the time that was supplied in the setup().
  • Once the time has run out, the index will be increased and we switch to the next "step".
  • Here we repeat as before, we heat up until desired temperature has been met and then start a new timer.

Also, if the timer has been started and the actual temperature drops BELOW the desired temperature, we only want to start heating again, the timer should remain running!

Currently my code is really really messy and I would be thankful if someone could take a look at it. Especially the setup() could need a little cleaning. I would like to somehow combine the 3 while loops if possible at all.

The timers still aren't working, could someone also help me on that one?

Thank you so much!

Code:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>                                                              
#include <LiquidCrystal_I2C.h> 

#define ONE_WIRE_BUS 3
#define arraySize 5
#define potPin 0
#define buttonPin 2

int Rs_pin = 0;                                                                 
int Rw_pin = 1;
int En_pin = 2;
int Bl_pin = 3;
int D4_pin = 4;
int D5_pin = 5;
int D6_pin = 6;
int D7_pin = 7;
int I2C_ADDR = 0x27;

int bootTime = 0;
int buttonState = 0;
int lastButtonState = 0;
int index = 0; 
int amountSteps = 0;

long previousMillis = 0;

int startCountdown = false;
int stepTemperature[arraySize];
int stepTime[arraySize];

boolean menu = true;
boolean startStep = false;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin, 
                      Rs_pin,D4_pin,D5_pin,
                      D6_pin,D7_pin,Bl_pin,POSITIVE);                      

DeviceAddress insideThermometer = { 0x28, 0x4A, 0x8D, 0x60, 0x05, 0x00, 0x00, 0x26 };

void setup(void) {  
  Serial.begin(115200);   

  sensors.begin();  
  sensors.setResolution(insideThermometer, 12); 

  lcd.begin(16,2);  

  pinMode(buttonPin, INPUT);     
  
  while(menu) {
    buttonState = digitalRead(buttonPin);
    
    lcd.setCursor(0, 0);
    lcd.print("Amount Steps?");
    lcd.setCursor(14, 1);
    lcd.print(map(analogRead(potPin), 0, 1000, 5, 1));
    if (buttonState != lastButtonState) {      
      if (buttonState == 1) {        
        amountSteps = map(analogRead(potPin), 0, 1000, 5, 1);
        menu = false;   
        lcd.clear();     
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);        
  } 
  lcd.clear();  
  
  index = 0;
  
  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin); 
    
    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step"); 
    lcd.setCursor(8, 0);
    lcd.print((char)223);
    lcd.setCursor(9, 0);
    lcd.print("C ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1023, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1023, 90, 0));    
    
    if (buttonState != lastButtonState) {      
      if (buttonState == 1) {        
        stepTemperature[index] = map(analogRead(potPin), 0, 1023, 90, 0);        
        index++;        
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }
  lcd.clear();  
  
  index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin);  
    
    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step");     
    lcd.setCursor(8, 0);
    lcd.print("Min ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1023, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1023, 90, 0));  
    
    if (buttonState != lastButtonState) {      
      if (buttonState == 1) {        
        stepTime[index] = map(analogRead(potPin), 0, 1023, 90, 0);        
        index++;
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }   
  lcd.clear();   
}

void loop(void) {      
  buttonState = digitalRead(buttonPin);
  
  getTemperature(true);  
  
  if (buttonState != lastButtonState) {      
    if (buttonState == 1) {        
      startStep = true;
      lcd.clear();
    }  
    lastButtonState = buttonState;      
  }    
  delay(20);    
  
  index = 0;  
  
  if (startStep) {         
    while (index < amountSteps) { 
      unsigned long currentMillis = millis(); 
      
      getTemperature(true);
      
      Serial.print("Step ");
      Serial.print(index + 1);
      Serial.println(" active!");
      
      if (getTemperature(false) < stepTemperature[index]) {
        Serial.println("Temperature has not been reached!");                
      } else {
        Serial.println("Temperature reached!");
        bootTime = millis();
        startCountdown = true;        
      }
      
      Serial.println(currentMillis);
      Serial.println(previousMillis);
      
      if(startCountdown && (currentMillis - previousMillis > ((500 * 10) + bootTime))) {
        previousMillis = currentMillis; 
        startCountdown = false;  
        bootTime = 0;      
        index++;         
      }            
    }    
    startStep = false;
  }
}

float getTemperature(bool printTemperature) {   
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures(); 
  sensors.setWaitForConversion(true);

  float tempC = sensors.getTempC(insideThermometer);

  if (printTemperature) {
    lcd.setCursor(0, 0); 
    lcd.print("Temp C:"); 
    lcd.setCursor(8, 0);
    lcd.print(tempC);        
  }  

  return tempC;  
}

Yes there is still something wrong with it...

The problem is that millis() points to the time SINCE arduino start. So I added the bootTime variable which is supposed to take the current millis() to the point where the while loop is executed.

But yes...you are right this isn't working yet...

I just need something that tells the condition to take the start time right before the while loop.

Right that would be it. Any advice on how this could be achieved? Also, how is the rest of the code? Any way to optimize and clean it up?

startCountdown would be the boolean to check wether the step is active or not. But where should I declare theStartingTime?

Side note: I didn't use the time saved in the array yet because I was just testing the whole thing.

Maybe the code in several things at a time will help to show how to use millis()

You need to record the time when an event starts (for example when you put the chicken in the oven) and then keep checking if the difference between the latest time (as in millis() ) and the start time equals or exceeds the interval (cooking time).

...R

I adjusted the code.

If the temperature is below the desired temperature it will do nothing. As soon as I bring up the temperature it will immediatly increase the index...Which makes no sense as it should be waiting for the desired interval...

Here the updated code:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>                                                              
#include <LiquidCrystal_I2C.h> 

#define ONE_WIRE_BUS 3
#define arraySize 5
#define potPin 0
#define buttonPin 2

int Rs_pin = 0;                                                                 
int Rw_pin = 1;
int En_pin = 2;
int Bl_pin = 3;
int D4_pin = 4;
int D5_pin = 5;
int D6_pin = 6;
int D7_pin = 7;
int I2C_ADDR = 0x27;

int buttonState = 0;
int lastButtonState = 0;
int index = 0; 
int amountSteps = 0;

unsigned long previousMillis = 0;
unsigned long theStartTime = 0;

boolean menu = true;
boolean startStep = false;
boolean startCountdown = false;

int stepTemperature[arraySize];
int stepTime[arraySize];

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin, 
Rs_pin,D4_pin,D5_pin,
D6_pin,D7_pin,Bl_pin,POSITIVE);                      

DeviceAddress insideThermometer = { 
  0x28, 0x4A, 0x8D, 0x60, 0x05, 0x00, 0x00, 0x26 };

void setup(void) {  
  Serial.begin(115200);   

  sensors.begin();  
  sensors.setResolution(insideThermometer, 12); 

  lcd.begin(16,2);  

  pinMode(buttonPin, INPUT);     

  while(menu) {
    buttonState = digitalRead(buttonPin);

    lcd.setCursor(0, 0);
    lcd.print("Amount Steps?");
    lcd.setCursor(14, 1);
    lcd.print(map(analogRead(potPin), 0, 1000, 5, 1));
    if (buttonState != lastButtonState) {      
      if (buttonState == 1) {        
        amountSteps = map(analogRead(potPin), 0, 1000, 5, 1);
        menu = false;   
        lcd.clear();     
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);        
  } 
  lcd.clear();  

  index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin); 

    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step"); 
    lcd.setCursor(8, 0);
    lcd.print((char)223);
    lcd.setCursor(9, 0);
    lcd.print("C ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1023, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1023, 90, 0));    

    if (buttonState != lastButtonState) {      
      if (buttonState == 1) {        
        stepTemperature[index] = map(analogRead(potPin), 0, 1023, 90, 0);        
        index++;        
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }
  lcd.clear();  

  index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin);  

    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step");     
    lcd.setCursor(8, 0);
    lcd.print("Min ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1023, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1023, 90, 0));  

    if (buttonState != lastButtonState) {      
      if (buttonState == 1) {        
        stepTime[index] = map(analogRead(potPin), 0, 1023, 90, 0);        
        index++;
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }   
  lcd.clear();   
}

void loop(void) {      
  buttonState = digitalRead(buttonPin);

  getTemperature(true);  

  if (buttonState != lastButtonState) {      
    if (buttonState == 1) {        
      startStep = true;
      lcd.clear();
    }  
    lastButtonState = buttonState;      
  }    
  delay(20);    

  index = 0;  

  if (startStep) {       
    while (index < amountSteps) { 
      unsigned long currentMillis = millis(); 

      getTemperature(true);

      Serial.print("Step ");
      Serial.print(index + 1);
      Serial.println(" active!");

      if (getTemperature(false) < stepTemperature[index]) {
        Serial.println("Temperature has not been reached!");                
      } 
      else {
        Serial.println("Temperature reached!");
        if(!startCountdown) {
          theStartTime = millis();
        }
        startCountdown = true;        
      }

      Serial.println(startCountdown);
      Serial.println(theStartTime);      
      Serial.println(currentMillis);
      Serial.println(previousMillis);

      if(startCountdown && ((currentMillis - theStartTime) > (5000 * 10))) { // Using this interval for testing!
        previousMillis = currentMillis;  // do I still need previousMillis ???
        startCountdown = false;      
        index++;         
      }        
    }    
    startStep = false; 
  } 
}

float getTemperature(bool printTemperature) {   
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures(); 
  sensors.setWaitForConversion(true);

  float tempC = sensors.getTempC(insideThermometer);

  if (printTemperature) {
    lcd.setCursor(0, 0); 
    lcd.print("Temp C:"); 
    lcd.setCursor(8, 0);
    lcd.print(tempC);        
  }  

  return tempC;  
}

And here some debugging output:

shortly before the temperature is reached.

Step 1 active!
Temperature has not been reached!
0
0
72225

as soon as the temperature is reached:

Step 1 active!
Temperature has not been reached!
0
0
72225
0

and this is the output directly after the previous one, without any interval

Step 2 active!
Temperature has not been reached!
0
72315
72316
72270

For some reason...that still won`t do it...

Step 1 active!
Temperature reached!
Current time: 40034
Start time: 40079
Needed time: 50000
Countdown started
Time is up!
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>                                                              
#include <LiquidCrystal_I2C.h> 

#define one_wire 3
#define arraySize 5
#define potPin 0
#define buttonPin 2

int Rs_pin = 0;                                                                 
int Rw_pin = 1;
int En_pin = 2;
int Bl_pin = 3;
int D4_pin = 4;
int D5_pin = 5;
int D6_pin = 6;
int D7_pin = 7;
int I2C_ADDR = 0x27;

int buttonState = 0;
int lastButtonState = 0;
int index = 0; 
int amountSteps = 0;

unsigned long previousMillis = 0;
unsigned long theStartTime = 0;

boolean menu = true;
boolean startStep = false;
boolean startCountdown = false;

int stepTemperature[arraySize];
int stepTime[arraySize];

OneWire oneWire(one_wire);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin, 
Rs_pin,D4_pin,D5_pin,
D6_pin,D7_pin,Bl_pin,POSITIVE);                      

DeviceAddress sensor = { 
  0x28, 0x4A, 0x8D, 0x60, 0x05, 0x00, 0x00, 0x26 };

void setup(void) {  
  Serial.begin(115200);   

  sensors.begin();  
  sensors.setResolution(sensor, 12); 

  lcd.begin(16,2);  

  pinMode(buttonPin, INPUT);     

  while(menu) {
    buttonState = digitalRead(buttonPin);

    lcd.setCursor(0, 0);
    lcd.print("Amount Steps?");
    lcd.setCursor(14, 1);
    lcd.print(map(analogRead(potPin), 0, 1000, 5, 1));
    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {        
        amountSteps = map(analogRead(potPin), 0, 1000, 5, 1);
        menu = false;   
        lcd.clear();     
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);        
  } 
  lcd.clear();  

  index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin); 

    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step"); 
    lcd.setCursor(8, 0);
    lcd.print((char)223);
    lcd.setCursor(9, 0);
    lcd.print("C ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1023, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1023, 90, 0));    

    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {        
        stepTemperature[index] = map(analogRead(potPin), 0, 1023, 90, 0);        
        index++;        
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }
  lcd.clear();  

  index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin);  

    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step");     
    lcd.setCursor(8, 0);
    lcd.print("Min ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1023, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1023, 90, 0));  

    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {        
        stepTime[index] = map(analogRead(potPin), 0, 1023, 90, 0);        
        index++;
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }   
  lcd.clear();   
}

void loop(void) {      
  buttonState = digitalRead(buttonPin);

  getTemperature(true);  

  if (buttonState != lastButtonState) {      
    if (buttonState == HIGH) {        
      startStep = true;
      lcd.clear();
    }  
    lastButtonState = buttonState;      
  }    
  delay(20);    

  index = 0;  

  if (startStep) {       
    while (index < amountSteps) { 
      unsigned long currentMillis = millis(); 

      getTemperature(true);

      Serial.print("Step ");
      Serial.print(index + 1);
      Serial.println(" active!");

      if (getTemperature(false) < stepTemperature[index]) {
        Serial.println("Temperature has not been reached!");                
      } 
      else {
        Serial.println("Temperature reached!");
        if(!startCountdown) {
          theStartTime = millis();
        }
        startCountdown = true;        
      }
      
      Serial.print("Current time: ");
      Serial.println(currentMillis);
       
      Serial.print("Start time: ");
      Serial.println(theStartTime);  
      
      Serial.print("Needed time: ");
      Serial.println(5000UL * 10);

      if(startCountdown) {
        Serial.println("Countdown started");
        
        if ((currentMillis - theStartTime) > (5000UL * 10)) {
          Serial.println("Time is up!");
          previousMillis = currentMillis;  // do I still need previousMillis ???
          startCountdown = false;      
          index++;         
        }
      }     
      delay(250);       
    }    
    startStep = false; 
  } 
}

float getTemperature(bool printTemperature) {   
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures(); 
  sensors.setWaitForConversion(true);

  float tempC = sensors.getTempC(sensor);

  if (printTemperature) {
    lcd.setCursor(0, 0); 
    lcd.print("Temp C:"); 
    lcd.setCursor(8, 0);
    lcd.print(tempC);        
  }  

  return tempC;  
}

Could it be that

Current time: 40034
Start time: 40079

is causing an overflow?

currentMillis - theStartTime
40034 - 40079 = negative?

Yep! that was it, it works now!

Any suggestions for making the code more efficient? Especially the setup?

Thank you so much btw!

Ok! I have revised my code a bit.

Anybody care to have a look and maybe help me with making it clearer and easier to work with?

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>                                                              
#include <LiquidCrystal_I2C.h> 

// Constant variables
#define one_wire 3
#define maxSteps 5
#define potPin 0
#define buttonPin 2

// Non-constant variables
byte Rs_pin = 0;                                                                 
byte Rw_pin = 1;
byte En_pin = 2;
byte Bl_pin = 3;
byte D4_pin = 4;
byte D5_pin = 5;
byte D6_pin = 6;
byte D7_pin = 7;
byte I2C_ADDR = 0x27;

byte amountSteps = 0;
byte buttonState = 0;
byte lastButtonState = 0;

unsigned long theStartTime = 0;

boolean startCountdown = false;

byte stepTemperature[maxSteps];
byte stepTime[maxSteps];

OneWire oneWire(one_wire);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin, 
                      Rs_pin,D4_pin,D5_pin,
                      D6_pin,D7_pin,Bl_pin,POSITIVE);                      

DeviceAddress sensor = { 0x28, 0x4A, 0x8D, 0x60, 0x05, 0x00, 0x00, 0x26 };

void setup(void) {  
  Serial.begin(115200);   

  sensors.begin();  
  sensors.setResolution(sensor, 12); 

  lcd.begin(16,2);  

  pinMode(buttonPin, INPUT);    

  getSteps(true);
  getTemps(); 
  getTimes();

  lcd.clear(); 

  waitForButton(true); 
}

void loop(void) {  
 // Empty! The program only needs one cycle!
}

// Configure the amount of steps
void getSteps(boolean enabled) {
  while(enabled) {
    buttonState = digitalRead(buttonPin);

    lcd.setCursor(0, 0);
    lcd.print("Amount Steps?");
    lcd.setCursor(14, 1);
    lcd.print(map(analogRead(potPin), 0, 1000, maxSteps, 1));
    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {        
        amountSteps = map(analogRead(potPin), 0, 1000, maxSteps, 1);
        enabled = false;   
        lcd.clear();     
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);        
  }    
}

// Configure the temperatures for each step
void getTemps() {
  byte index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin); 

    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step"); 
    lcd.setCursor(8, 0);
    lcd.print((char)223);
    lcd.setCursor(9, 0);
    lcd.print("C ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1022, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1022, 90, 0));    

    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {        
        stepTemperature[index] = map(analogRead(potPin), 0, 1022, 90, 0);        
        index++;        
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }  
}

// Configure the times for each step
void getTimes() {
  byte index = 0;

  while(index < amountSteps) { 
    buttonState = digitalRead(buttonPin);  

    lcd.setCursor(0, 0);
    lcd.print(index + 1);
    lcd.setCursor(1, 0);
    lcd.print(". Step");     
    lcd.setCursor(8, 0);
    lcd.print("Min ="); 
    lcd.setCursor(14, 0);    
    if (map(analogRead(potPin), 0, 1022, 90, 0) < 10) {
      lcd.print(" ");
    } 
    lcd.print(map(analogRead(potPin), 0, 1022, 90, 0));  

    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {        
        stepTime[index] = map(analogRead(potPin), 0, 1022, 90, 0);        
        index++;
      }  
      lastButtonState = buttonState;      
    }    
    delay(20);
  }   
}

// Wait for button to start the process
void waitForButton(boolean enabled) {
  while (enabled) {
    buttonState = digitalRead(buttonPin);

    lcd.setCursor(1, 0);
    lcd.print("Press a Button");
    lcd.setCursor(4, 1);
    lcd.print("to start");

    if (buttonState != lastButtonState) {      
      if (buttonState == HIGH) {  
        lcd.clear();        
        startSteps();
        enabled = false;    
      }  
      lastButtonState = buttonState;      
    }    
    delay(20); 
  }  
}

// Start the process
void startSteps() {
  byte index = 0;  

  while (index < amountSteps) { 
    unsigned long currentMillis = millis();

    getTemperature(true);

    if (getTemperature(false) < stepTemperature[index]) {     
      Serial.println("Temperature has not been reached!"); 
      digitalWrite(12, HIGH);   // some pin for now. Not supposed to work right now.  
    } 
    else {
      Serial.println("Temperature reached!");
      digitalWrite(12, LOW);   // some pin for now. Not supposed to work right now.
      if(!startCountdown) {
        theStartTime = currentMillis;
      }
      startCountdown = true;        
    }

    if(startCountdown) {      
      Serial.println("Countdown started");

      if (currentMillis - theStartTime > stepTime[index] * 60000UL) {
        Serial.println("Time is up! Switching to the next step!");          
        startCountdown = false;      
        index++;         
      }
    }             
  }  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("done!");
}

float getTemperature(bool printTemperature) {   
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures(); 
  sensors.setWaitForConversion(true);

  float tempC = sensors.getTempC(sensor);

  if (printTemperature) {
    lcd.setCursor(0, 0); 
    lcd.print("Temp C:"); 
    lcd.setCursor(8, 0);
    lcd.print(tempC);        
  }  

  return tempC;  
}

Some suggestions
If the function is always used with a parameter set to one value (getStep(true)) the parameter MAY be redundant.( No big deal) .
When you use #define it implies a constant, so the additional comment is not necessary.
Of course calling pin numbers not constant is incorrect.( But we all leave artifacts like that in heat of the battle coding the "main stuff")

You did a good job commenting the code, however some of the comments just repeat the code.

For example:

if( A and B) // if A and B are true
does not say what the code does

this does
if( A and B) // check if the switch is on and temperature is over 100

You put comments in code for yourself , not for benefits of the audience.( Maybe your boss! ).
And as your code gets more involved it helps to keep track what it suppose to do.
You did an exceptional job describing what your code should do in your OP.
You are on right track.
Good luck

Thank you buddy!

I think I will leave the code as is for now...It works as expected and I can't find a way to achieve the same with a more compact code.

Thanks for the suggestions!