Switch 230V devices with Raspberry Pi

Switch 230v with Raspberry Pi Working with 230v mains can be dangerous. So, for hobbyists switching 230v devices can be a challenge. But with a special multiple socket adapter it's easy! Only a few components are needed to switch 230v devices with the Raspberry Pi.

USB multiple socket adapter

The main part of this project is a USB multiple socket adapter. There are mainly two types of this adapters out: We need a socket of the second type, the "hardware controlled" type. I use this one:

revolt Automatische USB-gesteuerte Steckdosenleiste Amazon.de 9,90 Eur (02/2014)

Interface to Raspberry Pi

The interface for a USB voltage controlled adapter is simple:

Interface Raspberry Pi to switch 230v

One GPIO of Raspberry Pi is used to switch a transistor. The transistor converts the GPOs output voltage of 3.3V to 5V and provides enough current to switch the relay integrated in the multiple socket adapter.
I've choosen GPIO15, but you can also use other GPIOs. I soldered SMD components directly onto the USB connector and fixed it with hot glue.

Control the 230V on Raspberry Pi

Prepare the GPIO, set it to output:
sudo su -c 'echo 15 >/sys/class/gpio/export'
sudo su -c 'echo out >/sys/class/gpio/gpio15/direction'
Switch on:
sudo su -c 'echo 1 >/sys/class/gpio/gpio15/value'
Switch off
sudo su -c 'echo 0 >/sys/class/gpio/gpio15/value'

Links

de Raspberry PI: GPIO