Tuesday, 30 January 2018

Composting toilet raspberry pi controlled extractor fan

I've been having some trouble with humidity building up under the lid and on the seat (under the lid) of my home-build wheelie-bin composting toilet - usually when there has been a rapid drop in temperature of several degrees, such as overnight. 

I had a computer cooling fan in a housing that I had built, running continuously to extract air from the composting toilet up a vent pipe, but it wasn't working as well as I had hoped. It just wasn't powerful enough.
Image result for 12v computer fan


I found a fan more suited to the task; an in-line blower fan used to remove dangerous petrol fumes from boat bilges.
   Image result for eco worthy blower
However, it turned out to be a little bit too powerful (and noisy!). I didn't want to run it continuously due to noise, the probability that it would totally dry out my composting toilet (not ideal), and it would quickly drain my solar panel/battery system.

A solution was required: I already had a raspberry pi attached to the outhouse to run a timelapse photography project.

I purchased a DHT22 temperature/humidity sensor from Jaycar electronics. Image result for dht22
Connection to the GPIO header pins on the raspberry pi was made easy using header plugs from an old computer, and I soldiered the wires directly to the sensor pins.
Image result for computer header plug
I just followed the instructions at http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-the-raspberry-pi/
Which has instructions for the DHT11 and the DHT22 - the only trick was an unexpected error "ImportError: cannot import name Raspberry_Pi_Driver" which I got when trying to use the python code - however, moving the script into the Adafruit source subfolder seemed to help get past the error.

I also purchased a 5v relay from Jaycar electronics.
5V 1-Channel Relay Board Module
This uses 5volts from one of the GPIO pins on the raspberry pi to control whether or not 12volts (or 240volts) can pass through.

I followed the instructions at http://www.instructables.com/id/5V-Relay-Raspberry-Pi/

The final python code I used (from within the Adafruit source subfolder) is below (although I've probably tweaked it further by now: I'm not sure running the fan would be useful below 10°C )

#!/usr/bin/python
import sys
import Adafruit_DHT
#check humidity
#if humidity is greater than 60% then
#activate blower for 10minutes
#sleep for 5 minutes if ok
#loop and check again
import RPi.GPIO as GPIO
import time
#blower GPIO channel
channel = 11
# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.OUT)
def motor_on(pin):
        GPIO.output(pin, GPIO.HIGH) #TURN ON
def motor_off(pin):
        GPIO.output(pin, GPIO.LOW) #TURN OFF
try:
        while True:
                humidity, temperature  = Adafruit_DHT.read_retry(11, 15) #GPIO pin 15
                print 'Temp: {0:0.1f} C Humidity: {1:0.1f} %'.format(temperature,humidity)
                if humidity > 60:
                        print 'Humidity is greater than 60-turning fan on'
                        motor_on(channel)
                        time.sleep(60*10)
                else:
                        motor_off(channel)
                        print 'Humidity is fine'
                        time.sleep(60*5)
except KeyboardInterrupt:
        motor_off(channel)
        print 'Fan has been stopped'
finally:
        GPIO.cleanup()
        print 'GPIO pins cleaned'

So far it seems to be working great, and I can watch the humidity drop over time. 😎