I have recently built a temperature controller unit for a fermentation bucket using a DS18B20 temperature sensor, a heater pad and an Arduino Uno. I have based this around a project I found (https://www.instructables.com/Multiple-Fermenter-Temperature-Control-With-Arduin/), however, unlike that project, I am just using one heater and have not included a cooler.
I have butchered the existing code and everything works fine but I would like to add 2 buttons, one to increment the Set Temperature and the other to decrement it. This will save me having to re-upload a new sketch every time I want to have a different threshold temperature. I have read various posts, on a number of forums, regarding adding buttons to an existing project and have tried my best to resolve this, but I'm not getting very far.
The code, which works fine is as follows: -
/* DS18B20 Temperature Sensors on 1 wire for controlling heating fermenter
-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>
//Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>
/*-----( Declare Constants and Pin Numbers )-----*/
// Digital pin 2 for the DS18B20 data line.
#define ONE_WIRE_BUS_PIN 2
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*-----( Declare Variables )-----*/
//Get Device Address for Probe01;
DeviceAddress Probe01;
//Relay digital write pin on Arduino
int Relay1 = 5;
float Probe01Temp = 0;
//Limit and floor are Celcius
//Adjust these temperature limits as needed
int Temp01SetPoint = 20;
int Temp01SetDiff = 1;
static bool Temp01WarmMaxed;
static bool Relay01Status;
//Adjust the address of the I2C as needed
//See https://github.com/todbot/arduino-i2c-scanner
//LiquidCrystal_I2C lcd(0x27, 16, 2); LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() /****** SETUP: RUNS ONCE ******/
{
// start lcd to show results
lcd.begin(20,4);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Starting Up");
// Initialize the Temperature measurement library
sensors.begin();
// Comment out the following line if pre-assigned above
sensors.getAddress(Probe01, 0);
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
sensors.setResolution(Probe01, 9);
//set the relays
pinMode(Relay1, OUTPUT);
//turn off the relays to start
digitalWrite(Relay1, HIGH);
Temp01WarmMaxed = false;
Relay01Status = false;
lcd.setCursor(0, 1);
lcd.print("No. Sensors:");
lcd.setCursor(12, 1);
lcd.print(sensors.getDeviceCount());
lcd.setCursor(0, 2);
lcd.print("Getting temperature");
delay(5000);
lcd.clear();
//Set up labels on LCD
lcd.setCursor(0, 0);
lcd.print("Set temp:");
lcd.setCursor(12, 0);
lcd.print(char(223));
lcd.setCursor(13,0);
lcd.print("+/-");
lcd.setCursor(17, 0);
lcd.print(char(223));
lcd.setCursor(18,0);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Barrel temperature:");
lcd.setCursor(4, 2);
lcd.print(char(223));
lcd.setCursor(5, 2);
lcd.print("C");
lcd.setCursor(0, 3);
lcd.print("Heater:");
lcd.setCursor(10,0);
lcd.print(Temp01SetPoint);
lcd.setCursor(16,0);
lcd.print(Temp01SetDiff);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
delay(5000);
// Command Probe01 to read temperature
sensors.requestTemperatures();
//Barrel temperature
Probe01Temp = sensors.getTempC(Probe01);
//Change calls to triggerCoolingRelay and triggerWarmingRelay
//as needed such as both Relay01 and Relay02 both call triggerWarmingRelay()
Relay01Status=triggerWarmingRelay(Probe01Temp, Relay1, Temp01SetPoint, Temp01SetDiff, Temp01WarmMaxed);
Temp01WarmMaxed=Relay01Status;
//Print to LCD
lcd.setCursor(0,2);
lcd.print(Probe01Temp, 1);
lcd.setCursor(7,3);
if (Relay01Status)
{
lcd.print("On ");
}
else
{
lcd.print("Off");
}
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
bool triggerWarmingRelay(float tempC, int Relay, int TempSetLimit, int TempSetDiff, bool TempWarmMaxed)
{
bool result;
if (TempWarmMaxed)
{
if (tempC > (TempSetLimit+TempSetDiff))
{
//TempWarmMaxed=false;
result=false;
}
}
else
{
if (tempC < TempSetLimit)
{
//TempWarmMaxed=true;
digitalWrite(Relay, LOW);
result=true;
}
else
{
digitalWrite(Relay, HIGH);
result=false;
}
}
return result;
}// End triggerWarmingRelay
//*********( THE END )***********
What I think needs to be done is to increase and decrease the Temp01SetPoint (line 36) by 1 degree each time the relevant button is pressed. This value will then be used to turn the heater on and off once the Temp01SetPoint, + or - the Temp01SetDiff (line 37), has been breached.
Typing this out, it all sounds so simple, however, I am struggling and would appreciate any help.
TIA