Electronic and Computer Resources - Parallel Port Interfacing and Programming using Turbo C


BACK            HOME             NEXT 


Interfacing with Coil

To interface a solenoid or coil to the PC, a buffer or current driver is needed because solenoid demands a considerable amount of current. The current driver can be a transistor, darlington, or an opto-coupler.

A free-wheeling diode must be connected in parallel with the coil or solenoid terminal to protect the transistor or current driver from back emf produced by the coil.

 Below is one of the interfacing circuits that can be design for a solenoid or coil.




Interfacing circuit diagram


 Resistor value depends on 

     1. the transistor dc current gain (B)

     2. resistance of the coil (Rc)

     3. supply voltage (Vcc)


 The following formula can be used to compute the resistor value


                     R = 5 / {[(Vcc / Rc) / B] * 4 } 


To be able to activate the solenoid, the program needs only to output a high bit to the output port pin that is connected to the base resistor of the interfaced circuit. 

Our examples next will be programs that will control a relay and a stepper motor.



Interfacing with Relay

A relay is basically composed of a solenoid and contacts. Most relays have two contacts, normally open (NO) and normally close (NC) contacts. Below is a schematic diagram of a relay.  


Lamp Control Program

Consider this problem:

A 12V relay, controlling a 12V lamp, is interfaced to D0 of the computer's parallel printer port. Three push button, Pb1 to Pb3, are also interfaced to S3 to S5. Write a program such that if Pb1 is pressed, the computer will ask for the number of seconds. After the user entered the time, the lamp will turn on for the specified time. Then, it will turn off.

If Pb2 is pressed, the lamp should turn off no matter what is the status of the lamp. 

If Pb3 is pressed, the program should end no matter what is the status of the lamp.



R2-R3 = 10k

Interfacing Circuit Diagram


Here is the link of the source code of the program: Relay.CPP


BACK        HOME          NEXT




    Parallel Printer Port  

    Port Functions

    Sending a Byte

    Reading a Byte

    Interfacing LED

    Interfacing Push Button

    Interfacing 7-Segment

    Interfacing Coil

    Interfacing Relay

    Interfacing  S. Motor

    Interfacing AC Load

    Interfacing Sensor




Electronic and Computer Resources - Parallel Port Interfacing and Programming using Turbo C







1.  The Parallel Printer Port     2.  Port Functions in Turbo C    3.  Sending a Byte to the Port    4.  Reading a Byte     5.  Interfacing with LED

6.   Interfacing with Push Button     7.  Interfacing with 7-Segment    8.  Interfacing with Coil    9.  Interfacing with Relay    

10.  Interfacing with Stepper Motor    11.  Interfacing with AC Load    12.  Interfacing with Sensor

For questions, corrections and suggestions, 

email to: [email protected]

Hosted by www.Geocities.ws