Anth's Computer Cave

Hack an air cooler to use from your Raspberry Pi

Today I am hacking an air cooler to use in my Pi-powered home-automation system

I found this unit on the roadside in perfect condition. We're heading towards winter in Australia so I don't really need an evaporative cooler, but I decide it was a good opportunity to build cooling functionality into my programs.

A three-speed air cooler. Picture by Anthony Hartup.
A three-speed air cooler.

Anything that can switch on solely via a power point can already work with my current system. Unfortunately these cooling units, like many other appliances, don't turn on when you switch them on at the wall.

The control panel for the cooler. Picture by Anthony Hartup.
The control panel for the cooler

When you plug this into the wall and flick the switch this unit goes into standby. To activate the unit you need to press the power button on the panel. The fan then starts on a low setting. To adjust the speed you must press the Speed button, once to change to medium, twice to go high and a third time to return to low.

The problem is that my Raspberry Pi has no hands.

A highly-technical way to solve this would be to tap into the logic circuits in the panel, ground them to the Pi and mimic the signals that control the appliance using the Pi GPIO pins directly. This is tricky and has the potential to fry your Pi, and you'll need to determine the circuit layout for every appliance you wish to hack.

I decided to use a simpler (and more cave-like) method that should work with almost any appliance, not just this cooler.

I hacked the actual buttons!

Buttons commonly used in circuits.
Buttons commonly used in circuits.

To do this you use relays to either replace the button, or work alongside it. The latter option allows you to control it from the Pi yet still use the button manually.

Using these relays separates the power system of the Pi from the power system of the appliance and means errors (either in your modifications or a fault in your appliance) do not reach back and fry the Pi.

A 5V Relay. Picture by Anthony Hartup.
A 5V relay salvaged from an old TV.

That is because there is no electrical connection between the 5V pins at one end of the relay to the activation pins on the other end that work your buttons.

I like to salvage mine from old TVs but you may be better off buying a cheap ready-made unit from ebay. The unit pictured below only costs a couple of bucks.

A 5V Relay. Picture by Anthony Hartup.
A cheap pre-built relay unit from ebay.

Click here for a series of tutorials on using salvaged relays. I'll try to get a tutorial on using the ebay relays soon.

Now you need to decide how to connect the relay to the buttons

The On/Off button I have left on the board and soldered wires to the connectors underneath.

Wires soldered to the button connections underneath the circuit. Picture by Anthony Hartup.
Wires soldered to the button connections underneath the circuit.

This button can still manually turn the unit on or off.

The Speed button was different in that the button connectors were attaching to extra thin traces on the circuit board. My arthritic hands cannot solder accurately enough to attach wires from underneath, so I removed the button and pushed male breadboard cables through the holes from above.

Wires replacing the buttons from above. Picture by Anthony Hartup.
Wires replacing the buttons from above.

This made soldering to the traces a lot easier, but would not be an option if you wanted both computer and manual control. I am all-in with my home-automation system so I don't require the manual option.

Picture by Anthony Hartup.
One of the relays used in the cooler.

I positioned the relays against the inside of the casing and connected the button wires to the staggered pins.

I soldered wires to the other 5V pins and connected these to spring-loaded speaker plugs outside the unit for easy connection to the relay-drivers on my home-automation base station.

Picture by Anthony Hartup.
The main connectors reclaimed from an old stereo.

Wiring Diagram

Below is a wiring diagram showing the salvaged relays connected to the Raspberry Pi via a dual H-bridge motor-controller.

The wiring diagram for the air cooler. Image created by Anthony Hartup with CircuitDraw.
The wiring diagram for the air cooler. Image created using with CircuitDraw. Click for larger image.

The polarity of the wires connecting to the air cooler panel is irrelevant, as is the polarity of the wires between the motor-controller and the relays.

Python Code

Here is the code to run on your raspberry Pi. The GPIO pins are configured to match the diagram above.

Paste it into a file and save it as "pi_cooler.py" or something similar.

#!/bin/bash

#Control a three-speed air cooler from Pi
#By Anthony Hartup

#Hardware instructions are at:
#anthscomputercave.com/projects/salvagehacking/pi_cooler/raspberry_pi_air_cooler.html

import RPi.GPIO as GPIO
import time

power_status = "off"
speed_status = "low"

#Set GPIO pins for power and speed relays
power_pin = 4
speed_pin = 17

GPIO.setmode(GPIO.BCM)
GPIO.setup(power_pin, GPIO.OUT)
GPIO.output(power_pin, False)
GPIO.setup(speed_pin, GPIO.OUT)
GPIO.output(speed_pin, False)

#Turn cooler power on or off
def power():
    global power_status
    GPIO.output(power_pin, True)
    time.sleep(.1)
    GPIO.output(power_pin, False)
    if power_status == "off":
        power_status = "on"      
    else:
        power_status = "off"

#change fan speed by one simulated button-push
def change_speed():
    GPIO.output(speed_pin, True)
    time.sleep(.1)
    GPIO.output(speed_pin, False)

#Adjust fan speed to specific level
def speed(level):
    global speed_status
    if level == "low":
        if speed_status == "high":
            change_speed()
        elif speed_status == "medium":
            change_speed()
            time.sleep(.1)            
            change_speed()
        speed_status = "low"
    elif level == "medium":
        if speed_status == "low":
            change_speed()
        elif speed_status == "high":
            change_speed()
            time.sleep(.1)            
            change_speed()
        speed_status = "medium"
    elif level == "high":
        if speed_status == "medium":
            change_speed()
        elif speed_status == "low"
            change_speed()
            time.sleep(.1)            
            change_speed()
        speed_status = "high"

#run before closing program to reset GPIO pins            
def close():
    GPIO.cleanup()

Run the program

In a terminal on your Raspberry Pi, navigate the the folder containing the code and type sudo python.

Once Python Loads, type import pi_cooler.

To turn the cooler on type pi_cooler.power(). The air cooler should turn on running at low speed.

To change speed to medium, type pi_cooler.speed("medium"). To change speed to high, type pi_cooler.speed("high").

To change speed to back to low, type pi_cooler.speed("low").

That's it, you're Raspberry Pi can now control the cooling in your home. Next month you will see some more complex ways to use the system when I build it in to the upcoming version 3 of the AAIMI Room Control module.

Cheers

Anth

_____________________________________________


Comments

Leave a comment.

There are currently no comments for this article.

Leave a comment on this article