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.
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.