ds18b20 etc

Wood Boiler Control – Timers, Relays, DS18x20, LCD, LED, GPIOZERO, Temperature [closed]

Ask QuestionAsked todayActive todayViewed 31 times01Closed. This question needs to be more focused. It is not currently accepting answers.

Update the question so it focuses on one problem only. This will help others answer the question. You can edit the question.

Closed 2 hours ago by DirkCoderMikejoanSteve RobillardMilliways.

(Viewable by the post author and users with the close/reopen votes privilege)Edit question

Hello smarter people than I,

I don’t do forums. I usually figure everything out on my own, however….

I have a wood boiler, but it’s control is a simple aquastat.
Aquastat controls an intake solenoid, and exhaust fan.
The circulation pumps run 24/7 (with no low water protection)

So I’m looking to design my own controller. I have made one using Arduino, but I’d rather use RPi. Arduino has it’s own issues with timing (49days), and communication(wifi). Attached is the code I have for that so far. (just for kicks) I could get the buttons to change the temp displayed on the LCD, however it ignored it when running the code. So I gave up and left it unfinished.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define ONE_WIRE_BUS 2
#define LED_PIN_R 9
#define LED_PIN_Y 10
#define LED_PIN_G 11
#define HOUR 3600000UL
#define MIN 60000UL
const int Upbutton = 6;
const int Downbutton = 7;
const int relayPin = 5;
int tempSet = 175;
const int noFire = 150;
const int Differential = 5;
const int setDif = tempSet - Differential;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int ledPin = 8;
const long OnTime = MIN; //
const long OffTime = HOUR; //
int ledState = LOW;           //   HIGH = off
unsigned long previousMillis = 0;

void setup()
  pinMode(ledPin, OUTPUT);

  pinMode(LED_PIN_R, OUTPUT);
  pinMode(LED_PIN_Y, OUTPUT);
  pinMode(LED_PIN_G, OUTPUT);
  digitalWrite(LED_PIN_R, LOW);
  digitalWrite(LED_PIN_Y, LOW);
  digitalWrite(LED_PIN_G, LOW);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  pinMode(Upbutton, INPUT_PULLUP);
  pinMode(Downbutton, INPUT_PULLUP);

void loop()
  unsigned long currentMillis = millis();   // capture the latest value of millis()

  int tempF = sensors.getTempFByIndex(0);
  Serial.print("Current Temp: ");
  Serial.print("Temp Set: ");
  lcd.setCursor(0, 0);
  lcd.print("Temp Set: ");
  lcd.setCursor(0, 1);
  lcd.print("Water Temp: ");

  if (digitalRead(Upbutton) == 0) {
    tempSet = tempSet + 1;
  if (digitalRead(Downbutton) == 0) {
    tempSet = tempSet - 1;

  if (tempF >= tempSet) {
    Serial.println("High Temp");
    digitalWrite(relayPin, HIGH);
    digitalWrite(LED_PIN_Y, LOW);
    digitalWrite(LED_PIN_G, HIGH);
    digitalWrite(LED_PIN_R, HIGH);
  if (tempF <= tempSet && tempF > setDif) {
    Serial.println("Perfect Temp");
    digitalWrite(relayPin, HIGH);
    digitalWrite(LED_PIN_Y, LOW);
    digitalWrite(LED_PIN_G, HIGH);
    digitalWrite(LED_PIN_R, LOW);
  if (tempF < setDif && tempF > noFire) {
    digitalWrite(relayPin, LOW);
    digitalWrite(LED_PIN_Y, HIGH);
    digitalWrite(LED_PIN_G, HIGH);
    digitalWrite(LED_PIN_R, LOW);
  if (tempF < noFire) {
    Serial.println("NO FIRE");
    digitalWrite(relayPin, HIGH);
    digitalWrite(LED_PIN_Y, LOW);
    digitalWrite(LED_PIN_G, LOW);
    digitalWrite(LED_PIN_R, HIGH);

  if ((ledState == LOW) && (currentMillis - previousMillis >= OnTime))
    ledState = HIGH;  // Turn it off
    previousMillis = currentMillis;  // Remember the time
    digitalWrite(ledPin, ledState);  // Update the actual LED
  else if ((ledState == HIGH) && (currentMillis - previousMillis >= OffTime))
    ledState = LOW;  // turn it on
    previousMillis = currentMillis;   // Remember the time
    digitalWrite(ledPin, ledState);    // Update the actual LED

Now… I’m not a coder, by any means. I actually just started learning Python last week. Most tutorials, etc all have old outdated info/code so it’s been rough. I’ve read 5 RPi books and I think there is some room for improvement (easy money for some?)

I’m running a RPi 3B, fully updated/upgraded as of this date (I have a RPi 4 if needed)

Attached is the current code I have, there may be some dead ends that I’m working on, and it’s obviously amateur coding. I figure once I get it to work, I can clean it up a bit and start adding notes. Some notes came from code online (not mine) Time and Temps are only for testing, eventually they will be longer duration / higher temps (See Arduino code if you understand it)

#! /usr/bin/python3
# Import Libraries
import os
import glob
import time
import gpiozero
from gpiozero import LED, Button
from signal import signal, pause, SIGTERM, SIGHUP
from time import sleep
from rpi_lcd import LCD

Red = LED(17)
Yellow = LED(18)
Green = LED(19)
Button = Button(20)
RELAY_PIN = (21)
LED_on = False
relay = gpiozero.OutputDevice(RELAY_PIN, active_high=False, initial_value=True)
tempSet = 100
noFire = 70
tempDif = 5
setDif = tempSet - tempDif

def safe_exit(signum, frame):

signal(SIGTERM, safe_exit)
signal(SIGHUP, safe_exit)
# Initialize the GPIO Pins
os.system('modprobe w1-gpio')  # Turns on the GPIO module
os.system('modprobe w1-therm') # Turns on the Temperature module
# Finds the correct device file that holds the temperature data
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
# A function that reads the sensors data
def read_temp_raw():
  f = open(device_file, 'r') # Opens the temperature device file
  lines = f.readlines() # Returns the text
  return lines
def autoStoke():
    while True:
        fanOn = now.replace(second=1)
        fanOff = now.replace(second=1)
        turnOn = now>fanOn and now<fanOff
        turnOff = now>fanOff
    if(turnOn == True):
    elif(turnOf == True):
# Convert the value of the sensor into a temperature
def read_temp():
  lines = read_temp_raw() # Read the temperature 'device file'
  # While the first line does not contain 'YES', wait for 0.2s
  # and then read the device file again.
  while lines[0].strip()[-3:] != 'YES':
    lines = read_temp_raw()
  # Look for the position of the '=' in the second line of the
  # device file.
  equals_pos = lines[1].find('t=')
  # If the '=' is found, convert the rest of the line after the
  # '=' into degrees Celsius, then degrees Fahrenheit
  if equals_pos != -1:
    temp_string = lines[1][equals_pos+2:]
    temp_f = float(temp_string) / 1000.0 * 1.8 + 32.0
    return temp_f

while True:
    lcd.text('Temp: {:.0f} F' .format(read_temp()),2)

    if read_temp()<75:
    elif  read_temp()>75:

You may notice weird things like Importing Time 2 different ways, I had an issue with Thonny so had to do it that way. Or imports not being used or needed… 🙂 This code is very basic for testing, but I have searched all day and can’t come up with a suitable solution for the auto stoke. 😦

One big issue I have is, the code just stops running after some time (only tested in Thonny)

Goals of the project:

  1. Display (LCD or OLED) Water input and output temps (from pumps)
  2. Show Outside Ambient Temp and Exhaust (flue) Temp to know if it’s heating or cooling water
  3. Set Temps (with buttons) to Turn on and off relay (fan and intake) Example:Turn relay on at differential temp (5* below set temp of 175*) Turn relay off at set temp (175*) Dif temp may be set to 10+ when it’s below freezing out (so automate to outside temp) Below 150* turn relay OFF (extremely important) This is the main reason this controller is being made. If there is no fire; it doesn’t know, so it keeps fan on… which cools the water until morning (tons of wasted stored energy!) I’ve lost 90* water temp over night… that’s 90* with 250gallons :O
  4. Auto Stoke – To prevent no fire situation. No matter what is going on, turn the relay on for ~1min every ~60min. This will keep coals glowing hopefully! (will have to play with numbers)
  5. LED Status – If it’s too hot, too cold (no fire), Just right, Heating, etc (possibly OLED display to show as much info as possible, then no LEDs?)
  6. Four Relay outputs, I’d like Fan/Intake on Relay 1, House Pump on Relay 2, Garage Pump on Relay 3. I debated separate Fan and Intake relays, but it’s very important they both work together, one without the other is bad. Possibly doing auto fill using 4th relay, If it bumps low water limit switch, turn relay on for say 10 seconds to fill. If it hits limit again(has to be a leak), shut everything down and contact me via Text.
  7. Limit switch on water level indicator (physical floating ball water level indicator) If water is low, it will trip the switch,(*4th relay) telling the RPi to Turn off Pumps to prevent flooding (heat exchanger in attic), loss of 1200$ in antifreeze and additive (total 250gallons) May as well turn all relays off actually. This fail safe is very important.
  8. Email/text status updates. I would want a TEXT for emergencies (and email), and just emails for general logging (fan off, fan on, etc) so I can use the frequency of emails to tweak the differential temp logic. When it’s warm outside you want low dif, cold outside you want long dif. It’s a balancing act.
  9. Eventually remote monitoring next to house thermostat.

*** Wood Boiler and House Thermostat are NOT connected, they don’t know about each other. I have a separate thermostat wired from ‘call for heat’ to the furnace fan terminal, when it calls for heat, it just turns on the fan. The wood boiler is always doing it’s own thing, keeps water between 170-175(whatever I set it to), and is always circulating water. (also give hot water in house) I will have an aquastat installed on furnace heat exchanger that will break the fan wire if temp is below say 100* to prevent blowing cold air incase of… So what has happened is boiler had no fire,ran all night cooling the water. It always kept circulating water which is fine because then the House kept temp.(I had no idea there was no fire) Then I came out in the morning and boiler was at ~80* water temp, fan running, no fire!

This is my first year with a wood boiler, so I’m learning… How on earth did they get away with this junk controller for so many years (30+ years I guess…)

That’s about it, to some this may seem very easy! (I hope) I’m open to suggestions on books to read, so far no luck on anything worth while.

Any help is appreciated (direct (‘my name’ at duck dot com) or through here)ledrelaylcdgpiozerods18b20ShareEditFollowReopenFlagasked 4 hours agohomestead1 New contributor

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.