Motor control

I have what should be a pretty simple question. I’m very new to this stuff. I’ve got a small DC motor. It runs just fine when connected to the arduino +5v and ground pins. I’d like to be able to simply switch it on and off, but I’m having difficulty figuring out how to do that. I first tried connecting it to various pins and a ground, and played around using digitalWrite() and analogWrite() in all kinds of different configurations, with no luck. So I tried putting a current I knew would work just fine with the motor through a transistor that was rated to handle it, and tried using the digital pins to control the base current, once again with no luck.

Are the methods I’ve tried flawed somehow, or do I just need to rework them? I’ve very recently opened an electronics text for the first time, so I’m sure there’s something very simple that I’m not getting here.

Thanks a bunch

You should be able to control it in one direction with a transistor.

You’ll need a resistor to limit base current from the Arduino output or the transistor will fail. Probably silently so you won’t know it has failed.

This page: motor control has some sketches to show how it is done.

Regards,

Mike

The method expalined here has worked great for me :

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

It’s just at transistor and a diode and a resistor.

You should be very careful with running motors directly fom Arduno pins, all but the smallest motors can easily draw a lot more current than the 40 mA an Arduino pin can supply. And even if a motor is rated at XX mA it will draw a lot more just when starting up.

Thanks for the responses, they have been very helpful. I’ve got things working like a charm now.