Wifi Enabled Outlet with VoCore

We have an older Mr. Coffee without all that newfangled technology like a clock and timer which means getting out of bed to start the coffee pot. How can one turn on a coffee pot without leaving the warmth of cozy sheets? Add a VoCore, some LED’s and relays to a surge protector/USB charger, that’s how.

The shell is a cheap 3 outlet surge protector with a built in 2 port USB 5V 1A charger. I don’t have any before photos but you can probably imagine what it looked like. The USB ports were removed from the charging circuit and the board cut to allow space for the two manual switches on front. The board at the top of the shell is the surge protection circuit and only half the board was populated (maybe it’s also used in other units with more outlets?) so I cut off the unused section to allow room for the relays. Two Omron G5SB-14 relays allow the VoCore to control the left and right outlets. Each relay can handle 5A up to 240VAC. The center outlet is always enabled. Two green LED’s at the top light up when the corresponding relay is on. The LED cathode (via resistor) are connected to the relay and the anode always connected to 5V. It’s basically the same relay circuit used in the Zipit Z2 Breakout board but with through hole components (and added LED). I drilled a few holes on the back that will hopefully let some of the heat produced by the VoCore escape from inside the shell.

The VoCore is powered by the 5V 1A circuit. Four GPIO’s are used; one for each relay and one for each switch. The switches are wired to ground (via 10K resistor) and the GPIO on one side. The other side is connected to 3.3V. I also wired up the UART TX,RX,GND pins to a debug port on the side for easy access. When plugged in, the VoCore automatically connects to my access point and is assigned the same IP. There is a startup shell script that sets up the 2 relay GPIO’s for output and 2 switch GPIO’s for input. Another shell script polls the switch GPIO’s enabling or disabling the relay if pressed. Lighttpd is serving up a simple webpage with current status and on/off buttons for each relay. The relay GPIOS are triggered using the file_get/put_contents() PHP functions through sysfs so the www-data group must have read/write access to the “value” file for each GPIO.

I’m happy with how it turned out. Looks good on the outside and works on the inside. It’s not very secure at the moment, but I plan to tweak things a lot more on the software side. One feature to be added is a timer/schedule/calendar interface. Maybe I’ll add a RTC.

You can view the PHP code I’m using here.

GPIO Setup

#!/bin/sh
#Setup GPIO’s

echo “out” > /sys/class/gpio/gpio19/direction # Relay 1 output
echo “0” > /sys/class/gpio/gpio19/value # Relay 1 OFF
echo “out” > /sys/class/gpio/gpio20/direction # Relay 2 output
echo “0” > /sys/class/gpio/gpio20/value # Relay 2 OFF
echo “in” > /sys/class/gpio/gpio21/direction # Switch 1 input
echo “in” > /sys/class/gpio/gpio17/direction # Switch 2 input

#Allow www-data group read/write access to our relay gpios
chown root:www-data /sys/class/gpio/gpio19/value
chmod g+rw /sys/class/gpio/gpio19/value
chown root:www-data /sys/class/gpio/gpio20/value
chmod g+rw /sys/class/gpio/gpio20/value

Shell script to toggle relay when switch is pressed

#!/bin/sh
# Infinite loop to watch on/off switch for relay

sw=21 # switch gpio
relay=19 # relay gpio
echo “Starting Relay $relay / Switch $sw Trigger” > /dev/ttyS0

while true; do
 val=cat "/sys/class/gpio/gpio$sw/value"
  if [ $val -eq 1 ]; then
   # Switch pressed, toggle relay
   relaystate=cat "/sys/class/gpio/gpio$relay/value"
   if [ $relaystate -eq 1 ]; then
    echo “Turning relay off (GPIO $relay)” > /dev/ttyS0
    echo “0” > “/sys/class/gpio/gpio$relay/value”
   else
    echo “Turning relay on (GPIO $relay)” > /dev/ttyS0
    echo “1” > “/sys/class/gpio/gpio$relay/value”
   fi
   # Catch the switch release
   while [ $val -eq 1 ]; do
    val=cat "/sys/class/gpio/gpio$sw/value"
   done
   sleep 1 # wait just a sec to prevent unwanted press from fast fingers
  fi
done

5 comments

  1. I did the same thing with an electric imp. http://tinkeringetc.blogspot.com/2013/12/electric-imp-controlled-120vac-relay.html
    Your solution is definitively cheaper though. The Vocore is a pretty sweet device.

    And I love your use of the surge protector. I got one for a Christmas gift and I am in the middle of a project that is a perfect fit for it. I might just use it for that. Thanks for the idea!

    Dillon Wed, 24 Dec 2014

  2. @Dillon, nice work. Would like to see how the new project turns out. The Vocore is very versatile with what it can do. Small, cheap, lots of I/O and features.

    mozzwald Wed, 24 Dec 2014

  3. I finally posted my project using your outlet idea. Thanks for the inspiration!

    http://tinkeringetc.blogspot.com/2015/01/spark-lamp.html

    Dillon Tue, 27 Jan 2015

  4. Hi, I tried to do the same, but gpio 19 & 20 makes a pulse after 4seconds from power up. Is it happened to you? Most of gpio pins change their state during boot. Even gpio 0 is changing its state during boot. Some kind of kmod is doing it. I tried several images and they were all same.

    — ruchira Mon, 9 Feb 2015

  5. @ruchira, You should use pull up or pull down resistors to prevent this problem.

    mozzwald Tue, 10 Feb 2015

Archives By Month

Tags