Saturday, June 18, 2011

How to control a Motor Using Parallel port.

Parallel port gives a continuos 0 volt(as 0) or continuous 3 volt(as 1).

For controlling a motor in both direction, we can use L293D IC which simple to connect and we can controll two motor with the help of one IC, and the maximum current it can provide to motor is 1A. So if we are using motor controlling in a small robot or something else where no much load and motor can be drive by only 1A current then it is the best IC.



This IC takes only four inputs, which can be 0 or 1,and combination of 0, 1 decide how will motor rotate. And parallel port output is sufficient to give the input in this IC. So we can directly add parallel port outputs to the L293D IC inputs, and can control motor in both direction usning programming, and how to control parallel port output using programming i have discussed this in my earlier post.

But in L293D IC there is a problem we can not give more than 1A current for driving the motor so if we want to drive a motor which takes more current we can use L298 IC it can provide about 2A current. But again if you want more than this current then u have to use relay.

relay is much better solution it can switch 220V AC supply also.

for energizing the realy using parallel port, we can use ULN2803, because parallel port is not able to switch the relay, so it is better option.

Parallel port programming in Linux (Ubuntu)

Hello Every one.

It is very simple to control the parallel port in linux in c. Just run this c program. Make sure you are logged in as a root.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define pport 0x378

main(int argc,char **argv)
{
unsigned long int i;
if (ioperm(pport,1,1))
    printf("Error: Couldn't get the port at %x\n", pport);

while(1){
 for(i=0;i<99999999;i++);
   outb(0xFF,pport);
   printf("\nON");
 for(i=0;i<99999999;i++);
   outb(0x00,pport);
   printf("OFF");
}
}

This program is for blinking a LED on any data bit of parallel port.

U can change the delay by changing the for loop conditions.

If some one is new to linux then here is some help, how to add root user...

type ' sudo passwd root ' on terminal then hit enter. it will ask password for root user two times, give the password and then login as a root.

enjoy...