How to run motor in both directions, using just 2 output pins

I want to run a dc motor, using just two output pins .

(I cant use a dpdt realy, and an h-bridge requires 4 pins)
{I just have tip 122, and I cant get any PNP transistors. }

You can use a H-bridge.

I think it is like this:
If you keep one pin low, the other pin uses PWM for forward speed.
To reverse, do it the other way around, the first pin for PWM and keep the second pin low.

If you build a H-bridge yourself, you need extra transistors. Perhaps the best way is to use a H-bridge with optocouplers. With optocouplers you don't have to worry about level shifting or inverting the signal for NPN or PNP transistors.

I like this kind of circuit: BJT H-bridge Circuit Details
It can be adapted for NPN transistors only.

Krodal, what do you thing of using one relay for ON/OFF and another for direction ?

(edit: no, wait, the ON/OFF relay could be replaced by a transistor to be able to use pwm for speed control (to some degree), right ? )

so what do i finally do?

what about using the L293D ?

the ENABLE pins will always be HIGH(5 v source). to switch off the motors, i can use analogWrite(0)

is this idea going to work?

You might want to consider adafruit's motor shield then.

(I'm not linked to adafruit industries in any way, I just happen to have one of those)

nop, will not spend so much on a shield

harshvardhan:
nop, will not spend so much on a shield

5 or 6 dollars (inclusive shipping) on Ebay.
Search for "motor shield", it is the same as the Adafruit shield, but an older version with cheaper components.

basta semplicemente che ti compri due relè a doppio contatto
collegando i due centrali dei due relè hai due cavi del motore, i due contatti normalmente aperti del relè al meno, ed i due normalmente chiusi al più. Dopo di che fai un ponte tra il + ed il - dell'alimentazione dei relè, e diventa gnd, cosi hai un più per la sinistra ed un più per la destra. Se non hai capito ti posto uno schema.. :slight_smile:
sono italiano, e questo testo è stato tradotto, probabilmente non capirai..
appena ci riesco ti posto lo schema

DPDT relay and transistor will work.

+V C -V
M+
M-
-V C +V

Use transistor to control application of voltage
When relay is connected to the left pins, current flows from top to bottom
When relay is connected to the right pins, current flows from bottom to top

Okay TIP122, use that to connect V- to Gnd (sink current).
Don't forget a 1N4001 type diode across the relay +/- pairs (in parallel with the motor) with cathode on V+ and anod on V-

harshvardhan:
I want to run a dc motor, using just two output pins .

(I cant use a dpdt realy, and an h-bridge requires 4 pins)
{I just have tip 122, and I cant get any PNP transistors. }

You could modify a servo for continous rotation and control direction and speed just using one control line.