I’m making a model elevator for a school project that will be fully functioning. I can’t figure out how to reverse the motor though. I need to not only be able to turn the motor on and off, but I also need to be able to change the direction. Can I connect the motor to two Arduino output pins and switch which one is HIGH and which one is LOW? It seems like a really basic task but I can’t figure it out. Any help is appreciated.
Unless its a reeeeeeaally small motor, that won’t work, and you’ll just burn out your IO pins.
Here’s a simple schematic that uses a relay to solve your problem. This one is nice as your design doesn’t need high speed switching.
When Enable is high, the NPN turns on and current can flow.
When the relay is not energized, the motor+ is connected the +supply, the motor- is grounded thru the transistor, and turns one direction.
When the relay is energized, the motor connections are swapped, and it turns the other direction.
Use a DPDT relay that has a 5v coil with 140+ ohm resistance to keep current flow <35mA.
Or use a transistor to drive the relay coil.
Lastly, put a diode in reverse across the coil pins (cathode to +5V, anode to the Direction pin) so the coil inductor does not damage your output pin.
(inductors create a reverse voltage spike when current flow stops, the diode dissipates it back thru the motor)
I found this circuit after some research. It seems the same concept as what you explained. What values for the components should I use if I'm running a motor that normally uses around 8 volts?
Yes, looks like the same thing. Transistor needed depends on how much current your motor needs. This relay http://search.digikey.com/us/en/products/IM22TS/PB1168-ND/1828440 can be controlled directly from Arduino output pin. This N-Channel MOSFET can handle 8V & lots of current. http://search.digikey.com/us/en/products/NTD5867NL-1G/NTD5867NL-1GOS-ND/2401422 Just put a 100 ohm resistor from arduino pin to the gate. Be sure to put a diode across the coil as mentioned earlier.
So if I use the circuit in the page I posted but replaced the relay with a 4.5v DPDT relay, the transistors with the MOSFET N-CH ones, and added a diode accross the coil, I could use the motor with my Arduino?
Yes. Only need the one transistor, that connects the relay to ground, as I posted originally.
You may want to look at using a continous rotation servo if you just need a bi directional geared motor with somewhat adjustable speed.