Home of TurboCNC, the best open-source CNC control around...
You are here:
Homepage -> Articles -> Relay control
|Latest release of TurboCNC is v4.01
released March 13
Relay control from the Parallel Port
The question of how to connect and control a relay from the parallel port came up recently from a user of TurboCNC via email. Here's how you can do it, even if you don't know a lot about electronics! You should be able to solder and recognize basic electronic components for this project.
If you can get all the information you need from that picture, congratulations! You're probably as well off as most second year EE students, without the headache-inducing math of course. If not, read on....
You'll need to round up some parts first. Head out to your local Radio Shack and pick up the following, listed in increasing order of probability that you have it already:
OK. Now we'll translate that schematic a bit. The colored stripes on the resistors are the coding for the resistance in ohms.
This is standardized, and everyone has a reference for this, or if you hang around trade shows enough you'll come across a nifty index card calculator or some such thing. Here are the codes for the ones we're concerned about:
220 ohms -- Red, Red, Brown, Gold (or Silver)
1000 ohms (1k) -- Brown, Black, Red, Gold (or Silver)
The transistor is a little trickier, since it has three pins. Hold it with the pins down, and the flat side facing you, like this:
As in the photograph, the pins are E B C from left to right (90% of the time). Many of them are labeled as such. If yours says E C B or something, then go with what the part says instead of what I'm telling you.
The particular relay for this project is a reed-relay, which puts the contacts inside a tube where you can't see them. The contact pins are at the far opposite ends of the device, and the coil pins are about a third of the way along the barrel.
Diodes usually have a circumferential stripe at one end that corresponds to the "pointy" end of the arrow in the schematic. Polarity matters!
The D-sub connector has tiny markings on it that number the pins on each side. If your eyesight isn't quite 20/20, just hold it so that the side with the largest number of pins is on top and the side the computer sees faces you, like this:
The pins go from LEFT TO RIGHT, 1-13 on top, 14-25 on the bottom. Pins 18-25 are ground, so be sure to connect them all to the ground line on the schematic. Use one wire to do this, stripping about an inch or so so you can just solder them all in a row.
Putting it together:
Go around the schematic building it exactly as shown. A good crutch when you're just starting out is to print the schematic out, and check off each wire as you connect it. Hook up the signal line to any convenient pin in the range 2-9 (I suggest pin 2). Be careful, and always take a break before double checking your work. The other end of the battery (black wire) goes to ground.
When you're done, it'll look something like this:
Testing it out:
WARNING: If you blow your motherboard plugging this in, I'm not responsible.
Now, plug it in, attach the 9V battery, and run FKEYBIT on your computer with one of these command lines according to the way your computer is set up:
. By pressing F8, and alt-F8 (if you used pin 2), the relay should go on. If you can't hear it clicking, you should be able to tell it's on by measuring the resistance of the relay contacts with a meter. Off will be infinite, on is near zero. Don't have a voltmeter? It's a crucial tool for electronics of all types, so go out and buy a good one.
What can you do with this circuit? Well, you probably could control coolant pumps or your machine spindle with a bigger relay. This one is adequate for a radio to wake you up in the morning, a 75W or smaller lamp, activating a PLC input, or something like that. But 1A doesn't go very far these days.
If you want to change the relay for a larger one, or change the input voltage to 12V or something appropriate for your machinery, you need to do some homework:
- The input voltage to the board must be higher than, or equal to the relay coil voltage.
- If it's exactly equal, get rid of the 220 ohm resistor completely and connect that side of the relay coil directly to the power rail.
- If it's higher (like in our case, where it was 9V in for a 5V relay), gather the following numbers:
Rballast = (V-VC) divided by (VC / R)
[(V-VC) times (VC / R) ] should be less than 0.5 or so. This is the wattage dissipated by the ballast resistor.
Substitute the closest standard value for the 220 ohm resistor in the schematic.
You've got to watch out that you don't go over about 0.5A or so with this circuit, or the transistor will burn up.
If you have a penchant for making things complicated, add an LED so that the state of the relay is indicated at a glance.
© 2001-2019 DAK Engineering.
All rights reserved.
This page last updated on January 11, 2015 .