Wireless Controller - 120/240 VAC
Posted: Sun Jan 12, 2014 1:08 pm
Here is a weekend project. I tried to make the code as readable and as simple as possible.
Either a MCP23008 or MCP23017 can be used. I had a couple of MCP23008 chips laying around so that is what I used.
The wireless remote fob has 4 buttons and their functions are:
A = On
B = Off
C = On for 10 Minutes then Off
D = On for 20 minutes then Off
Parts list:
315 mhz rcvr - Adafruit http://www.adafruit.com/products/1096
315 fob xmtr - Adafruit http://www.adafruit.com/products/1095
Solid state relay
2 x 10k resistors (optional but recommended)
mcp23008 - Adafruit http://www.adafruit.com/products/593
4x4x2 box
power receptacle
120 VAC plug and cord
Rpi Case - Adafruit
Either a MCP23008 or MCP23017 can be used. I had a couple of MCP23008 chips laying around so that is what I used.
The wireless remote fob has 4 buttons and their functions are:
A = On
B = Off
C = On for 10 Minutes then Off
D = On for 20 minutes then Off
Parts list:
315 mhz rcvr - Adafruit http://www.adafruit.com/products/1096
315 fob xmtr - Adafruit http://www.adafruit.com/products/1095
Solid state relay
2 x 10k resistors (optional but recommended)
mcp23008 - Adafruit http://www.adafruit.com/products/593
4x4x2 box
power receptacle
120 VAC plug and cord
Rpi Case - Adafruit
Code: Select all
#!/usr/bin/python
import os
import time
import sys
import smbus
address=0x20
bus = smbus.SMBus(1)
#setup chip
bus.write_byte_data(address,0x00,0xfe)
TMOUT=0
GM=0
while (True):
# read the inputs, etc.
GM=int(time.time())
res=bus.read_byte_data(address,0x09)
# uncomment next line for debugging
#print res
if res == 128 or res == 129:
bus.write_byte_data(address,0x09,1)
if res == 64 or res == 65:
bus.write_byte_data(address,0x09,0)
if res == 32 or res == 33:
bus.write_byte_data(address,0x09,1)
GM=int(time.time())
TMOUT=GM+600
if res == 16 or res == 17:
bus.write_byte_data(address,0x09,1)
GM=int(time.time())
TMOUT=GM+1200
if TMOUT == GM:
bus.write_byte_data(address,0x09,0)
time.sleep (0.05)
