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.
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.
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!
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.
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.
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.
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.
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.
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.
Below is a wiring diagram showing the salvaged relays connected to the Raspberry Pi via a dual H-bridge motor-controller.
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.
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.
There are currently no comments for this article.