Interfacing RELAYs using the Parallel Port

If you haven't read my previous article "Basics of Parallel Port" then I would suggest you to read it first.



Introduction

In this article I will first tell you about how to build the Relay interface circuit for the Parallel Port and then how to control the circuit using software. With this very basic prototype you will be able to learn a lot how the parallel port works, how a relay works and the use of ULN2803 IC. So, I'll start with the circuit first.

Circuit Diagram

Interfacing Relays using the Parallel Port Circuit Description

Components Used:-
  1. One 12V Relay
  2. IC ULN2803
  3. 12V power supply
  4. DB-25 Male Connector
  5. Light Bulb
  6. Zero PCB
  7. Ribbon Wire
  • Connect the data pins(2 to 9) of the parallel port to pins 1 to 8 of ULN2803 IC.
  • Connect GND pin 25 of the parallel port to pin 9 of ULN2803 IC.
  • Connect one side of Relay coil to pin 10 and other side to pin 18 of ULN2803 IC.
  • Connect a bulb between common terminal of relay and neutral AC wire.
  • Connect the live AC wire to normally open terminal of relay.
  • Connect +ve terminal of power supply to pin 10 and -ve terminal to pin 9.
  • Your circuit is now complete.
Note - For 12 V power supply I have used the power supply of my computer system. Power supply of a PC has got 4 terminals, of which 2 are GND and the other 2 are +5V and +12V. I have used one GND and +12V terminal to give power supply to ULN2803 IC.

How the circuit works?

The circuit consists of two main parts - ULN2803 IC and a 5 pin Relay. Working of both of them is explained below:-

Working of Relay


A relay is an electrically operated switch. It allows one circuit to switch a second circuit which is completely separated from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. There is no electrical connection inside the relay between the two circuits, the link is magnetic and mechanical.

Relay Operation
In the above figure, when controlling switch is closed, current flows through the coil and thus, magnetic field is produced. The resulting magnetic field attracts an armature that is mechanically linked to a set of contacts. The movement makes a connection with a fixed contact and circuit gets completed. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position and the connection is broken.

The relay's switch connections are usually labeled COM, N/C and N/O:
  • COM = Common, always connect to this, it is the moving part of the switch.
  • N/C = Normally Closed, COM is connected to this when the relay coil is off.
  • N/O = Normally Open, COM is connected to this when the relay coil is on.
  • Connect to COM and N/O if you want the switched circuit to be on when the relay coil is on.
  • Connect to COM and N/C if you want the switched circuit to be on when the relay coil is off.
Working of ULN2803 IC

For working of ULN2803 click here.


Circuit Working

Working of this circuit is very simple. When data at pin 2 is '1', i.e., when 5V is coming out of pin 2 then, pin 1 of
ULN2803 IC receives 5V input and thus its pin 18 provides GND to one end of relay coil. The other end of relay coil is given +Vcc (12V), so the coil gets energized and the COM gets connected to the N/O contact and the AC mains circuit gets completed and the bulb glows.
Now, bulb will glow as long as data at pin 2 is high. When data at pin 2 becomes low, then the GND provided by pin 18 of
ULN2803 IC vanishes and coil gets de-energized and thus COM is connected back to N/C contact. Thus, external AC mains circuit is broken and bulb stops glowing.

Software

To control any port we need a kernel mode driver software. Softwares generally run in USER mode. But to control the Parallel Port we need a software running in kernel mode. I have used C#.Net for developing this software.
  1. Download and install Microsoft .NET Framework Version 2.0.

  2. Now download and install My Parallel Port Control Setup.

  3. Download C#.net source code.
For more info on software click here.



73 comments:

Anonymous said...

Thanks for sharing,

Can i use it without ULN IC?

Thanks

Jaspreet Singh said...

You can use it without ULN but you will need a few transistors to replace ULN. Also the circuit will become more complex. So, its better to use ULN instead.

mOnster said...

Hi,, me doing electronic engineering,me in 4th Semester,, me want to do this Project,, If i Cant Get ULN 2803,, Could i Use another one

Jaspreet Singh said...

ULN 2003 can also be used instead of ULN 2803. The only difference b/w the two is that ULN2003 has got 7 input/output pins and ULN2803 has 8 input/output pins.

Anonymous said...

Which relay i need to use, there is many ? Like 12V 6A, 12V 1A...
Which ?

Unknown said...

sir mainay is web say circuit diagram tally kar kay circuit banaya http://www.electronic-circuits-diagrams.com/computersimages/computersckt1.shtml but yeh work nahi kar raha jub may apnay ghar kay pass electronic shop per gia to usnay kaha yeh circuit diagram kharab hai app com ko load per lagai or n/o ko ac voltage day then it will work ...so sir can you pls help me out abh to ciruit chal hi nahi raha mujhay lagata hai IC ur gai hai kue kay mainay ziada voltage bhi diya that 12v...pls sir help me.

Jaspreet Singh said...

@Saqib
Circuit diagram is OK.
Either ur ckt connections are wrong or ur IC is not working.
Also, ur ckt will work only if ur ckt's GROUND is connected to the parallel port's GROUND.

Anonymous said...

hi how to make a 8 leds conected with parallel port to make them on off in odd and even numbers by using terbo c

Jaspreet Singh said...

Turbo C programs for parallel port will not work on 2000, XP, vista and windows 7. We need DOS or windows 98 to run C program for parallel port.

Siddharth Srivastava said...

Hi,

I am building a project for my sister. I am trying to interface eight 6V bulbs(In a house model) and control it with parallel port. All I need is to replace the relays with my 6V bulb. Right???

Your explaination and video was very helpful but I got to visit this site http://www.zen22142.zen.co.uk/Circuits/Interface/pc_int.htm

Here the diagram shows pin 10 isnt connected to neither VCC or Gnd...

Could you explain.

Siddharth
vish.sid73@gmail.com

Jaspreet Singh said...

@Siddharth

Replace the relays with 6V bulbs. It would work fine.

For ULN2803 either we can connect +ve supply to pin 10 or we can provide output supply via a diode directly to its output pins.
But its better to connect it to pin 10 as we would not need any external diode in this case.

Siddharth Srivastava said...

Hi, Thanks for your prompt reply.

I will be using ULN2803 for the project. But I yesterday I made this schematic using NPN transistors only.
http://demo.festinindia.com/schemesvg.png
Would you mind checking it. I built this schematic taking refrence from this http://demo.festinindia.com/ref.png
I have replaced the IN4148 btwn parllel port grnd and data line with a zener.

What are your suggestions..

NOte: In my schematic please see the placing of zener diode is correct. I think It should not be between transistor and data line but it should be btwn ground of parallel port and data line.


I will be uploading my new schematic using ULN2803 before implementing.

Jaspreet Singh said...

@Siddharth
Instead of using such complex circuit use ULN2803. Circuit will take less space and also can be made in less time. Also no external diodes are required for ULN2803.

Siddharth Srivastava said...

Hi,

Sure. I totally agree with you. I was just asking to make sure my circuit was fine.

Here, my new ULN2803 schematic. Please confirm me so that i can move ahead with the implementation part. http://demo.festinindia.com/project.svg

I added a zener to your design. I took refernce from http://demo.festinindia.com/ref1.PNG

Do I need any more addition or substration. Or this design is good to move forward. i hope it dont short my PC.:-)

Jaspreet Singh said...

@Siddharth

Add a 220 ohm resistor (or above) between each of the output pin of the ULN2803 and the LED. Rest of the circuit in my opnion is OK.

Anonymous said...

Hello,
Great tutorial..This tutorial only use one relay..if i want to control a lot of appliances..how should i do that?

thanks

Siddharth Srivastava said...

@jaspreet

Thanks for your review.

I am using 6V bulbs..Do I still need to add 220 ohm resistor btwn output pins and Bulb.

Jaspreet Singh said...

@Anonymous

We can connect 8 relays to ULN2803.
Connect coil of each relay between PIN 10 and PINs 11 to 18 of ULN2803.

Jaspreet Singh said...

@Siddharth

For 6V Bulb we can omit the resistor but for LED we need it.

mahesh said...

Thanks for sharing such a nice tutorial.

What will happen if "Pin 10" is not connected to +V in case of driving an unipolar stepper motor ?

Please reply.
Thanks.

Jaspreet Singh said...

@mahesh

We can remove +V from Pin 10 of ULN2803. The circuit will work fine.
But this may damage the ULN2803 if high reverse voltages are introduced at its output pins.

mahesh said...

Thanks a lot Jaspreet.
Keep it up.

Unknown said...

Sir Jaspreet i need circuit diagram for controlling home lights and fan from remote control. This circuit has also ability to control tuning speed of fan from fast to slow or slow to fast. please help me out.

Engr_Saifq said...

bro ur work is really awesome can u tell the specs of inductor to be used

Unknown said...

sir pls provide me circuit that control electrical appliances from GSM based mobile sms.

edmer said...

im edmer what relay do you use? and what transistor can i use for may relay 12v 220vac

Jaspreet Singh said...

@edmer
I'm using a 12V relay with IC ULN2803.

Instead of ULN2803 we can use NPN Transistor: BC547A or 2N2222A.

Anonymous said...

Hi, im doing a project regarding this, is it ok if there are multiple high inputs to the ic?? for ex. is it ok if i keep input pin 1,3, and 5 of the ic on? will it result into any damage

Ardy said...

Hey Jaspreet, thanks a lot man. This is just amazing.

I just wanted to ask:

1. Any other IC's I can use apart from the one you did?

2. Can I use the same code in Windows 7? Or can I use C?

Thanks a lot man.

Ardy said...

Sorry I should have included this above.

Earlier you said that, NPN Transistors: BC547A or 2N2222A can also be used.
How does that work?
One Transistor for every Relay?
A little more detail please?

My gmail id:
aradhyaalamuru@gmail.com

Thanks a lot man.

Jaspreet Singh said...

@Ardy

Q. Any other IC apart from ULN2803 that can be used?
A. ULN2003 can be used. The ULN2803 & ULN2003 are identical except ULN2003 has 7 channels and ULN2803 has 8 channels.


Q. Can I use the same code in Windows 7?
A. Yes, we can use the above code in Windows 7.


Q. BC547A or 2N2222A can also be used. How does that work?
A. We need to connect one Parallel Port output pin to the transistor and further connect the transistor to the Relay. So for 8 data pins of Parallel Port we need 8 transistors & 8 relays.

Ardy said...

Sweet. Thanks man. That was a very swift reply. Appreciate it a lot.

Can I get your email id? I have a couple of other related questions.

Thanks man.

Aditya Medhe said...

Hi Jaspreet, im doing a project regarding this, is it ok if there are multiple high inputs to the ic?? for ex. is it ok if i keep input pin 1,3, and 5 of the ic on? will it result into any damage??
Pls reply need ur help

Jaspreet Singh said...

@Ardy

Please ask your questions here via comments only, so that everybody else can see and have their doubts cleared.

Jaspreet Singh said...

@Aditya Medhe

ULN2803 IC provides 8 simultaneous channels. We can keep any number of inputs to the IC High or Low, at any time. It would not result in any damage.

Ardy said...

Okay, which IC can I use to convert BCD from the parallel port of the computer to control relays in a mux?

Thanks.

Aditya Medhe said...

Thanks a lot! I created my circuit today and am happy to see it running!

Jaspreet Singh said...

@Ardy

Use IC 74LS154 & IC 74LS05.

Anonymous said...

is this wireless.

Jaspreet Singh said...

It is wired.

Vinod Mishra said...

Sir, Namaskar. I am trying to register Jaspreets Parallel Port Control.dll in windows 7 but could not success. Please help. I want to develop program in VB6.

Thanks and Regards

Jaspreet Singh said...

@Vinod Mishra

Please follow the steps described in this article here - http://jaspreetscodezone.blogspot.com/2008/03/parallel-port-user-control.html

Vinod Mishra said...

Sir, Can I write program by using com port or not ?

Regards.

Jaspreet Singh said...

Yes, COM port can also be used but hardware and software required would be different from the one used above.

Vinod Mishra said...

Sir, Namaskar. I have designed circuit as per your direction. I want to know that :

After preparation of circuit I had given supply of 12 volt dc, and relay is making start sound. Is circuit O.K.

I have tried too many times to register your dll in windows xp, but could not success. computer is showing message 'C:\PROGRAM FILES\jASPREET KALEKA\PARALLEL PORT CONTROL (DEVELOPED BY JASPREET KALEKA)\JASPREETS PARALLEL PORT CONTROL.DLL WAS LOADED, BUT THE DLLREGISTERSERVER ENTRY POINT WAS NOT FOUND. THIS FILE CAN NOT BE REGISTERED.'

Please Help.

Thanking you and regards

Jaspreet Singh said...

@Vinod Mishra

Please follow the steps described in the "Using the code" section of this article here - http://jaspreetscodezone.blogspot.com/2008/03/parallel-port-user-control.html

Awi....... said...

Thank you Sir for this wonderful tutorial !

My doubt is how do I connect the transistor, as in which lead to which pin ?

Another question is, I have a relay, photos of which can be found in the following link

http://www.flickr.com/photos/82983032@N03/

Can I use this ? And again, Where should I connect which wires?

Thanks in advance :)

Jaspreet Singh said...

@Awi...

Use a multimeter to detect NO and NC relay pins.
For full circuit read the above article.

lara said...

can i control the parallel port via sms??? can u help me?

Jaspreet Singh said...

@lara

Yes you can control the Parallel Port via sms. You need to interface a GSM Module with your PC.
You can also use a Nokia mobile phone.
Nokia provides a "PC Connectivity API" to interface a Nokia phone to PC via .NET.

Awi....... said...

hi man
i figured out NO, NC and COM pins..
but for the transistor, can u pls tell me if this circuit is right..

http://www.flickr.com/photos/82983032@N03/

And also, i couldnt find 2N2222 or BC547A

I got 2N3906 (PNP) and 2N3904 (NPN)

which one is better for this purpose?

Awi....... said...

I just got a better relay from radioshack. the wiring diagram will be in my photostream

http://www.flickr.com/photos/82983032@N03/

Now im confused, there are 2 NO pins and 2 COM pins..which one should be used ?!

Jaspreet Singh said...

@Awi...

Either use the above NO, COM & NC pins or the bottom ones.

lara said...

thank you sir.
i really don't know how to use the c# can u give a sample code for vb.net?

Jaspreet Singh said...

@lara

You can convert the c# code to vb.net easily via online converters. Just search for "c# to vb" converter online.

Jan said...

HI sir

thank you very much for this helpful tutorial ..

but I have something to ask
now since we are using the first input " pin 2 " for this relay
do we still have to connect the rest of data pins ( 3-9)with the IC ?

Jaspreet Singh said...

No need to connect all the pins. Just connect the required pins.

Jan said...

thanks for your reply ^^

is it possible to show us s picture for the circuit connection ?
because this is the first time that teacher asked us to work with parallel port .. and I'm not sure where you have connected the Ribbon Wire

Jan said...

also If I want to connect the parallel port to a laptop , should I use an adapter from parallel to USB ?

Unknown said...

i want to control the data pins via keyboard please tell me program or to modify the program u have given please
abhishek
abhihellow@gmail.com

Unknown said...

please tell me the program or create a program to control data pins by keyboard i dont know programming bcoz m just in electronic engg diploma.

dreemo said...

Hi Jas

can I use the program to control the brightness of the lamp ?
if yes .. what changes I have to do in the circuit ?

another question ^^ .. I did the circuit on ( Proteus 7 ) .. is there any way to match the source code with the proteus so that I can test the circuit before apply it on hardware !

thank you very much

Jaspreet Singh said...

Hi Dreemo,

Yes we can use the program to control the brightness of a bulb. Just use a 'Potentiometer' in series with the bulb. The bulb I'm talking about here is an electronic bulb like an LED etc.

Regarding your second question, in my knowledge there is no way to match the source code with the Proteus 7.

dreemoo said...

mmm I think the "Potentiometer" will be difficult for me ..especially if I use the digital Potentiometer ..

I want to use two input pins to play with two different resisters .. in this case I need two relays right ?

and the rest 6 pins I want to connect them with a motor .. it will connect directly to the IC or it needs relays also ? and what kind of motor do you suggest in this case

about your program .. what version of ( Visual Studio ) you are using ? because I think I have a problem with .Net framework

I really appreciate your help

SPV said...

sir,
I want to controll a power supply of 3 to 5V DC using relay and the above circuit in windows XP.What are the changes required.Please let me know the software code required in xp.

Siddharth Srivastava said...

Hi Jaspreet,

It's been a long time since we last discussed.

I just want to know what is the maximum V power supply we can use with this circuit diagram. You used 12 V power Supply.

After a long time, out of curiosity I attached 8 9V batteries (In series).

The system is fine but the IC is getting too hot and the 10 and 11 pin have shorted so the bulb attached to port 11 is always ON.

Note I didn't used Relays. Shall I use them. I just directly attached 6V bulbs directly in place of relays.

Looking forward.

Bhagzi said...
This comment has been removed by the author.
Bhagzi said...

I am using a relay whose specs are:
Contact:

250VAC~/28VDC 10A(N.O.), 5A(N.C.)

250VAC~7A GEN.COS = 0.4

The bulb is not switching ON or OFF. I have used all the equipment that you said except for the relay. Is the problem with the relay??
Please help

phani bhargav said...
This comment has been removed by the author.
phani bhargav said...

Hello sir, what is the relay that i need to ask for as I am not sure. Is there any specification for relay or model no. Pls help me out.

Technocrat said...

This article was of great help...!
Thanks!

Unknown said...

Hi Jaspreet,

Great site and super explanations. Thank you

Anonymous said...

hi jespreet
i used the same cicut with 12v
12v realy

it was working fine for 15mint
but after some time ic is getting heating up and now its only working for first time. power on