Another USB controlled 230V socket

The easiest way to switch on-off a 230V socket using an USB port is to buy an already made device, but if one has some hardware in the drawer and some spare time in a rainy Sunday, he can try to build it by himself.

The scope of this job is remotely switch on and off some instrument in the hamradio shack when I’m away, using the USB port of  an always-powered pc server.

Disclaimer: be careful, here we play with the main voltage. Proceed at your own risk and try to don’t kill anyone or burn something.

I used an USB-TTL adapter with the PL2303 chip, 0.65 euro included shipping on a web store (how they can do that?).

pl2303

The pins on the right side are +3.3V, +5V,  TXData,  RXData, Ground.
TXData and RXData are useless for this project, but their tracks on the PCB can be used to route different signals, on their path there are also two surface mounted bonus leds to monitor the status of the lines.
A little mod is needed. By using a magnifying glass and a cutter, the TXD and RXD pins have to be cut on the PL2303 chip. I have cut them from the top, keeping the blade close to the body of the chip then, with the soldering iron, it’s easy to remove the pins from the pads and connect 1-2 and 3-5.

pl2303pinspl2303dtrrts

After this mod, on the output plug  with the labels “TXD” and “RXD”, there will be two RS232 control signals, DTR and RTS, that can be raised/lowered at will.

This project uses only the RTS signal.

A mosfet (BSS138) is used to drive an opto-isolator to energize the 24V coil of a 2×8 amps relay.
The 24V are obtained directly from the mains, well I don’t like it so much, but this voltage is needed only for the relay’s coil, it isn’t worth a transformer, anyway in the little junction box there was not room for anything else…
This circuit is *LIVE*, no one  must be able to touch it when powered, it has to be placed in a plastic box or carefully isolated.Danger-Live-Electrical-equischematic_powusb

Most of the parts (capacitors, zener, resistors etc.) have been recycled from an old steam iron control board.

When connected to my Linux server, the PL2303 adapter is mapped as /dev/ttyUSBx, where x is a number depending the inserting order in the USB hub. I have a number of PL2303 connected to the pc, so it’s  highly recommended to create a static link to the port, whatever be the first PL2303 connected. The file /etc/udev/rules.d/serusb.rules has to be edited/created to contain a string like:

SUBSYSTEMS==”usb”, KERNEL==”ttyUSB*”, KERNELS==”1-2.1″, SYMLINK+=”ttyPOW”

This maps the port always to /dev/ttyPOW .
The number 1-2.1 is the position of the serial adapter on the USB hub. These RS232 converters have all the same serial number, so the only way to identify them is to insert always in the same USB port, easy. The hub position of /dev/ttyUSB0 can be obtained with the command:

udevadm info –attribute-walk –path=/sys/bus/usb-serial/devices/ttyUSB0

To move  DTS and RTS, for now, I use a minimal Python script created to test the signals, I think I will insert it as a cgi in the local webserver to permit any browser  to power on the instruments.
Here the script: dtrrts

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: