Web Controlled Valentine





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)

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


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



  • Epilog Challenge 9

    Epilog Challenge 9
  • Gluten Free Challenge

    Gluten Free Challenge
  • First Time Author Contest 2018

    First Time Author Contest 2018

We have a be nice policy.
Please be positive and constructive.




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.

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




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

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


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

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)


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


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

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....

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