by December 5, 2002 0 comments

Our last month’s article on making your own robot (Make Your Own Robot, PCQuest, page 90) gave an overview of how you can control a robot (say, a toy car) from the parallel port of your PC. And we had promised that this time, we would tell you how to create the simple circuitry for controlling the robot.

The shopping list
Let us start by first creating the robot itself. For this you need an inexpensive battery-operated car; one in which the front wheels can turn to the left and right (don’t get the ones where the front wheels move only backwards and forwards). We bought a Chinese-made remote-controlled model for Rs 700. You may be able to get something that costs a bit less. You will find one in any toyshop or in any Chinese goods shops that have sprung up in all nooks and corners of the country.

For the circuit, your shopping list should start with three meters of ribbon wire. You need four wires connecting your car to the PC. Since four individual wires can get tangled, we opted for the ribbon. (We got a ribbon of six strands, from which we yanked out two, leaving the four we needed. We later used the yanked-out strands for connecting the relays.) Why three meters? You could do with two or four. But if you go beyond five meters, then the system may not work, because of voltage drops across the wire. 

Next come four relays. What you need are 6 volt, single pole, single throw (SPST) relays. Next come the diodes and transistors. You need two types of diodes, IN 4148 and IN 4002, and one type of transistor, the BC 547, an NPN transistor, and also a 4.7 K resistance.

Ready for assembly: The toy car all opened up and wires to motors identified

Motors connected up. Inset: reassembling the car

The four relays wired up according to the circuit diagrams provided
Inset right: assembled circuit 1 Inset left: A relay

Connecting up to the male plug for the parallel prot

From the fact that we have four relays, you would have guessed that we have four similar sets of circuits to make. We would need four such circuits for connecting the two motors of the car, one for each motion. Each of these would need one of IN 4002 and two of IN4148, along with one transistor. Thus you would need four IN 4002s, eight 4148s and four BC 547s. You also need a PCB on which to solder the circuits. We have used five small pieces to illustrate the methodology. You can buy a larger piece and do with one. 

Finally, you need power. We use a 1 amp, 6 V adapter. You may have to search around for a 1 amp adapter. A standard 6 V adapter would barely take the load of the two motors and the four relays. 

You can buy all these things from any electronics shop. You also need a parallel port 25 pin D-type male connector, that can be bought from any PC assemblers shop. All of these together will come for less than Rs 150. 

You also need the standard electronics hobbyst’s companions: a soldering iron, enough solder, a multimeter and oodles of patience.

The circuit
The circuitry is a buffer circuit to drive a relay using +5v volts from the parallel port. The relays, in turn, are connected to the DC motors in the car. The circuit is very basic as shown in the diagram above, and you can put the components together on a PCB.

The parallel port is a very sensitive electronic device that can fail if the wiring is faulty or if there’s a short circuit. In newer motherboards, where the parallel port is built into the board, the fault can domino through the port to your motherboard. We have provided enough safeguards (the two IN4148 diodes), but make sure the circuit is correctly made before you connect it to the parallel port. Also, check the IN4002 diode because this diode protects the circuit from any back EMF generated from the relay. To be doubly sure, you can replace the IN 4148 diodes with 5.1 V Zener diodes.

Vcc in the circuit diagram is the external power supply for the relay. The circuit can handle relays that operate at 24 volts or less having a current rating of 100 mA or less. We use 6 V.

The outputs to be connected to the parallel port can be connected through a 25 PIN D type male plug, which can then be connected to the parallel port. The pins to which the circuit has to be connected on the parallel port have been explained in last month’s article (the article is also on this month’s CD in the Tutorials section).

Once you have created the circuit, the next step is to take the car apart. Do this by opening up all the screws on it. There are two motors, attached to the front and back wheels. Identify the wires powering them and cut them clean. Now remove the rest of the existing circuits off the car and you are ready.

Wiring the car
The motors will be connected as shown in the diagram below. 

Functioning of the relay-to-motor connection is very simple. Initially the potentials at point A and B are both 0V and the motor is switched off. When the relay 1 is switched on, the potential at point A changes to Vmm (the voltage required by the motors, 6 volts in our case) and at point B the potentials remains at OV (ground). This dictates the clockwise motion of the motor. Similarly, when relay 2 is switched on (and relay 1 is switched off ), the potentials at A and B exchange and this facilitates the anticlockwise motion of the relay . 

By sending a 1 (binary 00000001), (see last month’s article on how to do this), you can make the motor move clockwise and by sending a 2 you can make the motor move anticlockwise, These translate into forward/backward or left /right depending on how you have attached the circuit to motors in
the car. 

One important thing to remember is that it is imperative that we have enough power for the relay and the motors. Even though the relays and the motors work at the same voltage, a typical 6 V DC adaptor (if you are using 6 volts relay and 6v volts motors) will not be able to drive all of them simultaneously as it can only source 500mA.

You can use an adapter with higher Amp rating (1 Amp) or use two adaptors, one for the relays and another for the motors as they are more easily available. 

Basic control
We will now modify the code snippet from the last month’s article to test what we have created. Here at PCQ Labs we attached the data pins 0 and 1 to the motor controlling the direction (front wheel) and data pins 2 and 3 to the motor controlling the forward and backward motion (back wheel). 

Accordingly, the code now becomes 
#define value 1
void main (void )
outportb(0x378,value); //activating the first pin for turning left .
sleep(2) ; // sleeping for 2 secs 
ouportb(0x378,0) // switch of all motors 

If you do not have access to a C ++ compiler, the compiled exe for the code is in the CD as \cdrom\devlabs\source
Run the file with a numerical argument to make the car move. This argument is taken by value in the above code. An argument of 1 turns the car left, 2 turns it right, 4 gives forward and 8 gives backward motion (see last month’s article for an explanation). 5 (1+4) will send the car left and forward and 6 (2 +4) will send it right and forward. Similarly 9 (8+1) and 10 (8+2) will send it 
back and left and back and right, respectively. 

3 or 12 don’t make sense. There will be no motion as the potential difference between point A and point B is 0 (both are at 6 volts).

At this point in the game, every time you want to impart motion to the robot, 
you will have to run the exe file with an argument. This is a lousy way of doing things
and not the way it should be. So, next month we will build a more elaborate program that will give you more control over your robot, and will be easier 
to use. 

Ankit Khare

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.