This project is a combination of several difference resources:
- My single-outlet control project with Raspberry Pi and Python, originally inspired by user wilq44’s Raspberry Pi GPIO home automation
- WiringPi, software written by Gordon Henderson that allows “Arduino style” control of the GPIO pins from the command line in a Linux terminal
- Voice Command, a package written by Steven Hickson that allows voice control of the Raspberry Pi by connecting to a Google speech-to-text service.
The end result is voice-activated control of up to three electrical outlets using the Raspberry Pi. Here’s a video of the final product in action (read on for a detailed parts list, circuit diagram, and code):
A couple notes before you begin. This project is up-to-date as of December 2013, but Gordon and Steve may update their respective software in the future. If you notice any major changes to WiringPi or Voice Command that make my instructions obsolete, please leave a comment or send me a message. Also, while my previous Instructable was written to be super beginner friendly, this one is a little more advanced so it skips over a lot of the introductory material. I refer back to the single-channel version several times, instead of duplicating the content here.
Here is a list of the parts I used. Of course, if you know what you’re doing you can make substitutes as needed, or shop around for cheaper suppliers. Quantities in parenthesis.
Materials & Tools
- (1) Raspberry Pi model B with standard accessories (power supply, monitor, keyboard/mouse, SD card, ethernet cable or USB wifi adapter). See my other Instructable for a list of the exact accessories I use.
- (1) USB webcam or microphone*. I have a Logitech Quickcam Pro 9000.
- (1) Three-channel wireless outlet remote, $21
- (1) Solderless breadboard, $10
- (5 different colored spools) 22 AWG solid-core hookup wire, $17
- (1 pack of 10) M/F jumper wires, $4
- (6) SPDT relay, $2
- (6) N-channel MOSFET, $1
- Multimeter, soldering iron, wire strippers, small Philips screwdriver. See my other Instructable for some suggestions if you don’t already own tools.
The cost of this project depends heavily on what you already have lying around. If you already have a Raspberry Pi, webcam/mic and basic electronics equipment (tools, breadboard, jumper wire etc) it will only be about $40 for the wireless remote, relays and MOSFETs, and the cost goes up from there.
*My Quickcam Pro is 5 years old and I’m not sure if this exact model has been discontinued, or if it is the same thing as the “Webcam Pro 9000”, which pops up on Amazon. You may need to do some poking around online to find out if your webcam is compatible with the Raspberry Pi (keep in mind that you only need the mic, and don’t care about video). This wiki has an extensive list of verified
Step 1: Open the Remote and Remove the Circuit Board
The first thing you’ll need to do is open the plastic case of the remote to expose the circuit board.
1. Remove the battery cover and take the battery out for now.
2. Use a small Phillips head screwdriver to remove the single screw holding the front and back halves of the plastic case together.
3. Use needle nose pliers to bend off the keychain ring.
This exposes the underside of the circuit board, which you can remove from the case entirely to get a look at the top half. However, I find it easier to work with the circuit board attached to the front half of the case. This way, you can easily push the buttons when you’re testing the circuit (next step). The battery also tends to stay in better when it’s in the case. There was an unoccupied hole in the case that lined up with a hole in the circuit board – I used the small screw to attach the circuit board to the front half of the case (see the last two pictures above).
Step 2: Reverse-Engineer the Remote
This step will assume you already have basic knowledge of how a single-channel remote works. You can find a detailed explanation of that in my previous Instructable.
The basic idea here is the same – but instead of two buttons controlling a single channel (one ON and one OFF), you have six buttons controlling three channels (three ON and three OFF). Each of these buttons is connected to a pin on a chip on the circuit board (the black rectangle). Normally, these pins sit at 0V (a logical LOW). When the respective button is pressed, the pin goes up to 5V (a logical HIGH). Your ultimate goal is to “trick” the remote into thinking buttons are being pressed by sending a 5V signal from a circuit controlled by the Raspberry Pi (more on that later). In order to do that, you need to figure out which pins on the chip are connected to the pushbuttons, so you can solder jumper wires to them.
There are two complementary ways to do this. One is to just look at the traces on the back of the circuit board, and figure out which ones connect the pushbuttons to pins on the chip. You can also test this with a multimeter by testing to see which pin changes from 0V to 5V when you push each button (make sure the battery is in, or that won’t work!). The latter can be a little difficult to do with just two hands, and is definitely easier if you have alligator clip attachments for your multimeter.
If you’re using the exact same remote I linked to from Amazon, you should be able to follow my diagrams exactly. If not, you’ll need to do some tinkering on your own to figure out which pins to solder to in the next step.
Step 3: Solder Jumper Wires to the Remote
Note: I opted for economy shipping from SparkFun for my multi-colored jumper wire. The good news is I got free shipping. The bad news is I only had red and black jumper wire available before that. The connections in this project are a little easier to keep track of if you have 8 different colors available. So, for the circuit diagrams (expertly drawn in Powerpoint), I’ll use the following convention:
In the photos of my actual build, you will only see red and black wire. Of course you can use whatever colors you prefer – my intent is that the color-coding scheme in the diagrams will be easier to follow, and I apologize that it doesn’t match up to my photos exactly (it was this, or miss the deadline for the Hardware Hacking contest).
Anyway – now you need to solder jumper wir
es to the six pins identified in the previous step, plus the negative terminal of the battery connection (this will make sure your whole circuit has a common ground later). Seven connections total, as shown in the pictures above (a “fake” photo with the color-coded wires drawn in, as well as a photo of the real thing).
Optionally, if you’d like to protect the circuit board a little better, you can drill holes in the back of the remote’s original case to feed the jumper wires through. Just make sure you can keep track of which wire is which. I used a label maker since I didn’t have properly color-coded wire.
Step 4: Build the Circuit
Assemble the circuit on the breadboard. If you’re good at following breadboard diagrams, you can just go ahead and use the first image above. If that seems a little overwhelming, try doing it one step at a time (following the pictures in order):
1. Insert the relays and MOSFETS (six of each). Important – I didn’t realize until after I made all of these diagrams that the packaging on the relays is slightly too bulky for them to occupy adjacent breadboard rows, as pictured here. You will actually need one blank row in between each relay, adding five rows of total space to the build (which shouldn’t be an issue if you’re already using a big 60+ row breadboard).
2. Use jumper wires to make all the +5V (red) and ground (black) connections on the breadboard.
3. Connect the breadboard to the Raspberry Pi’s +5V and GND pins, and to the negative battery terminal (-) on the remote. Important: do NOT connect the positive power rail on the breadboard to the (+) battery terminal on the remote. The remote battery is 12 volts, so if you short that to your Raspberry Pi’s 5V pin, bad things will happen.
4. Connect the Raspberry Pi’s GPIO pins (17, 18, 22, 23, 24, and 25) to the gates (left-most pin when facing the side with the writing) of the respective MOSFETs as shown. See the color-coded table above, which matches the wire colors I used in the breadboard diagrams, for help keeping track of everything. See this page for more information about the GPIO pins and the numbering scheme (which can be confusing if you’re new to Raspberry Pi, especially if you’re used to Arduino).
5. Connect the wires you previously soldered onto the remote to the breadboard. I use the same color-coding convention for these wires in the diagrams above.
For an explanation of how the circuit works, see this step of my previous Instructable.
Step 5: Install WiringPi
Step 6: Install Voice Command