bi direction without short ciruit

i'm using some motors ( some weak ones, and some hard core ones ) to set up a sample test with a joystick, and i want it to be bi directional, for instance, when i press the joystick left, the motor will spin left, and when i press right, the motor will spin to the right.

i now know reversing the voltage on the wires will infact turn the motor the opposite direction, but i also know connecting the motor from one pin to another is bad. and i think that i need a connection to 2 pins and a connection to ground, but i only have 2 wires, and i don't wanna short the arduino!

is there a way to safely hook it up, so even if i do connect two pins, or i connect bad to bad, no damage will be done?

secondary question:
i have a 5v motor that kills the arduino if i hook it up, and i want to be able to pwm it, so is an opto coupler good, or is there a diffrent way to do it with pwm?
and, can i opto couple it with things i have lying around, photodiode, resistors, led, potentiometers, switches?

thanks in advance!
-int big = 93;

This is how to hook up a DC motor to Arduino for PWM one way control:

http://www.tigoe.net/pcomp/code/category/code/picbasic-pro/62

If you also want to be able to control direction you shold use a H bridge circuit, do it like this:

http://www.toddholoubek.com/classes/pcomp/hbridge/Hbridgel293.html

As i said in the other thread if you try to drive inductive loads like motors directly from Arduino pins, best case it won't work, worst case, you can kill the Arduino board.

Inductive loads pull a lot of current in generel, and especially just when they start up, usually much more than the max 40mA you can source from any Arduino pin

Optocouplers are no good in this case.

ok, ill order the hbridge asap, thnks for the help.

i'm happy the the arduino is low cost, that way if i blow it up, its fairly cheap to replace, and thats why i dident lean twards any other microcontroller!