Step 1: Open the Remote Case and Remove the Circuit BoardFirst you'll need to open up your wireless outlet and crack open the remote. Here are the steps I followed - you may have to improvise if you couldn't find the exact same model remote. Your goal is just to get the circuit board out intact. It's OK if you have to break some of the plastic case to do this. 1. Remove the battery cover and battery. 2. Pry off the little keychain attachment. 3. Remove screw holding on the back cover. 4. Pop off the back cover. 5. Remove the circuit board. Step 2: Reverse-engineer the circuit: Part 1This is probably the most difficult (and possibly intimidating) part of the project - figuring out how the circuit works. Don't feel overwhelmed though - you DON'T need to understand what every single component in the circuit does. Your goal is just to figure out what the on and off buttons do, so you can use the Raspberry Pi to "trick" the remote into thinking those buttons are being pressed. So, what's going on when we look at the circuit board? The first two images, showing side-by-side pictures of both sides of the board, give you a rough idea of the things we care about. There's a battery, which has positive and negative terminals, connected to the board. There are two pushbutton switches, labeled SW1 and SW2 on the circuit board, corresponding to the ON and OFF buttons on the exterior plastic case, respectively. Each one of these switches has four pins connected to the circuit board, labeled in the second image above. So, we want to figure out what these buttons do - a good way to start is to figure out what the voltages at these pins are when the buttons are pushed. This is where your multimeter will come in handy. If you need help using a multimeter, check out this tutorial from SparkFun or this one from Science Buddies (full disclosure: I work for Science Buddies and I wrote that tutorial). You'll want to attach your multimeter's black probe to the negative battery terminal (this is where I find those alligator clips very handy). Then, use the red probe to measure the voltage at EACH pin when:
So, now we know how the voltages of the button pins change when they are pushed. The next step is to figure out which of those pins are connected to inputs on the chip - the big black rectangle that acts like the "brains" of the circuit. Step 3: Reverse-engineer the circuit: Part 2Next you need to analyze the chip's connection to the circuit. The chip in my remote is in a dual in-line package (DIP), meaning it has two parallel rows of pins. The first image above highlights all of these pins on the bottom of the board using yellow circles. Our goal is to figure out which of these pins are connected to the pins on the buttons we analyzed in the previous step. You can guess at this by looking at the lighter-green traces on the circuit board. The second image above highlights these in magenta and orange - it looks like we can trace two different pins (one from the ON button and one from the OFF button) to pins on the chip. It probably isn't a good idea just to eyeball this, however. You need to use a multimeter in continuity-test mode to check and make sure that these pins are actually electrically connected. So, do that - set your multimeter to continuity test, and use the probe tips to simultaneously poke two different pins (bounded by the orange or magenta polygons above, respectively). If the pins are electrically connected, you should hear a loud BEEP from your multimeter. Now, let's cross-reference this with our analysis of the pin voltages (on the buttons) in the previous step, to find out what happens to the pin voltages on the chip when the buttons are pressed. The last three images above show this. It looks like both pins sit at 0V by default. When the ON button is pressed, one of them goes up to 4.5V. When the OFF button is pressed, the other one goes up to 4.5V. This confirms our suspicion that the circuit probably has a chip operating at 5V logic levels. Now we can move on to building a circuit that will trick the remote into thinking the buttons are being pressed, by sending 5V signals to these pins. Step 4: Solder Jumper Wires to the RemoteYou'll need to solder three jumper wires to the remote: one to each of the pins identified in the previous step, and one to the pins connected to the battery's negative terminal (so you can make sure the remote has a common groundconnection with the circuit you'll build). Make sure you remove the battery before soldering (excessive heat can make batteries explode), and if you're cutting your own jumper wires, make sure they're long enough (a few inches) to reach a nearby breadboard. Odds are if you've gotten this far you already know how to solder (or can get help from someone who does), but here's the SparkFun soldering tutorial just in case. Step 5: Build the CircuitIn this step you'll assemble the circuit that will connect your newly-hacked remote to your Raspberry Pi. Follow the steps below (corresponding to the diagrams above) to build the circuit. To learn how the circuit actually works, go on to the next step. 1. Line up your Raspberry Pi, breadboard, and remote left to right as shown. 2. Populate your breadboard with the two MOSFETs and two relays. Pay attention to the orientation based on the pins of the relays (one side has three pins, the other side only has two), and the big "tabs" on the back of the MOSFETs (facing to the left in my diagrams). 3. Use jumper cables to make connections on the breadboard as shown in the second diagram. 4. Use jumper cables to make external connections to the remote and the Raspberry Pi, as shown in the third diagram. A couple notes:
Step 6: How Does the Circuit Work?Disclaimer: I'm not an electrical engineer, and there might be much, much better ways to go about doing this. I'll present what I did and how it works. If you have a better circuit design, or see something wrong with mine, please go ahead and leave suggestions in the comments! Here's the general idea: we need to be able to toggle a 5V logic signal on and off to trick the remote into thinking the buttons are being pressed. The Raspberry Pi operates at a 3.3V logic level, but generally chips designed for 5V logic will still recognize 3.3V as "high". So, ideally you should just be able to wire the Raspberry Pi's GPIO pins straight to the remote, with no intermediate circuit. That's kind of what you see in this Instructable (although the pins aren't connected directly to the remove, there is a resistor in between). So, I tried that method first, but could not get it to work at all (even for a range of different resistor values). Ultimately, after some tinkering around with a multimeter, it looked like my remote was drawing more current than the Raspberry Pi's GPIO pins could supply - which was causing the output voltage to drop to around two-point-something, too low to be recognized as a logical HIGH. Some Googling about GPIO pin current limitations lead to a bunch of forum discussions about how you're really supposed to use a buffer with the GPIO pins, they aren't designed to drive much of anything directly. Thus, the buffer circuit using relays and MOSFETs. A relay is an electrically-controlled switch with an electromagnet inside. A "single pole double throw" (SPDT) relay can toggle between two different connections, depending on whether or not the electromagnet is energized. So in this case, we can hook a relay up to +5V and 0V and toggle back and forth depending on which voltage we want to send to the remote. We use the Raspberry Pi to control the electromagnet to turn the relay on or off - but the electromagnets still require more current than the Raspberry Pi's GPIO pins can supply. So, we use aMOSFET, which allows you to drive high-power loads using a low-power source (you can't magically draw power from nowhere - you have to connect to a bigger external power supply, in this case the Raspberry Pi's 5V source coming straight from USB, which can supply more current than the GPIO pins themselves). You might be familiar with MOSFETs if you've ever tried to control a motor or huge LED strip with an Arduino, which also has current limitations. The three diagrams above show what happens depending on which GPIO pins are set to HIGH in Python (which we'll get to next). When both pins are sitting at LOW, both relays connect the buttons on the remote to 0V (ground), so nothing happens. When GPIO 17 is set to HIGH, the first MOSFET turns on, which allows current to flow through the electromagnet in the first relay, flipping the switch and connecting it to 5V instead of 0V. This sends a 5V signal to the ON button's pin on the remote, making the remote think the button has been pressed. The same concept applies to GPIO 18 and the OFF button. Step 7: Python CodeAnother disclaimer: I'm also not a computer scientist or programmer, much less a Python expert. If the code below looks awful, inefficient, or just makes you cringe, please feel free to post a link to better code, for the sake of people reading this in the future. Update 12/13/2013: See mmoon's comment below for a link to some neater code. Now that you have the circuit built, it's time to start using the Raspberry Pi! This is another part that was confusing for a first-time Raspberry Pi user - it wasn't immediately obvious how to actually control the GPIO pins, because apparently there's more than one way to do it. A Google search for "raspberry pi gpio python" reveals multiple different tutorials and Python packages you can download. You can also control the pins directly from a terminal without using Python at all. So, it took me a while to figure out that the default Raspbian distribution already comes with a Python module for controlling GPIO pins. Phew! Remember that I'm assuming you already have a Raspberry Pi up and running this point, using Raspbian, which comes with both Python 2.x and 3.x (as of December 2013). I wrote the code in Python 3.2.3 using IDLE 3 (Integrated Development Library) - there's a shortcut for it on the default Raspbian desktop. To run the code: 1. Open a terminal ("LXTerminal" icon on the desktop), type sudo idle3, and hit enter. This runs IDLE "as root", which is required for GPIO access with Python. 2. Download christmas_timer.py (below) and then open it in IDLE 3, or create a new Python file and copy and paste the code below. 3. Take a minute to look at the code and the comments. The only part you should need to edit is the section towards the beginning with all the "on" and "off" times (MonOn, MonOff, TueOn, etc). 4. You're almost ready to run the code! But first...(go to the next step)
Step 8: Hook Up Your Christmas Lights!Don't forget the most important part of the project! If you haven't done so already, string up your Christmas lights and make sure they're plugged into the wireless outlet adapter you bought (I used the remote manually to make sure the lights were on for these pictures). Step 9: Test Your CodeYou're ready for a test run! Select Run->Run Module or press F5 in IDLE to run the code. However, if you're doing this project in the middle of the day, you probably don't want to wait until evening to see if the lights turn on, and then a few more hours to see if they turn off. For testing purposes it's a lot faster to change a few lines of code temporarily. For example, if it's 3:30pm on a Tuesday, you could change
(on at 5:30pm, off at 10:30pm) to
(on at 3:32pm, off at 3:33pm) That will give you enough time to run outside and see if the lights turn on and off. You could also just temporarily set the wireless outlet up right next to your desk (with a lamp or a strand of lights) so you don't have to run back and forth to test. If it works - congrats! Sit back and bask on the glory of your fully-customizable automatic Christmas light timer. Maybe you can work on expanding your code to allow web control, or multiple outlets for one of those crazy Wizards of Winter Christmas light shows. If it didn't work on the first try, don't worry - head over to the next step for some debugging tips. Step 10: DebuggingCircuit not working? Here are a bunch of things you can try.
I'd suggest using cron to schedule the fan's on/off tasks. Scheduling tasks can be managed by the
Add each on/off task. They would look something like:
The actual python script would be straight forward. Import
|
R&D Publishing > Raspberry Pi >