Push button + Vibration motor trouble

Hi,

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!

Any suggestions?

Here is my code:

const int buttonPin = 9;    
const int VibratePin =  8;    
int buttonState = 0;        

void setup() {
  pinMode(VibratePin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
    digitalWrite(VibratePin, HIGH);
  }
  else {
    digitalWrite(VibratePin, LOW);
  }
}

Thanks!!

I hope the motor is NOT connected directly to the Arduino output pin.

Weedpharma

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:

http://bildr.org/2011/03/high-power-control-with-arduino-and-tip120/

Draw current is not the main issue. There are spikes to contend with.

Weedpharma

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.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom.... :slight_smile:
(ahh yes old faithful...)