I have a DC motor connected to my Arduino through a transistor. The motor uses the 5V from the Arduino, but is controlled through the transistor base from pin 4. I have a button on pin 9. Whenever my DC motor gets going, I start receiving phantom signals on the button. Has anyone else experienced this? If so, what to do about it?
DC motors generate a lot of electrical noise on the power supply lines. There’s lots of ways this can cuase the problem you’re seeing. Try running the motor off a different supply, just make sure it shares a common ground with the Arduino.
How much power does the motor draw? Only very small motors could be run from the Arduino’s +5V power supply without causing issues. Also, do you have a resistor between the Arduino pin and the base of the transistor? You need one - if it’s not present, the base of the transistor will draw a lot of current from the Arduino, possibly causing erratic behavior.
For anything other than tiny motors I’d always recommend MOSFETs instead of BJTs - they don’t require current to keep them turned on.
Try what the others mentioned. Also, make sure your arduino, button and motor grounds are sufficient and not loose.
You pulled up/down your button input pin, right? Without that, it will potentially have transients, esp with some source of interference close or on same circuit.