Advertisment

Make Your Own Robot

author-image
PCQ Bureau
New Update

Starting with this issue we bring you a series of articles on how you can build a robot. Before you get overly excited about it, however, a clarification is in order. We are not talking about those walking, talking robots you see in movies. We will see how to build a really basic one–a computer-controlled robotic toy car. At the end of this project, we will have a toy car that is connected to, and controlled from, your PC.

Advertisment

We’ll build three parts of the robot: the software (let’s call it the brain), the interface with a PC and the mechanical assembly.

The ingredients



To start with, we will need a computer with a working parallel port. This is for the interface. You can use a serial port or USB, too, but the good old parallel port is the easiest and most convenient to handle. 

Even an old 286s or 386s will do. We will use good old MS DOS as our OS. You could create complex graphical control programs for Windows, Linux or the Mac. The idea here is to implement a basic system. So we choose MS DOS. As an interesting option, you can even try the concept on embedded systems.

Advertisment

To program the parallel port, any of the programming languages, which support I/ O port access, would do. We will use C ++. If you are not keen on coding, we will give you the compiled executable along with the source code that will be required, on the CD in the month when we talk about coding. 

The parallel port



A parallel port can send (by varying the voltage levels) 8 bits in parallel (1 byte), simultaneously to a connected device, for example, a printer. The parallel port that you find at the back of your PC is a 25-pin, D-type female connector. 25 pins allow for powerful communication with devices, but we will restrict ourselves to just sending data out of the parallel port.

As mentioned, a parallel port can send 8 bits simultaneously. The pins that are used to do so are 8 pins from pin numbers 2 to 9. You will find the pin numbers etched on the plastic casing of the port. Other pins that we will use are the ground pins (numbers 18, 19, 20, 21, 22, 23, 24 and 25). So many (redundant) ground pins are used for parity checking.

Advertisment

Identifying the pins on the parallel port

The output pins on the parallel port use TTL (Transistor-Transistor Logic) to pass signals as voltage levels. Voltage levels are either ‘1’ or ‘high’ (a voltage level of 5V) or ‘0’ or ‘low’, signified by 0 volts. This is the theory. In practice, the actual voltages will not be exactly these, but around them. The objective of the interfacing circuitry is to identify these voltage levels on the parallel port and use them for driving our robot. As for the current, the parallel port itself can source only 4.6 mA of current, which is very less, except for say lighting up LEDs. For driving the motors in the robots, we will need more current.

This will be provided by a separate power source.



The voltage levels at the parallel port are interpreted as digital signals to make the robot perform specific tasks. Let us see how to do this. Pin number 2 is the 0th bit and progressively pin 9 is the 7th bit of the byte that is sent to the connected device through the parallel port. Hence, a value of 11111111 in binary or 255 in decimal would mean that all pins are at a voltage level of 5V.

Advertisment

Generalizing this, a pin status of 00000001 (only the first data pin, ie, the 2nd pin on the parallel port, or the 0th bit, is active) would be signified by a value 1, or the decimal equivalent of the binary number that corresponds to the desired high—low (one or zero) configuration of the data pins. If decimal to binary and vice versa confuses you, the following chart should help.

Give the pins the following weights
Pin   2 3 4 5 6 7 8 9
Bit

no.
0 1 2 3 4 5 6  7
Wt. 1    2 4 8 16 32

 
64 128 
(Wt.:

2n, where n is the bit no.)
0 1 1 0 0 0 0 0

then the equivalent decimal would be 2 + 4 = 6 (adding corresponding weights of the active (‘high’) pins. People who can work with hexadecimal

may find that base-16 a better way to express pin status.

Advertisment

Once you have understood the above cocktail of pins and voltages, sending this decimal value using a program is trivial. Although the basics of coding are presented here, higher levels of abstraction of this code have to be used for some really constructive programming.

Consider the following code snippet.



#include


#define port 0x378 


#define value 255


void main(void)


{


outportb (port, value) ;


}





Port is the I/ O address of the first parallel port attached on your computer. In the rarest of cases where it might be other than 0x378, do check the printer port I/ O address in the BIOS settings. Value is the decimal value as described in the previous section.

Advertisment

An important point to note is that this setting of value remains the same even after the program has quit, until your PC is rebooted in which case the parallel port is reset. So, any good programmer should, before exiting the program, set the values back to where he started from. For this, you have to obviously read them in when you start the program. That is a completely different topic and we will not cover it in this series.

Now consider a motor inside your robot. A typical DC motor can have three states: clockwise motion, anticlockwise motion and no motion. To generate control signals for these three states we will need 2 bits.

Bit no.0 1
0 0 off
1 0 clockwise motion 
1 anticlockwise motion 
1 1 not needed 
Advertisment















So, to create a clockwise motion of the motor we will have to send a value of 1 to the parallel port, similarly a value of 2 for anticlockwise motion. Likewise, the other six unused data bits can be used for controlling three other motors. In our example, we will use only two motors, one for forward/backward motion and other for changing direction.

Next month, we will construct the circuitry necessary to implement this.

Ankit Khare

Advertisment