Raspberry Pi Heater Controller

UPDATE (2013-02-15): I’ve discovered why the DS18B20 was giving out the wrong temperature! Silly mistake.. I had wired the Vdd to 5V instead of 3.3V. In the process I’ve blown GPIO pin 4 on one of my Raspberry Pi’s.. bummer but installed a new Pi and re-wired the Vdd on the DS18B20 to 3.3V, now it’s working fine.

Over the last few evenings I’ve been working on my Raspberry Pi heater controller… The hardware is now finished and I’ve started on the software.  The controller uses a DS18B20 to monitor the temperature and one of the GPIO pins to drive a relay which in turn drives a contactor (the heater is a 1.5kW air blower, that is why the contactor is required). Here is a quick overview of the setup so far.

Circuit diagram:

Heater control schematic (in KiCAD)

Heater control schematic (in KiCAD)

The parts in their box:

Heater control in it's box...!

Heater control in it’s box…!

The 1-wire input through a 3.5mm stereo jack and the relay drive transistor:

Relay drive transistor (under shrink wrap)

Relay drive transistor (under shrink wrap)

The recycled phone charger PSU:

The recycled phone charger switch-mode PSU

The recycled phone charger switch-mode PSU

The relay and contactor combo:

Relay and contactor piggy backed

Relay and contactor piggy backed

The control software is going to be web based and will allow me to set a temperature set point, override the control, and if I get to it, will also have some sort of timer to allow the heater be set to come on and go off at pre-set times.

There is a pile of info out there on 1-wire temperature sensors and connecting them to the RasPi.  One of the better sites I found was: www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/temperature/

Setting the GPIO pin is simple, this script gets run at boot up:

echo "17" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio17/direction
echo "0" > /sys/class/gpio/gpio17/value
chmod 777 /sys/class/gpio/gpio17/value

Now the lighttp web server can have access to the GPIO pin.  Here is a snippet of the PHP that does the business…

$s = $_REQUEST["s"];

if ( $s == 'on' ) {
        $cmd = 'echo "1" > /sys/class/gpio/gpio17/value';
        exec( $cmd );
        }

if ( $s == 'off' ) {
        $cmd = 'echo "0" > /sys/class/gpio/gpio17/value';
        exec( $cmd );
        }

I’m having an interesting problem with my 1-wire readings at the moment. For the first five minutes or so the reading are correct, but after a while the readings jump by 40 degrees! The 1-wire CRC is fine so I don’t think there is a problem with the bus, but I’ll have to take a look with the scope to see if I can get to the bottom of it… very strange!