Hello to all,
I would like to implement a variable control with a DS18B20 temp sensor. Either using a potentiometer on an analog pin or using two buttons to change the target temperature up or down.
See below a simple sketch with this fixed parameter. if (temperature > 19)
This project controls my electrical geyser. Currently if I need to change the target temperature, "occasionally" then I need to connect the USB cable to the device and modify the, if (temperature > 19) to if (temperature > 20).
Any one able to figure this out?
I have completed a similar project that works over the internet and I would like to implement the same idea.
Regards
#define RELAY1 9
#include <OneWire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
OneWire ds(12);
void setup(void) {
pinMode(RELAY1, OUTPUT);
Serial.begin(9600);
lcd.begin(20, 4);
float temperature = getTemp();
lcd.print(" TEMP - STATUS ");
}
void loop(void) {
pinMode(RELAY1, OUTPUT);
float temperature = getTemp();
Serial.println(temperature);
lcd.setCursor(0, 1);
lcd.print(temperature);
delay(1000);
if (temperature > 19) {
digitalWrite(9, LOW);
lcd.print(" Geyser OFF");
}
else
{
digitalWrite(9, HIGH);
lcd.print(" Geyser ON");
}
}
float getTemp() {
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.println("Device is not a DS18x20 family device.");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1);
delay(1000);
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for (int i = 0; i < 9; i++) {
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
moderator: added code tags ==> # button above smiley's