Vibration motors shorting

Sorry, I was on my phone before and that makes it hard to examine code. The false button presses are probably the result of contact bounce. A way to use button switches to do counting and avoid extra counts is by using the state change detection method. My state change detection for active low inputs tutorial shows how with example code and schematics. You will also see how to change your code to use the switch wired to ground and internal pullups.

Here is a MOSFET motor driver that shows the flyback diode (D1). The MOSFET will supply the stall current of the motors without stressing the output pins and the diode will shunt the high voltage spike generated by the motor coils when the magnetic field in the motor collapses upon motor power off. The capacitor help to prevent brush noise from getting onto the power supply and causing weird bugs. For your little motors a 2N7000 MOSFET could work. They are available in breadboard friendly through hole packages (TO-92). Available from DigiKey and many others.

image

1 Like