Web Controlled Valentine




About: I'm a self proclaimed renaissance man. My goal in life is to have a conversational/practical knowledge of every subject known to man. I do graphics design in my spare time, along with make-ing.

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)

I finally wrote my own serial communications program, with the new code, the delay is gone.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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


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

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

The Instructables Book Contest

Participated in the
The Instructables Book Contest



    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    19 Discussions

    Hi - this is pretty great, but when I run the php on apache I see the web page with
    "Notice: Undefined variable: submitted in C:\xampp\htdocs\index.php on line 51
    Outlet State is Unknown "
    and if I click a button
    "Fatal error: Class 'COM' not found in C:\xampp\htdocs\index.php on line 27"

    It *looks* like everything is defined? I'm unfamiliar with PHP but the arduino seems to be setup alright.

    1 reply

    Reply 5 years ago on Introduction

    Problem is that in new version of php COM class is not used.

    You have to include php_com_dotnet.dll which you already have in

    XAMPP\php\ext folder into apache php.ini file

    Go to Xampp config screen, then hit config for Apache server and choose PHP(php.ini) file and edit it.

    Scroll until you find ; Dynamic Extensions ; and add




    9 years ago on Step 6

    can you tell me what part of the xampp server your using cause i can only get ftp and apache working

    1 reply

    Reply 9 years ago on Step 6

    Apache+php (which is what xampp contains) is all you need.


    9 years ago on Step 6

    I really wanna do this project but I got 2 questions...... What is the php code and what code do I have to upload to my arduino......thanx

    2 replies

    Reply 9 years ago on Step 6

    the php code, along with the exe file and the ocx file, reside on the computer the arduino is connected to... they take care of turning web requests into serial communication to the arduino... the arduino code (the.pde file) is what goes on the arduino to read the serial transmissions from the computer and operate the relay accordingly... all the files are in the zip file attached to the first step (the arduino code is in the arduino subfolder)


    Reply 9 years ago on Step 6

    Wow......thank u so much........you cleared up everything so fast, keep up the good work!!!!


    9 years ago on Introduction

    can you post a method that give us to control more leds? or more outputs?

    please...I've tried but.... didn't work form me....

    works fine with 1 output..

    great instructable....

    please make the same idea with 8 or more outputs!!!!! T_T


    10 years ago on Step 1

    That's a great Instructable!!! I understand all the hardware construction parts but do you know if I could do it with a basic stamp 2 module? because I have one lying around....

    1 reply

    Reply 10 years ago on Step 1

    you definitely could, but since I haven't used that board for several years, I'm not sure what the code would look like.


    10 years ago on Introduction

    This is amazing and I really want to give this a try but I'm having trouble finding some of the supplies you used at a good price. Are there any alternatives?


    11 years ago on Introduction

    Hi, Funny thing... I kinda made the same thing... But its a USB powered white PLexyglas cube, with LEDs inside. The cube is constantly fading colors Then the 2 ppl have a program running on their PC, when either one is thinking about the other the fading stops and the cube turns red (you can change the color in the settings) I use ICQ to send the message through the internet, that way I dont have to bother about a server or anything... I will eventually post an Instructable here, when I can find some time. Mike


    12 years ago

    This is really cool. I have been wanting to mess around with controlling electronics over the internet. is there anywhere i should look that can give me the basics? I sorta understand what is happening, but i cant find a site that explains it out.


    12 years ago

    If you want to save the price of the USB board, you could just use the LPT port to drive the reed relay.


    If your looking to make a portable ethernet connected setup, I would check around for Nano ITX boards.


    I have a few of the EPIA boards laying around. you can power them from a regular 12V wall supply, and they have built in Ethernet. Many still have pin headers for LPT connections.

    1 reply

    Reply 12 years ago

    I kinda like the idea of using parallel, but most newer computers don't include it and most usb adapters can't be easily fiddled with (as I learned making a snes multitap/usb adapter)... I went with the Arduino for several reasons: 1) uses TTL to communicate, so any stand alone Ethernet controller can talk to it. 2) my arduino is usb and can easily become serial (with a max2322 and some caps) so use with both older and newer pcs is facilitated 3) Cheapest dev board I know of that has its powers 4) ethernet arduino is forthcoming 5) I already had one :) if i was going for a stand-alone setup, I'd use a less pricy/overly complicated solution than a nano itx pc... come on, ~$400 for an outlet control? i can do better. using an old thinkpad 365 (i think), a max2322 chip, three 1microfarad caps, and this setup, I've got a stand alone unit for ~$150, and thats without trying to be efficient or dedicated (BTW: just make a serial to ttl-adapter, connect it to the arduino, and run everything normally). if I used a serial arduino to start with and bought a gutted laptop (no need for cd, harddrive(use a cf card with an adapter), internal display, ect), it'd be even cheaper. with a bit of eBay magic, it could be a cool $100. anywho, for my future plans an arduino fit nicely, and its a great piece of kit to have around (used for a usb morse key, universal computer controlled remote, winamp control, ect)


    12 years ago

    This is some awesome Valentine's Day technology. Now that you have a computer controlled power outlet you can make all kinds of remotely operated gifts and machines. Nice idea and instructable!

    2 replies

    Reply 12 years ago

    You could make sure your christmas lights were off, space heater wasn't running while your out, but most importantly... annoy/freak the bejeezes out of anybody!


    12 years ago

    the eventual goal is to rig it with an Ethernet or Bluetooth Arduino, if and when I get one, and use them for full home automation... btw, this cost apr. $40 to do this, and I can add outlets for ~$10 a piece. X10 wants 99 for just the usb controller