FUN WITH LINUX

HackADay: Controlling power outlets using the Raspberry Pi

5 March 2016

My plan was to control some power outlets(16 ampere) using any browser(for example with a mobile phone). I wanted to use electronics only and tried to avoid relays.

Concept

I installed a Debian on my Raspberry Pi(including XBMC aka Kodi) on which a lighthttpd-daemon is running. This Webserver is calling a cgi-script(perl) which enables or disables the power sockets via it’s GPIO-Pins. To make it as easy as possible I just call the gpio-command from the WiringPi-Project. I really love to make things work automagically. That’s why I also included a function for enabling or disabling a socket at a specific time. Since I kept everything as simple as possible I just used a simple at-job for this.

GPIO

Raspberry Pi GPIO Pins

I am using the following Pins: GPIO23(socket 1), GPIO25(socket 2), P1-02 for 5volt power supply and P1-06 for ground.

Wiring

The most difficult thing was the wiring. As I already mentioned, I really wanted to avoid relays. Therefore I created this circuit: the GPIO-Pin controls an optocoppler(MOC3041) limited by a transistor(BC547). The optocoppler itself is switching a TRIAC(BT 139). The TRIAC enables or disables the power socket.

That’s the circuit:

Circuit

…and that’s how it looks like:

Programming

The Website is very very simple and looks like this:

Website-Screenshot

..very basic, isn’t it?

Don’t forget to change the sudo-rights for www-data:

/etc/sudoers:

www-data ALL=NOPASSWD:/usr/local/bin/gpio

You can find all the sources of this project on my github.

###
Final Words

This project was a lot of fun. I got much support at the Meta Lab(The very best hacker-space in vienna), The project works very well. I also implemented some (green)diodes for indicating if the sockets are enabled or not. And don’t forget that I really installed a full xbmc-system. That’s why my sockets are also a full multimedia center!!

[ Linux  Programming  HackADay  Raspberry  Hardware  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti