Parallel Port Tutorial – Part 1

Written on December 31, 2008 – 12:10 pm | by bluehash |

Disclaimer: The information provided here is correct to my best knowledge.You may use it at your own risk .

This tutorial will help you get a taste of controlling your machine using the printer port. Though the parallel port isn’t being used for many applications ,it is a boon for us hobbyists. This tutorial’s main aim is to get you working , so that you can send signals from the port like control a motor. Taking inputs
from the port will be covered in a subsequent tutorial.

Parallel Port Anatomy:
Following are the pinouts:

Picture Courtesy :: Ian Harries

  • 8 Output pins [D0 to D7]
  • 5 Status pins [S4 to S7 and S3]
  • 4 Control pins [C0 to C3]
  • 8 ground pins [18 to 25]

The Pins having a bar over them ,means that the signal is inverted by the parallel port’s hardware.If a 1 were to appear on the 11 pin [S7], the PC would see a 0. The Status pins are mainly used by the PC to know the status of the printer, like if there is paper in the printer, end of paper etc. Only the Data Port will be covered in this segment.

Parallel Port Female Connector

The Data Port
Sending commands involves only the data pins [D0 to D7].Though it is possible to use the some other pins as input, we’ll stick to the basics.

Please remember that the Data pins are from pin 2 to pin 9 and not from pin 1.
If you have a good eyesight, check your parallel port connectors. Both the connectors [male/female], have numbers etched next to their pins, so people like us don’t screw up our ports, connecting them the wrong way.The word “Parallel” means sending an entire set of 8 bits at once to the PC [That's why term Parallel Port].However we can use the individual pins of the port; sending either a 1 or a 0 to a peripheral like a motor or LED.

Sending Commands to the Port:
This part is easy.Just a single line of code does the trick.

  • C program for the motor

    #include{stdio.h} //replace {} with <>
    #include{dos.h} //replace {} with <>
    void main(void){

  • That’s it ,you just set all your data pins to 1.

    If you take an LED and put one terminal at pin2 and the other to pin 18,it would glow.[Use a 2K resistor in series with the LED, otherwise you will end up ruining your LED, or source too much current from the port pin].
    If you wish to switch it off. Type this:
    outportb(0x378,0x00); instead of the above line.

    What did you do?:

    0x378 is the parallel port address. Usually this is the default address.Sometimes it is 0x278 too

    0x00 is the command appearing at the output pins. The Format is in Hexadecimal. So if u want to make pin no2 high, that’s the first pin you type.
    0x01 which would mean 0000 0001 for the data port.

    0x04 would mean 00000100

    0x55 would mean 01010101

    0x0A would mean 00001010

    see the table below for reference

















    That finishes your basics so that you can run your motor.
    Material to control a Motor via a parallel port:

    • 1 parallel port Male connector
    • 1 DC Motor
    • 1 Motor Driver [L293D]
    • 1 5V regulator [7805]

    Before trying out anything ,please remember that your parallel port is not meant or designed to handle more than 5Volts.If possible, trying accessing your parallel port using Windows 98.Windows XP does not allow access to the parallel port. You’ll need special drivers for that.

    Steps to Control a Motor:

    • Use the Voltage regulator 7805,to get a constant DC 5V voltage from your
      DC power supply.
    • Connect your motor to your Motor Driver L293D.
    • Connect your parallel port pins to your Female connector [on your PC],through the male connector as follows.
    • Short all Ground pins i.e from 18 to 25.
    • Commands for the motor
      • outportb(0x378,0x00); ———STOP
      • outportb(0x378,0x03);———MOVE
      • outportb(0x378,0x01);———MOVE
      • outportb(0x378,0x02);———MOVE
    • C program for the motor

      [Please replace the {} bracket to <>]

      outportb(0x378,0x00); ———STOP MOTOR
      outportb(0x378,0x01);———MOVE MOTOR(CCW)
      outportb(0x378,0x02);———MOVE MOTOR(CW)
      outportb(0x378,0x03);———MOVE MOTOR(Break!)
      return 0;

    • The Sleep(n) function tells the port to hold [Latch] the command for (n) seconds.
      eg: sleep(2)——————delay or sleep for 2 seconds

      If you want to work in milliseconds ,use the delay(n) command
      eg: delay(500) ————–delay for 500 milliseconds

      That’s it, you can now control a motor using the parallel port. Use 2 motors and you have a moving machine. You can actually control the motors using the arrow keys using the Bioskey() function. Check “C” help for this. Hope you found this tutorial useful.
      Helpful links:
      Interfacing the printer port
      Introduction to Parallel Ports
      Books I used:
      Parallel Port Complete By Jan Axelson [Rs 350]

    Related Posts

    14 Responses to “Parallel Port Tutorial – Part 1”

    1. cosmin says:

      outportb takes 3 arguments. your code is wrong

    2. Narendran says:

      This website is awesome!!!!

    3. [...] Port Tutorial – [Part1] + [Part2] Tags: LPT, Parallel port, tutorial Filed in Interface | 1 views No Comments [...]

    4. anonymoose says:

      I’d like to make a usb to parallel port adapter… complete with bi-directional, and windows xp support!

      However, since inportb/outportb don’t work in windows xp/7, how can this be done? I would think a low level kernel driver would need to intercepts io calls to 0x378 and route them to the usb, but is this even possible?

    5. anonymoose says:


      But does that driver work on legacy applications natively, that use _inp/_outp? From the site it seems that a new application would need to be written in order to utilize the api calls that it introduces: Inp32 and Out32.

    6. pratibha says:

      can u tell me the logic & code i shud write for moving wheels in matlab

    7. pratibha says:

      can u tell me the logic & code i shud write for moving wheels in matlab..

    8. Aashique says:

      Hi Im using a usb to parallel port in my laptop which runs on win7, when I executed this there was no response of an output can you please help me to solve this issue ASAP, added can u help to find out the port address of an usb to parallel port

      • Scott says:

        Ditch the USB to parallel. There is a MUCH better interface which is a DLP-IO8. It’s a USB to 8 I/O data acquisition board. Each output will supply 5 volts @ 25mA much like the parallel port. It is actually “seen” by the PC as a COM port. Just send it a numerical value (1-8) to turn ON each channel or the character set below each number on the keyboard (QWERTYUI) to turn off channels. It can also be used in other ways, just look up the data sheet.

        Here’s how I’m using mine –


    Welcome to my place on the web. I note down anything interesting most of them relating to my experiences, Tech, To-dos, How-tos and various hacks. Most of my time is spent in tinkering around with hardware, building robots and working with DSPs.More

    Want to subscribe?

     Subscribe in a reader Or, subscribe via Email

    Add to Technorati Favorites
    Find entries :