Introduction: Web Controlled Valentine
With this mix of software and hardware, you can light up a heart-adorned night light from anywhere with internet access. So whether you remember at work, in a cafe, at home, or on your (web enabled) cell phone, you can tell your valentine that you're still remembering.
(that, or you can annoy your sweetheart by rapidly pulsing the light throughout the day, until she manually turns it off)
UPDATE 4/16/07: NO MORE DELAY!
I finally wrote my own serial communications program, with the new code, the delay is gone.
Step 1: Gathering Materials
There are several ways of controlling an outlet from a PC, but since I had one lying around anyway, I based the project on an Arduino NG i/o board. ($32 from Sparkfun) All other parts were either scavenged, picked up locally at Radio Shack or bought at a grocery store; therefore, there are some messy hacks involved.
Don't let the use of the Arduino dissuade you from attempting this, or a similar problem. The Arduino is extremely straightforward and inexpensive.
Arduino NG - USB Prototyping Board
9vdc 350ma power adapter
USB male A-male B cable
computer power cord (or other suitable grounded cord)
three prong outlet, cover, and box
PC Relay - 12vdc coil rating rs part #275-248
Reed Relay - 5vdc coil rating rs part #275-232
diode (i used rs part #276-1620, but I had it lying around)
Heart-adorned night light
Arduino IDE from http://www.arduino.cc
Xampp from http://www.apachefriends.org/en/xampp-windows.html
ComSender - my serial communications program, php code, and Arduino code. (attached)
Step 2: Prepare the Relay
This is pretty simple.
Locate the pins for "coil"(2 pins), "common", and "normally open".
Solder heavy gauge wire to "common" and "normally open". These wires will carry 120vac, so I suggest a bit of the wire from the pc power cable. Just be sure not to take too much, a 3 inches is plenty.
Solder lighter gauge wires to the two coil pins, these will carry 9vdc at no greater than 350ma. choose which coil pin you want to be positive (it doesn't matter which yet) and choose wire colors appropriately so as not to be confused.
solder a diode between the two coil pins, so that the black line is on the side facing the positive pin. This diode helps to suppress voltage spikes from the relay due to induction on the coil.
Step 3: Build Outlet Box
Cut the female end off the PC power cable, if you haven't already, and thread the cable through one of the holes in the outlet box. strip the three internal wires and connect them as follows.
connect green to the ground connector on the outlet.
connect white to the neutral connector on the outlet.
connect black to the "common" wire from the relay.
connect the "normally open" wire to the live connector on the outlet.
Double check everything, this is 120 we're dealing with. Mistakes are bad.
tape everything up nice and tidy, to avoid shorts and make everything prettier.
Thread the coil wires through one of the smaller holes in the outlet box and connect the outlet to the box.
Step 4: Add Secondary Relay
I had hoped that at this point I could connect the relay to the Arduino and call the hardware done; however, contrary to initial tests, 5vdc (the output current of data pins on the Arduino) wouldn't reliably drive a 12v relay. I had to add a second smaller relay and tap into the 9v output provided on the board. This smaller relay switches 9vdc using 5vdc. that 9vdc then switches the larger relay.
solder wires to the leads at the two ends of the reed relay ("normally open" and "common"). plug one wire into the 9vdc connector, and connect the other to your positive wire from the larger relay.
connect the ground wire from the coil of the larger relay into ground on the Arduino.
the two coil leads from the reed relay should fit snugly in pins 12 and ground on the Arduino and hold themselves in place, as well as supporting the relay's weight.
Attach the Arduino to the outlet box, being sure to insulate with electrical tape. I used a rubber band to hold it on, but my method is by no means perfect.
Also, set the power jumper on the Arduino to EXT and plug it into the power adapter and USB. also plug in the PC Power cord, and plug the night light into the outlet
THIS CONCLUDES THE HARDWARE PORTION
Step 5: Install Software
If you haven't already, install XAMPP and the Arduino IDE now.
Also install the USB drivers included with the Arduino IDE and set the COM port accordingly in the IDE
Next, copy Sender.exe to C:\Sender.exe (or another convenient place, if you are willing to edit the PHP file) and copy MSCOMM32.OCX to your system folder (c:\windows\system).
Step 6: Program Board/Write PHP
I've included source code for the Arduino and the Server.
first open the PHP file and make the following changes:
set $path to the location of Sender.exe
set $port to the COM port the arduino is using
save the PHP file to the htdocs folder in your XAMPP directory as index.php
load the Arduino IDE and open the Arduino file. Press the reset button on the Arduino. Then, quickly press the transfer button in the IDE. Once the file has transferred, you're done.
Step 7: Test/Debug
open your browser, and go to http://localhost
you should see a page titled "outlet control".
If you don't, there's a problem with XAMPP. Make sure Apache is running, and that you didn't break PHP.
If you do, try the two buttons.
if after pressing "on" the night light turns on, and after pressing "off" it turns off, its all working well.
if it doesn't respond, check your choice of COM port in the PHP file.
if that doesn't help, there's commented debugging code in the Arduino file that makes the light blink on a five second interval... you can use it to debug your hardware.
now try on another computer... access it through the computer's IP address
If all goes well, you can now control the light anywhere in the world... think about adding a password.
happy valentines day.
p.s. if you're behind a router, you may need to use port forwarding to be able to access the page from outside your network. with port forwarding on, you simply use your router's public IP to access the page.
Step 8: Future Improvements
1) Get rid of the Delay
FINISHED - THE NEW PROGRAM HAS NO DELAY!
2) USB powered (use a better relay, and I can get rid of the wall wort
3) easier install
single step installs and small footprints are much better
4) Multiple outlets, multiple relays
can you say Christmas display
5) infra-red transmitter (let it control your media center)
7) figure out what "6)" was
8) better construction/case