Skip to content

Instantly share code, notes, and snippets.

@Mad182
Last active August 21, 2025 16:38
Show Gist options
  • Select an option

  • Save Mad182/a02ad037021dabc003521ce522be8688 to your computer and use it in GitHub Desktop.

Select an option

Save Mad182/a02ad037021dabc003521ce522be8688 to your computer and use it in GitHub Desktop.
// Stage durations in milliseconds
const unsigned long stageDurations[] = {
4UL * 60UL * 60UL * 1000UL, // Stage 1
6UL * 60UL * 60UL * 1000UL, // Stage 2
8UL * 60UL * 60UL * 1000UL, // Stage 3
3UL * 60UL * 60UL * 1000UL, // Stage 4
1UL * 60UL * 60UL * 1000UL, // Stage 5
4UL * 60UL * 60UL * 1000UL // Stage 6
};
// Stage target temperatures
const float stageTemps[] = {
20.0, // Stage 1
25.0, // Stage 2
30.0, // Stage 3
40.0, // Stage 4
50.0, // Stage 5
60.0 // Stage 6
};
// -------------------- Includes --------------------
#include "LiquidCrystal.h"
#include "OneWire.h"
#include "DallasTemperature.h"
// -------------------- LCD Setup --------------------
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// -------------------- Temperature Sensors --------------------
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// -------------------- Heater Relay Pins --------------------
#define HEATER_PIN_1 8
#define HEATER_PIN_2 9
// -------------------- Timing --------------------
unsigned long startTime;
unsigned long lastLcdInit = 0;
const int numStages = sizeof(stageDurations) / sizeof(stageDurations[0]);
// -------------------- Global Variables --------------------
float targetTemp = 0.0;
bool finished = false;
// -------------------- Setup --------------------
void setup() {
lcd.begin(16, 2);
sensors.begin();
pinMode(HEATER_PIN_1, OUTPUT);
pinMode(HEATER_PIN_2, OUTPUT);
digitalWrite(HEATER_PIN_1, HIGH); // OFF at start
digitalWrite(HEATER_PIN_2, HIGH);
startTime = millis();
lastLcdInit = millis(); // initialize tracking
}
// -------------------- Loop --------------------
void loop() {
unsigned long elapsed = millis() - startTime;
// Re-init LCD every 3 minutes
if (millis() - lastLcdInit >= 180000UL) { // 3 minutes
lcd.begin(16, 2);
lastLcdInit = millis();
}
// Determine current stage
unsigned long accumulated = 0;
int currentStage = -1;
for (int i = 0; i < numStages; i++) {
accumulated += stageDurations[i];
if (elapsed < accumulated) {
currentStage = i;
break;
}
}
if (currentStage != -1) {
targetTemp = stageTemps[currentStage];
finished = false;
} else {
// All stages complete - stop heating
targetTemp = 0.0;
finished = true;
digitalWrite(HEATER_PIN_1, HIGH);
digitalWrite(HEATER_PIN_2, HIGH);
}
// Read temperatures
sensors.requestTemperatures();
float temp1 = sensors.getTempCByIndex(0);
float temp2 = sensors.getTempCByIndex(1);
// Control heaters independently
controlHeater(HEATER_PIN_1, temp1);
controlHeater(HEATER_PIN_2, temp2);
// Display temperatures
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("T1:");
lcd.print(temp1, 1);
lcd.print(" T2:");
lcd.print(temp2, 1);
// Second line: either show MT:XXC or "Gatavs"
lcd.setCursor(0, 1);
if (!finished) {
lcd.print("MT:");
lcd.print(targetTemp, 0);
lcd.print("C ");
} else {
lcd.print("Gatavs! "); // pad a bit so old text doesn't stay
}
// Elapsed time in HH:MM:SS
unsigned long elapsedSeconds = elapsed / 1000UL;
unsigned int hours = elapsedSeconds / 3600UL;
unsigned int minutes = (elapsedSeconds % 3600UL) / 60UL;
unsigned int seconds = elapsedSeconds % 60UL;
if (hours < 10) lcd.print("0");
lcd.print(hours);
lcd.print(":");
if (minutes < 10) lcd.print("0");
lcd.print(minutes);
lcd.print(":");
if (seconds < 10) lcd.print("0");
lcd.print(seconds);
delay(250); // Update
}
// -------------------- Heater Control Function --------------------
void controlHeater(int heaterPin, float currentTemp) {
if (targetTemp > 0) { // Only if in heating phase
if (currentTemp < targetTemp - 0.5) {
digitalWrite(heaterPin, LOW); // Turn heater ON (active LOW)
} else if (currentTemp > targetTemp + 0.5) {
digitalWrite(heaterPin, HIGH); // Turn heater OFF
}
} else {
digitalWrite(heaterPin, HIGH); // Force OFF when not heating
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment