Computer Control of AC Devices




If you have ever wanted to control electronic devices from your computer to control or regulate your environment, this instructable will guide you. In this example of computer control, a USB relay device (USBmicro - U451) will control two 60 watt light bulbs from a PC program.

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: Safety First!

First off - Any time that you work with 120V voltages, safety is paramount. If you are not comfortable working with mains power, please seek the assistance of someone who is.

This instructable is intended only for someone experienced and confident in wiring high voltages. Do not attempt to do this if you are not. Household current can kill or badly injure you if you who do not understand the danger.

Only the U451 relay contacts should be used for control/connection to 110V AC. The relay screw terminals are isolated from the other circuit connections. DO NOT touch the U451 when there is 110V AC present.

Step 2: Major Parts

The major components used for this example instructable are:
  • USB relay interface USBmicro U451
  • two light bulbs
  • lamp sockets
  • 110V AC cord
The example project will control two independent 110V AC lights with the two relays on the U451. The U451 and lights will be mounted on a wooden plank.

Step 3: Project Mounting Board

The lamp sockets are placed on either side of the wooden plank used for this project. The location of the lamps are copied to the plank and traced with a pen. A center line is drawn through the circle to aid in mounting the lamps.

Step 4: Board Parts

Four adhesive-backed felt pads are added to the bottom side of the board. This will prevent the board from scuffing the surface that the board is placed upon.

The lamp sockets in this example setup will rest on some washers to provide some space for the wires that lead out from the under side of the socket and to the U451.

Step 5: Mounting Lamps

The lamp sockets are positioned and the screw locations marked with a pen. The screws and two washers are added and partially screwed in place. The lamp sockets loosely mounted as a "dry fit" just to see that they fit in place nicely.

Step 6: Mounting the U451

The U451 is mounted next to the lamps with small standoffs and #4 screws. Pictured are the two 3-screw headers - one for each relay.

Step 7: Wiring Parts

Because of the high voltage and current involved with this example, you must use a wire of sufficient diameter. In this case 16 gauge will suffice.

Step 8: Hot Wire Connection to the U451

The pair of wires from the two-wire plug consists of "hot" and "neutral" represented by black and white respectively.

Hot connects to each of the two common "c" terminals on the U451. This example project uses a wire nut to make the connection from the single source hot/black wire to the two pigtail wires that lead to the U451.

Step 9: Connections to Lamp.

The neutral/white connection is split into two wire pigtails that connect to the lamp socket (silvered connection).

One black wire connects from the N.O. (normally open) screw terminal connection on relay 1 to this lamp socket (brass screw on socket) while the other lamp socket connects in a similar way to the N.O. connection for relay 2.

Step 10: Lamps and Bulbs.

Mount the lamp sockets, tighten the screws. Install the light bulbs. These test bulbs were incandescent. Other more energy sensible light bulbs could be used.

Check your wiring. Once you are sure about the 110V AC connections, attach the USB cable to the U451 and your PC. Plug the AC plug into an outlet.

Step 11: Very Simple PC Programming

This project is brought to you by the magic of RobotBASIC. RobotBASIC (RB) is a free programming language and IDE (integrated development environment). It has support for controlling the USBmicro U451.

RB is free. FREE! You can write a program in the RB IDE and then save it as an .exe - a stand-alone executable that doesn't need the IDE to run. The USBm.dll is needed to go along with that file, but that is free, too.

I'm not going to get into the details of the program in this instructable. The entire program is the 35 lines in the image below. The program is easy to copy into the IDE and simply run. Here is the program as text: (note the spacing gets screwed up.)

// U451 relay control program

// If the DLL is found...
if usbm_DllSpecs() != ""

// And the device is found...
if usbm_FindDevices()

// Initialize the U451, outputs
n = usbm_DirectionB(0, 0xFF, 0xFF)

// Create title and two checkboxes for the relays
xyText 10,10,"Relay 1 Relay 2","",20,fs_Bold
for i = 0 to 1
addcheckbox "" + i, 10 + 120*(1-i), 60, " "

while true
for i = 0 to 1
if getcheckbox("" + i)
n = usbm_SetBit(0, i+8)
n = usbm_ResetBit(0, i+8)
delay 100

print "There are no Devices"
print "The USBmicro DLL is not installed"


Step 12: Running the Program

When the program runs you are presented with two boxes that you can click on or off. If everything works the bulbs follow suit!

Step 13: Let There Be Light!

You now have control of two lights in this example instructable.

This setup could easily be modified to control the power to almost anything that plugs in. And RobotBASIC ( can be used to make much more complex programs that, for instance, turn on electric devices based on a complex PC schedule.

Let there be light bulbs. :-)

Step 14: Updated: Instead of Wiring the Lamps Directly...

...wire the relay into your own outlet.

Please see the specifications for the U451 for limits to the current for the devices you control.

USB Contest

Runner Up in the
USB Contest

Be the First to Share


    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    50 Discussions


    Question 10 months ago on Step 14

    Is it possible to do a 220 Dryer outlet to this? Or is there a relay that would handle a 220 outlet?


    Question 1 year ago on Step 10

    Created an EXE file from the text in the article. Connected my USBmicro U451, which the Windows XP operating system recognised ok, but the EXE just flashes very quickly on screen and disappears before I have time to read any error message etc.

    How do I troubleshoot this please?

    Helma MariaT

    3 years ago

    What is the easiest/cheapest way to controll 240 light bulbs?

    1 reply
    indestructableHelma MariaT

    Reply 3 years ago

    The obvious solution of using 120 U451 is a bit painful.

    Better solutions depend on your electronics construction skills. A single U451 can drive 6 more relays directly from the J4 connector. So now a solution would involve 30 U451s plus relays. J1 can't drive the coils of relays directly, but with some transistors could control 8 more relays, cutting the number in half.

    You can buy boards on ebay that have 8 relays on them. The boards are $7-10. They can be controlled by a USBmicro board that is similar to the U451 and so one U421 could control 2 of these 8-relay boards. So 16 relays controlled by each U421 would be 15 sets of these controllers.

    Instead of mechanical relays, you could also use solid state relays.


    4 years ago on Step 14

    Just a heads up. The plastic covers used are intended to be flush mounted against a wall since they aren't structural. For exposed boxes you need the metal covers that don't extend past the junction boxes themselves.


    5 years ago on Introduction

    wHi, what woudl I need if i wanted to control 4 lights??


    8 years ago on Step 13

    what sholud i use if i want 220 v??


    8 years ago on Introduction

    Here No steps are given about how to connect this with computer? Can you explain this!!!!!!!!!!!!!


    Reply 9 years ago on Introduction

    sry for the broken link:


    9 years ago on Introduction

    Awesome! This might be interesting to you: we created an inverse of this idea where you can use the A/C device to control the computer. Some documentation here:


    9 years ago on Introduction

    Hey nice!! Can you think of a way to add current load monitoring to this... It would be cool to be able to create software to mon current load and control lighting and other circuits based on time of day and power consumption??? Any thoughts would be appreciated!

    1 reply

    Reply 9 years ago on Introduction

    You can build your own current sensor with this instructable: