I am having an issue controlling a small vibration motor with a push button switch.
I want the motor to be off when the switch is not pressed, but for some reason is still gently vibrates. When I press the switch it vibrates harder - so it is reacting to the code, but for some reason I can't get it to stop vibrating when the button isn't pushed!
Have you tried putting it on a different pin? I've hooked those little vibration motors up directly to the digital output pins without any issue before. They don't really draw enough power to require a transistor, but if you're still having issue, you can using a transistor to control the motor:
Directly driving an inductive load from a microcontroller pin will destroy the microcontroller
unless you are very lucky. It will certainly stress it far beyond its ratings.
Inductive loads must have some protection circuitry like a free-wheel diode to prevent
high-voltage spikes.
A motor will pull too much current for an Arduino pin, you need a transistor or MOSFET
to switch it. This is all covered in the playground surely?
Logic signals are not power. Power is not a logic signal. Keep them separate.