Super Easy PC Control of 110 Vac Using a Crydom Solid-State Relay

20,264

31

33

Founder of Powerhouse Electronics. For more info goto: www.ph-elec.com

Intro: Super Easy PC Control of 110 Vac Using a Crydom Solid-State Relay

I'm getting ready to try my hand at doing some hot plate soldering. Therefore, I needed a way to control 110Vac from my PC.

This instructable shows how to easily control 110Vac from a serial output port on a PC. The serial port I used was a USB type. Any standard serial port should work.

The idea is to connect the DTR (data terminal ready) pin from the PC serial port to a Crydom solid-state relay. The Crydom relay accepts a control signal of 3 to 32 volts to turn on the solid-state relay. The Crydom relay can also handle up to -32 volts on the control input to the relay. See attached datasheet.

Under normally conditions the DTR signal switches between +10 volts and -10 volts. This works out perfectly for the Crydom relay. The Crydom relay turns on at anything above 3 volts. Any voltage below 1 volt is guaranteed to turn off the relay. So, using the +10 to -10 volts of the DTR signal is perfect. The Crydom relay has a maximum load of 2mA on the DTR signal.

Switching the DTR under program control is also really easy. I've attached a little Python script that toggles the DTR pin every couple of seconds. The Python script is only 16 lines long!

To make the Python code work you will need to add an extra little package to Python called PySerial. I've also attached the windows installer for PySerial to this instructable. With a quick Google search, you can find PySerial on Source Forge easily too.

Step 1: Wiring Crydom

Caution! Make sure you tripe check everything when working with 110Vac.

The wiring circuit couldn't get much easier than this! The Crydom block is simply inline with the hot side of the 110Vac line. The neutral side passes right through. Pass the ground through too. But, also connect the ground to the heatsink/Crydom block to ground.

I know, I know, the wiring I used on the AC side is to small. I've got a really big Crydom relay (40 Amps!) so I should have some big mother wires. My house has 15 amp breakers so #12 wiring would be OK. I just grabbed an old PC cord and forgot how small the wires are. I think my wiring on the AC side is #18. So far I've just been playing with a 100 watt lamp, so no problem. I'll rewire before plugging in a big hot plate.

Step 2: Python Test Code

Below is the magic Python code. Again, can't get much easier than this. I've also attached the code in a file called "Test.py".

import sys, serial
from time import sleep

COM_PORT = 7
BAUD = 9600

ser = serial.Serial( COM_PORT-1, BAUD, timeout=0.5, rtscts=0 )

# Toggle the DTR pin on for 15 seconds, then off for 5 seconds.
while ( 1 ) :
print "On"
ser.setDTR( 1 )
sleep( 15 )
print "Off"
ser.setDTR( 0 )
sleep( 5 )

Step 3: Be Careful

Before I use this Solid-State relay I'm going to mount some Plexiglas over the AC side of the relay. The 110Vac can really bite so be careful!

Hope this helps - Thanks,
Jim

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Audio Contest 2018

      Audio Contest 2018

    33 Discussions

    0
    None
    infitom

    4 years ago

    You can control TWO things with two CryDoms: one using DTR (Data Terminal ready), the other using the CTS (clear to send) lines. Just a thought. I'm building a circuit in this configuration, that will first turn on the front light of a haunted house mirror, count 30 seconds, then turn it off, turn on the back light, and take a picture with a webcam:
    I'll sense the switch with one of the other serial lines.

    0
    None
    frankenp

    8 years ago on Introduction

    Thanks!  I just built a similar device to switch off my old analog stereo gear (no remotes) when I put my computer to sleep.  Just tapped into the 5V line on a spare PC power connector.  The hand drawn diagram was very helpful.

    5 replies
    0
    None
    jimk3038frankenp

    Reply 8 years ago on Introduction

    That is a cool idea.

    I wonder if I could use my laptop's USB port? I'm assuming it switches off too when entering into sleep mode. I could use that to switch off my space heater I use under the desk.

    Nice idea,
    Jim

    0
    None
    frankenpjimk3038

    Reply 8 years ago on Introduction

    My PC keeps the USB ports turned on during sleep.... so I had to use a power plug.  Some PC's keep their USB powered while others do not.  I like having USB powered during sleep because I can use my wireless usb keyboard to wake the PC.

    0
    None
    frankenpfrankenp

    Reply 8 years ago on Introduction

    Pics of my build mentioned above.  I used two small 3A relays one for each plug..  3 amps per plug is more than enough for my use and the relays fit nicely inside a two gang box.

    100_1108.JPG100_1112.JPG100_1113.JPG
    0
    None
    jimk3038frankenp

    Reply 8 years ago on Introduction

    Really nice. I like how everything gets packaged into a plastic box. Being a computer guy 110Vac always makes me nervous. Having everything sealed up is nice.

    One thing to watch out for - the 3Amp rating is only good for Crydom modules that have a heat sink / good ventilation. I learned the hard way that the large module must be bolted to a heat sink. I'm not sure about the small modules you are using. But, packing them inside a small box might be a problem. Based on your mounting, I would derate them down to 1 amp.

    Looks good,
    Jim

    0
    None
    cowen

    7 years ago on Introduction

    I know this is an old Able but what would a circuit look like if you would use a parallel port instead of serial?

    LPTs use multiple data lines (8) instead of the serials one line.

    By comparison you can use lpt1, 2, and 3 with just 3 cards, where you need a serial port for each control port. USB to serial dongles would allow for more then 4 easily added ports.

    Do you think you could email a simple .py file for that interface?

    Thanks

    1 reply
    0
    None
    jimk3038cowen

    Reply 7 years ago on Introduction

    This was really intended as a quick and easy way to control a single 110Vac device. I used it to control the temperature on an electric skillet while reflowing solder paste.

    If you want to control a bunch of outputs at the same time I would be inclined to use a Pic, MBed, Arduino embedded micro instead. With one USB connection you could control an unlimited number of output channels.

    Note, there are already these kind of devices on the market. Folks use them to control outdoor Christmas lights under computer control.

    Sorry I couldn't be more helpful. I've just never fooled much with the parallel port.

    Good Luck,
    Jim

    0
    None
    cgrooms

    8 years ago on Introduction

    I have another question for you! Is there any way you can have multiple replays on one serial and if so What pins would I use?. My goal is to control multiple lights. or is that not possible and you have to use two serials pins 4 and 5

    1 reply
    0
    None
    jimk3038cgrooms

    Reply 8 years ago on Introduction

    Nope, one relay per comm port. However, I can think of two options. You could use a small micro like a Microchip to control a bunch of relays on the comm port. That would make for a low cost solution. Or, you might want to look at an off the shelf solution. Do a Google on "vixen". Folks use that software to control Christmas lights. There are a bunch of relay boards that work with vixen. So, by searching on vixen you will find the relay boards. Good luck, Jim

    0
    None
    cgrooms

    8 years ago on Introduction

    Thanks so much for your help! I got it to work last night! I just needed for some reason to install python-serial and to specify what serial port I had to modify the code a little

    0
    None
    cgrooms

    8 years ago on Step 2

    Thanks, I fix that problem now I have this error File "temp.py", line 7, in ser = serial.Serial( COM_PORT-1, BAUD, timeout=0.5, rtscts=0 ) File "/usr/lib/python2.6/dist-packages/serial/serialutil.py", line 166, in __init__ self.open() File "/usr/lib/python2.6/dist-packages/serial/serialposix.py", line 175, in open raise SerialException("could not open port %s: %s" % (self._port, msg)) serial.serialutil.SerialException: could not open port 6: [Errno 2] No such file or directory: '/dev/ttyS6'

    1 reply
    0
    None
    jimk3038cgrooms

    Reply 8 years ago on Step 2

    Looks like your trying to open a serial port that does not exist. The easiest thing to do is to use another terminal program to verify which ports are available on your machine. Make sure the terminal app can successfully open the port - if the terminal app can't open the port then Python will also fail by throwing the exception you see in your error message. Edit the known good port name into the Python code and you should be good to go. Good luck, Jim

    0
    None
    cgrooms

    8 years ago on Step 2

    having the same problem getting errors File "test.py", line 8 print "On" ^ IndentationError: expected an indented block

    1 reply
    0
    None
    jimk3038cgrooms

    Reply 8 years ago on Step 2

    Sorry to hear your having problems. The Indentation Error is a common error.

    Python is kinda weird, in that, it's really picky about indenting in the source code. It drives Python crazy if you happen to indent with tabs and spaces within the same file. Either use spaces, or tabs, but never both in the save file. Some of the better editors have the ability to show tabs with special visible characters. Using this special mode you can verify you have not mixed spaces and tabs. To execute a block of code within some loop like a "while" loop, Python looks for an extra level of indention. The syntax would look like the following.

    while 1:

    print "Hello World"

    This loop would print forever to the console simple because "print" is indented under the "while" statement.

    Help this helps,
    Jim

    0
    None
    jimk3038Crimson-Deity

    Reply 8 years ago on Step 2

    What error are you getting? What line number does it complain about? Can you capture the error message and post it?

    0
    None
    Crimson-Deityjimk3038

    Reply 8 years ago on Step 2

    Thanks for the quick respons ! :D

    I have never, ever programmed ANYTHING before so I'm a noob to the max. Could you make a tutorial on how to use Python? I tried to copy and paste the "Test.py" content into the IDLE Python text thing, but some sort of error occured. My laptop is somewhere out of my reach at the moment so ill post a picture ASAP.

    0
    None
    jimk3038Crimson-Deity

    Reply 8 years ago on Step 2

    You have made a good choice with Python as a starting language. Python is kinda like a Swiss Army Knife for programmers. Python can be used to code really simple stuff. Or, full blown object oriented code.

    Anyway, step number one - go out and buy two books. Learning Python and Python Cookbook. These are really good to get you jump started. I've attached a picture of my two books. You can see my books are kinda beat up - that is a good sign - means the books are used a lot!

    Next, try to run my little code block. I'm guessing your missing the extra serial port package. Python does not have support for serial ports by default. No problem - go back to my instructable and download the extra installer for the serial port package. This package adds serial port control to Python.

    Next, run each line of code in IDLE. IDLE will tell you when you hit a problem. But, once you install the serial port package I guessing you won't have any problems.

    Good luck,
    Jim


    DSCN1110.JPG