Better yet: Don't connect your Raspberry Pi / Arduino at all to mains electricity unless you use an opto-isolator, or you have training in designing such circuits.
In a device intended for hybrid hi/low voltage there is a clear gap between the high and low voltage components, and an isolation transformer or opto-isolator between them.
I have training in designing such circuits and I'd still use an opto-isolator.
This is not manufacturing. It's a one-off project. It's not a highly refined design. You don't have to worry about finessing a marginally lower build cost because of what it will mean in 10k unit quantities. Just use the opto-isolator.
An isolation transformer would be of absolutely no use here and the optoisolator would provide the same functionality that the existing relays on that board do.
I can't see how the PC board is laid out so I can't verify if there is inadequate separation between the control side and the isolated side of the relay (even so, you only need about 5mm separation to be minimally safe at 120V), but barring that, it's fine!
Yes, this particular device is not explicitly designed to deal with all the hazards of switching a high voltage load, but I don't see anything that leads me to believe that it's unsafe for that purpose.
Others have mentioned the Belkin WeMo, which seems to be the best solution for anyone who doesn't want to mess with circuits (though I have no experience with, so can't comment). Does anyone know if it is available in a 220v format?
But if you do mess around with RasPis or Arduinos for that, I can't stress how useful the PowerSwitchTail is http://www.powerswitchtail.com/Pages/default.aspx - you give it a low power signal, and it switches a high power one. They have a 220v version as well.
Thanks a lot for the link. I've been idly pondering a couple of projects that would involve switching mains power with a microcontroller, but didn't encounter anything like that at a price that made me want to consider it. You may have saved me from a fiery doom.
In fact if I had the free time then I'd build a binary display for page hits using a series of LEDs on a Raspberry Pi (sadly I have a million other projects going on at the moment - such as finishing my website so I can get hits to begin with hehehe)
This falls - as others have already commented - in the 'knows just enough to be dangerous' category.
Please use LEDs, don't even bother messing around with opto-isolators and so on unless you have experience with both mains electricity and designing safe circuitry.
This is what I used for a cool RPi + RFID + LED project this year, write-up coming eventually, here's a clip for now:
http://vine.co/v/bvZQVJLnemh - my example only has a few LEDs but in the final product I used strips with about 30.
This seems like a really great use for raspberry pi. I recently finished a project involving a pi + a relay to activate a door buzzer, written in javascript. It was surprisingly simple and straightforward.
Besides turning on lights, the cool thing about relays is that most things involving physical push-buttons can be taken apart and easily wired up to a relay.
Arduinos can (supposedly) host webpages, and pins can be powered or depowered by (properly parsed) HTML POST commands. Combining this with a relay means we can create WIFI website interfaces for anything that uses electricity.
The opportunities to improve current products are so endless that I become overwhelmed whenever I think about this. We all have the parts to do this today, but so few are assembling them.
---
Want to set an outlet to turn on or off at different times? No need to buy a timer, just goto that outlet's website on your WIFI LAN, and set it on a timer. Or you could depower the outlet to make it child-safe.
Are you going on a trip and you're afraid you left the toaster plugged in and your house might burn down? Just VPN to your home LAN, sign into your kitchen's website and have it power off all outlets.
Locked out of your car? Pull out your phone, securely sign into your car's website, and tell it to unlock the doors.
Power and depower garage door openers, sprinklers, RC cars, even industrial equipment from a simple web interface.
Couldn't agree more. I wrote a blog post about it a while back demonstrating my take on this. Here's common household appliances getting web interfaces that can be accessed with any smartphone by QR Code. No arduino or soldering mains current required. I think every electronic thing in my house should have a little QR Code next to it so I can just point my phone at it and get its interface.
Arduino or Raspberry Pi are kind of overkill for this ...
USB breakout board -> MSP430 -> LEDs/Buzzers/Whatever
You're talking somewhere around $14.
Yes, you'll need to know C or assembly for the MSP430 and likely a scripting language for the PC, but it makes a lot more sense than bringing in all of that horsepower to essentially get an I/O and light an LED.
Your solution works totally fine, but it also involves using an entire computer to run the thing, which may or may not be overkill depending on whether or not you already have a computer that can be dedicated to it. Personally, I prefer these kinds of projects to be self-contained.
We've had success with a WeMo and this project: https://github.com/issackelly/wemo which lets you control the WeMo switch from within your local network. A quick python script to query the database for new users followed by calls to on() and off() works great.
There are remote-controlled RF switches for $20 for four. The Raspberry Pi can send RF signalss to these switches. Unfortunately, I don't have an oscilloscope to reverse-engineer the signal for mine, so the most I could manage to do is turn them off (but not on).
That's a very safe way of doing these things. If anyone else knows how I can reverse-engineer the signal, I'd appreciate it (I also want to make the Raspberry Pi open my garage door, same deal).
This is when I feel envy toward engineers who can program hardware. I'm so involved with Ruby and HTTP and CSS etc. that I have negligible knowledge about Arduino, Raspberry Pi, and Beaglebone.
I don't even know where to start and whether it will be a fruitful exercise (i.e. will I be able to devote sufficient time to it to actually learn something worthwhile).
Anyway, this is a neat project and I wish you good luck OP!
With any of these three platforms you could be doing this project in an afternoon. Processing isn't any harder than Ruby. You can do it.
Check out http://Raspberry.io for some resources the python community put together to use Raspberry Pi
Check out makezine for resources designed for people who aren't even familiar with programming. It doesn't take much to get up to speed with some basic on/off circuits. With a little high-school physics or just some asking around of friends you can get custom devices going.
I built something similar recently to flash a light every time someone buys something on Creative Market (video here https://vine.co/v/bTnnTVmH5eD). I know nothing about mains electricity, so I pulled together an Arduino and a LED with a bit of socket work to get a green light flashing. Once someone completes a sale, a piece of Javascript is requested from a Node.js HTTP server I setup. The server then pings the computer with the Arduino plugged into it over UDP and the client sends a serial response to the Ardunio, flashing the light. It's pretty simple, but it was fun to get all the components together and learn more about hardware development. Since a flash of the LED is requested on every sale and the UDP responds pretty quickly, it acts as a great thermometer during high sales peaks.
I'm now in the process of abstracting the entire thing into a self-contained box that communicates over wifi and uses mains electricity. Hopefully I don't kill myself.
Nice one!
When I did something similar, I found the clicking sound of the relay more satisfying, than a lightbulb, so I eventually completely removed the lightbulb.
At the time I used MacMini, which was a tiny bit expensive for this very purpose (also not everyone in the office likes a blinking light 24/7) then eventually I came up with the following oneliner:
I built this for our company using IFTTT; we have a little blue siren that goes off when a user converts. It's powered by the production app sending an email to IFTTT which power cycles a Belkin WeMo. Very simple, and it works quite well (excepting for a 10 second or so delay between the conversion and the siren going off).
Mains electricity can KILL. Make sure you learn about safe shielding, connecting and grounding practices.
Above all, be extremely cautious!
I can't stress this enough.
EDIT: For more information: http://tubelab.com/Safety.htm