Instructables

Wireless Multi-Channel Voice-Controlled Electrical Outlets with Raspberry Pi

FeaturedContest Winner
Picture of Wireless Multi-Channel Voice-Controlled Electrical Outlets with Raspberry Pi
Update 2/11/2014: Thanks to everyone who voted for this project in the Raspberry Pi contest!

This project is a combination of several difference resources:

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
Cost

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 peripherals.
 
Remove these adsRemove these ads by Signing Up
mikerbob2 months ago

Great instructable - well done. Now my problem. My remote set is a little different from yours, but so close though that the pin outs are the same on the remote. My symptom is that when I raise the GPIO to high, the relay triggers, the LED on the remote lights up, but does not trigger the 120V plug. Unplug the remote from everything, and it works as it should (so it still works). Is there some troubleshooting step that I missed? Thanks in advance.

Ben Finio (author)  mikerbob2 months ago

Hmm. So, you know there's nothing wrong with your remote since it works fine when you unplug it and just push the buttons. You know your code, GPIO pins and relays are working correctly since you can hear the relays triggering. And you know the remote is receiving a signal since its LED lights up.

The only thing I can think of is that you soldered to the wrong pins on the remote, or the pinout is actually different even if it looks very similar to mine. Did you actually measure the voltage at each of the pins when you push each button, or just go by looks and visually following the circuit traces to the buttons? Can you post pictures of your remote and the circuit board?

Thanks Ben. I did recheck and see that each soldered lead goes +5V when the corresponding button is pressed (and doesn't move off 0 when the other buttons are pressed :-). I attached an image of this remote for reference.

Again, thanks for you reply. It's great to get a response.
photo (1).JPG
Ben Finio (author)  mikerbob2 months ago

Ok, so to add to the mystery (or maybe help resolve it?): I just moved my whole setup from my office to my living room. Everything worked very reliably in my office, where I shot the video. The only problems I had were related to the actual voice recognition (i.e. sometimes it would interpret "lights off" as "white sauce"), but the remote always triggered the outlets.

Now, in my living room (about 12'x17' vs 10'x10' for the office), it's very inconsistent. Even skipping voice command entirely and just typing the GPIO commands at the command prompt - sometimes it works, and sometimes it doesn't. I've been trying to figure out if it has something to do with the state of the pins/outlets when the Pi shuts down or turns on, e.g. if the lights are already on when the Pi boots up, does that somehow screw it up? But I can't find anything consistent - sometimes I reboot the Pi and it goes back to working, sometimes it doesn't.

Since I didn't have that problem in my smaller office, my only guess is that it actually has something to do with the range or signal power of the remote. If so, that would be very disappointing - I forget the advertised range of the remote, but I'm pretty sure it's way more than 15 feet. Have you tried using the adapters on an outlet that's physically very close to your Pi?

My remote has the same chip, so I think we are just a different revs of the remote overall.

I did do my testing of the standard remote, unconnected, to test that it still is functioning in the same location that it sits when it is connected. It works without issue to plugs 1, 6, and 15 feet away.

The only additional item I can add is that the LED on the remote glows bright and steady when unconnected and a button is pressed. It glows less-bright and has a "flicker" when it is driven by the Pi. I'll look next into power to see if there is a mismatch there from what is being driven by the remote itself and what the Pi delivers.

I'll keep plugging away - no pun intended - and see what I can come up with and report back.

Thanks and good luck with your issue after movement from test bench to final environment.

Ben Finio (author)  mikerbob2 months ago

Checking back in - check out this thread. The creator of the kit suggested increasing the length of the remote's antenna by soldering an additional 6" of wire on. I'm going to give that a shot when I get a chance.

Ben Finio (author)  Ben Finio2 months ago

Doh...stupid link didn't work. I blame the new editor.

http://www.reddit.com/r/raspberry_pi/comments/1xh36g/not_only_will_we_have_opensource_software_and/

I don't think my issue is the antenna (I could be wrong there) unless the rig or pi is causing enough interference that it no longer works in this "harsher" environment.

I did add a separate power source (1A USB) for just the breadboard. Same result. gpio triggers the relay, the LED on the remote light up, the remote plug does not trigger.

Is there a way to simply test the remote via the leads that are soldered there and a power source applied manually?

Ben Finio (author)  mikerbob1 month ago

Hmm. You could either use a 3xAA (or AAA) battery pack, which should supply 4.5V; or cut up a USB power supply cable (like the one that powers the Pi) and use that to get 5V from the V+ and GND wires. That way you can just connect a HIGH logic signal directly to the wires you soldered to the remote and not use the Pi at all (you'll probably still want to use a solderless breadboard though). If you do that make sure the remote shares a common ground with either the battery pack or the USB cable.

If you don't want to cut up a USB cable you can look for a breadboard adapter like this: http://www.pololu.com/product/2592

Ben Finio (author)  mikerbob2 months ago

Ok - so last night, I had myself convinced it was a range issue with the remote, because I could get it to work consistently when I plugged an adapter in right next to my TV stand, but not when the lamp was plugged in across the room.

Of course, this morning I was unable to reproduce that issue. I booted the Pi up and everything worked just fine. While I'm still unable to consistently reproduce the problem, I've noticed two things:

1. Either unplugging the remote adapters or rebooting the Pi while the lights are on seems to screw things up, sometimes. i.e. reboot the Pi while both lights are on, and then I can't turn them off from the command line - even if it was controlling both lights fine before the last reboot. Or, unplug a light that's on, and then the Pi can't control it when I plug it back in in the exact same spot. So, if you haven't already, try using the disconnected remote to turn the lights off, then boot up the Pi. Maybe unplug everything and plug it back in while you're at it (can't hurt, right?).

2. A vague hunch that it's a power issue, especially when you mention your LED flickering. I'm actually powering my Pi from this powered USB hub (I combined this build with a RetroPie and didn't want to have two power cords). That hub can provide 3A total split between 7 devices, which should be more than enough for the Pi and the remote - but things seem to work more consistently when the Pi is powered off certain ports more than others. I'm not sure if there are internal limitations on the hub where some of the ports have current limits and are only intended for low-power devices. Regardless - can you try just running the breadboard's power bus off a completely separate power supply? Either a 5V USB source, or 4.5V from a 3xAA battery pack (should still be recognized as a logical high)? I'd be surprised if the remote is drawing more current than the Pi's +5V supply can provide, because as far as I know that comes straight from USB...but who knows. If you do that, make sure the other power supply still shares a common ground with the Pi.

Ben Finio (author)  mikerbob2 months ago

Honestly I'm stumped then. Comparing your image to this one from my project, it does look like the layout of your board's traces is slightly different, but ultimately all the same pins go to the same buttons.

How about making sure we actually have the same chip? You can't really see it in my photos, but mine has AUT980202-B printed on the top. Maybe there's something else going on with your board that my tutorial doesn't account for at all...

My only other guess would be to somehow read the RF signals, but I have absolutely no idea how to do that because I have zero experience working with RF. Assuming you find some way to decode/read/whatever the signal when each button is pressed, then you could compare that to the signal when you drive it using the Pi (or see if it's even generating an RF signal at all). Again, not a clue how to do that myself, but I'm betting there's an Instructable on it somewhere...

Last question - are you testing it under the exact same conditions when you push the buttons and when you use the Pi? Same outlets, same range between the remote and the outlet, etc? My remote is a little finicky sometimes, so just a thought.

mason101982 months ago

To automatically set the GPIO's as outputs and auto-run the "voicecommand -c" command, you can visit this link for a quite easy way to create a startup script.

Easy startup script to run every time your RasPi boots:

Create a file for your startup script and write your script in the file:

$ sudo nano /etc/init.d/superscript

Save and exit!

Make the script executable:

$ sudo chmod 755 /etc/init.d/superscript

Register script to be run at startup:

$ sudo update-rc.d superscript defaults

All done!

Easy startup script to run every time you login:

Make sure you are in the pi folder:

$ cd <mypifolder>

Create a file and write a script to run in the file:

$ sudo nano superscript

Save and exit!

Open up .bashrc for configuration (still in pi folder):

$ sudo nano .bashrc

Scroll down to the bottom and add the line: ./superscript

Save and exit!

All done!


JamesKay3 months ago

Thanks for the reply, although I'm sure it is a push button remote, the switch on the back is used to change between different channels that the sockets might be operating on. Here is some photos when the casing and the silicone is put back in place.

1010722_713220832055973_763489535_n.jpg1525540_713220812055975_1743497023_n.jpg
Ben Finio (author)  JamesKay3 months ago

Whoops. Look like I couldn't have been more wrong then. Someone with a better EE background can probably recognize this easily and give you a better answer. My assumption is that the 8 buttons on the front line up with these 8 pads on the circuit board (see picture below). Can you post a picture of the back side of the top half of the remote case, so we can see what the backs of the buttons look like? I'm guessing they press against the board, somehow changing the resistance (or maybe capacitance) of those traces, which is what gets measured...but I could be totally wrong (again).

If you don't get a good answer here, maybe head over to the Tech forum and ask there?

buttons.jpg

Here is a picture of behind the buttons.

1560549_713305325380857_323901794_n.jpg
Ben Finio (author)  JamesKay3 months ago

Ok - so looks like it is just rubber pads that press directly against the circuit board. Again, I'm not the right person to ask but my best guess is that this changes the capacitance or resistance of the traces on the board, and this gets detected by the chip. If you have a multimeter, you could still just test what happens to the voltage at each pin on the chip when you push each button.

If you find answers elsewhere please let me know how it works, I'd be curious to know.

I'll try that thanks :) then if I can't figure it out I'll post in the forums

JamesKay3 months ago

My remote looks like this, could anybody help me to try and figure out how this would work?, Thanks

1510814_712724078772315_1344683086_n.jpg1511179_712724048772318_751061554_n.jpg
Ben Finio (author)  JamesKay3 months ago

Ok - so it looks like you have a toggle switch instead of a pushbutton switch. Can't say 100% from the picture but it is probably something like this: https://www.sparkfun.com/products/9609. It has three pins - my guess would be that the two outer pins are connected to HIGH and LOW (whatever those voltages happen to be for your remote), and the middle pin toggles between the two depending on the position of the switch. The middle pin of that switch is probably connected to one of the pins on the chip (the black rectangle on the back of the board) - you can figure out which one either by looking at the circuit traces, or using a multimeter. I give more details about that here. Can't tell you for sure which one it is just by looking at the pictures, I would need to be holding the remote in my hand.

So, you need to figure that out, and then follow my procedure as usual. The only other difference will be the code - you will need the GPIO pin to stay high (or low) when you want the lights on (or off), since the remote has a slide switch and not a pushbutton switch. If that doesn't make sense or you need help editing the code, just let me know.

vvjunk3 months ago
I think the relay and mosfets are an overkill. I think a 4 channel optocoupler ic can replace all those relays and mosfets. Here is a link to optocoupler: http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_878286_-1 -V
n8icus vvjunk3 months ago
I'm pretty new to circuit design, but I think I understand how the optocoupler works. Could you elaborate a little on how you would replace the 6 relays with the optocoupler.
vvjunk n8icus3 months ago

Here is the circuit. You totally need 6 channels. You can get two 4 channel optocouplers.

Here is another link to optocoupler

http://www.newark.com/avago-technologies/acpl-847-...

-V

pi to remote.jpg
vvjunk vvjunk3 months ago

Actually in this circuit, we are not isolating the pi from the remote. Since the remote pins need 5v and 5v is not available on the remote (only 12v is available), author is taking 5v from Pi. Since we are not isolating, you can as well use an NPN transistor array or individual transistors.

Ben Finio (author)  vvjunk3 months ago
That link gave me an error but I just searched "optocoupler" on Jameco and think I found what you mean.

Honestly I've never used an optocoupler before, so this is news to me, but if you're right, that would make the circuit much simpler (and cheaper).
nerys3 months ago
any way to simplify this? I don't want to say "pi" first and I don't want it talking back to me. I want to make it super "star trek" simple. I want to come into the room and simply say "lights" and have the lights go on. say "lights" again have them go off. IE simple voice keyword toggle.

Suggestions?
To combine what Ben Finio and chrwei say, you need to create a script and then change the voicecommand config file.

You need to change the voicecommand config file to have the following:
!quiet==1
!verify==0
lights==flick_lights.sh
light==flick_lights.sh

This will turn off the keyword and the response (i.e. it will never call tts because it is in quiet mode). Then you just need to create a sh file in /usr/bin/ or /usr/local/bin named flick_lights.sh (make sure to chmod +x it to make it executable) that sets a variable in memory with /dev/shm/ (can't use an environmental variable in this case) and then flicks the lights appropriately. Your script might look like this:

#!/bin/bash

state=`cat /dev/shm/lightstatus`
if [ $state == "ON" ] ; then
gpio write 1 1 && sleep 1 && gpio write 1 0
echo "OFF" > /dev/shm/lightstatus
else
gpio -g write 0 1 && sleep 1 && gpio -g write 0 0
echo "ON" > /dev/shm/lightstatus
fi

Ben Finio (author)  StevenHickson3 months ago
Hi Steve - just wanted to say thanks for chiming in, and thanks for putting together Voice Command in the first place (obviously this project wouldn't be possible without it).
chrwei nerys3 months ago
to make it a toggle, instead of calling the gpio command directly, call a script that can tell the current state and issue the appropriate gpio command. I know on an arduino you can digitalRead() a pin that's set for output to get its current state without keeping a tracking variable around. maybe wiringPi can too.
nerys chrwei3 months ago
or just use a wireless remote that does not have separate on and off but a single button and let "it" worry about the toggle.

I think my easiest bet would be some voice rec device that would simply trip a relay and I use that relay circuit to "trip" the button on the remote turning the light on and off.

Just got to figure out how to do it and find the time to mess with it.
Ben Finio (author)  nerys3 months ago
Yep, that'd work too - here's a 3-channel remote that just has a single toggle button for each channel:

http://www.amazon.com/Outlet-Wireless-Remote-Wall-Outlets/dp/B000G80V28
Ben Finio (author)  chrwei3 months ago
fyi, that won't quite work because the GPIO pins do not STAY high while the lights are on. They briefly toggle high then go low again, the equivalent of pushing and releasing a button. If the pin stayed high that'd be like holding the on button down the entire time you wanted the lights to be on, which you don't need to do. So, even if there's a digitalRead() equivalent for the RPi, you would always just read LOW.
Ben Finio (author)  nerys3 months ago
Sorry - didn't fully read your comment and see what you want to just use the command "lights" to turn the lights on OR off, depending on their current state.

To do THAT, you would actually need to edit Steve Hickson's underlying C++ code, and not just the config file. The config file is a simple text file you edit to assign actions to command words, and you can only assign one action per word. As far as I know, there is no way to use an IF/ELSE statement to tell it what to do using a single keyword depending on whether the lights are currently on or off (e.g. "If I say lights and the lights are off, turn them on. If I say lights and the lights are already on, turn them off).

So, if you really just want to say "lights" and not "lights on" and "lights off", you either need to know what you're doing in C++, or should contact Steve Hickson directly (I think his email is on his blog somewhere).
 
Ben Finio (author)  nerys3 months ago
Yes - see http://stevenhickson.blogspot.com/2013/06/voice-command-v30-for-raspberry-pi.html. There is a "verify" variable in the config file that determines whether or not the program listens for a "keyword" before doing anything. The default keyword is "pi" but you can change it to whatever you want, and if you want to turn it off completely you just set "verify" to 0 instead of 1:

!verify==0

I don't know if you can actually turn off the "response" (e.g. "Yes, sir."). You could try running the program like this but it might give you an error:

!response==

Or you could try setting it to something that doesn't actually have a pronunciation on its own, like a period:

!response==.

If you don't want it talking back to you, just delete the tts (text-to-speech) commands in the config file, e.g.

light one on==tts "Yes, sir." && gpio write 0 1 && sleep 1 && gpio write 0 0

becomes

light one on==gpio write 0 1 && sleep 1 && gpio write 0 0

Remember that the overall risk of not using a unique keyword is that you will accidentally trigger the commands during normal conversation, or by someone on TV saying "lights off", etc.
tony18m3 months ago
Why go to all this trouble of wiring relays and drivers to push buttons on the transmitter when the wireless remote switches can be controlled by a few inches of wire acting as an antenna and providing the 3rd harmonic of 145MHz from the Pi's internal clock generator. The code has been around for a year now. See PiHAT - www.raspberrypi.org/phpBB3/viewtopic.php?t=26485‎. I have added to it for control of the very cheap Status remote switches which at one time were available at Morrisons supermarket at £5 for three! I have yet to take the RF transmitting code and add extra complications like the ability to drive an Arduino MPE development system (they dont yet work together) but the command line driven interface works OK, so I'm sure it can be combined with the voice recognition code here.
Have fun
Tony
Ben Finio (author)  tony18m3 months ago
I got a very similar question when I posted this to r/raspberry_pi on Reddit. A couple reasons:
  1. This project was originally inspired by this Instructable, which hacks a multi-channel remote in a similar manner.
  2. Honestly I'm pretty new to the Raspberry Pi and I have zero experience working with RF circuits. So even if this approach seems very roundabout to you, it was probably easier for me - I didn't think it was a lot of "trouble" to build the circuit.
  3. Either way, for me Instructables aren't necessarily about the easiest/best way to do something. I think it's a cool learning experience to crack the remote open and get a basic idea of how it works, especially for a novice.
tony18m Ben Finio3 months ago
Hi Ben
Thanks for taking the time to reply. I fully appreciate what you have done and of course it can be used in plenty of different ways. Sorry to have used the word "trouble" in my post - its just that within its limitations the PiHAT idea is a brilliant way of using a very low cost computer (The Raspberry Pi) with a nearly zero cost addition, which to me keeps to the spirit of the original design. Radio frequency encoding of the clock generator in the Pi is being used in all sorts of ways - eg world wide propagation beacons (WSPR)
cheers
Tony
Ben Finio (author)  tony18m3 months ago
Ah, got it. So if you actually want to minimize cost for a practical home automation system, and not drop $20 on some unnecessary circuit components just for the sake of learning something, PiHAT probably makes more sense.

I'll put a note at the beginning of my procedure that people should scroll down and check out the comments for alternative ways to do this.
srmutt3 months ago
thak you
skexie3 months ago
This is so much cleaner than the one I did with an Arduino. I also like the addition of the voice commands. Now I need to tear mine apart and rewire based on your diagram. However, I used NPN switches instead of relays. It takes up a little less room. See below:


http://www.instructables.com/id/Arduino-Remote-Control-Lights-with-Universal-Remot/
Ben Finio (author)  skexie3 months ago
Cool how it looks like you went through a very similar process of reverse-engineering the same remote. Mine actually uses relays and MOSFETs, because the Raspberry Pi couldn't provide enough current to drive the relays directly...I think I briefly tried just using MOSFETs without the relays and it didn't work (although I might have been doing it wrong).

Someone, somewhere has to make a complete Raspberry Pi buffer board, but I haven't seen one yet. Of course, if you want a good learning experience instead of just the quickest/easiest way to do it, then building your own circuit is a better way to go.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!