Arduino programming and circuit for vibration motor

Hello,

I am trying to program arduino for my project in which my vibration motor will keep running and will stop on pressing push button.

I am attaching circuit diagram and program. Please suggest me how can I run this.

int incomingByte = 0;// for incoming serial data
const int motorPin = 3;

int inPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup()
{

Serial.begin(9600); // // opens serial port, sets data rate to 9600 bps
pinMode(motorPin, OUTPUT);

pinMode(inPin, INPUT); // declare pushbutton as input
}

void loop()
{

if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();//not using this

val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(motorPin, LOW);

}
else {

digitalWrite(motorPin, HIGH);

}
}

}

(deleted)

I am using serial to run the motor with c program. It's working, just the switch is not working. The vibration motor runs continously and even after pressing button the motor won't stop. How to go about it?

(deleted)

spycatcher2k: What are you using Serial for?

I think you mean "What are you using a vibration motor for ?"

nishantmsil you should put your code in code quote to make easy for all os us to read it! And "What are you using Serial for?", you don't need it!

You just need it:

int incomingByte = 0;// for incoming serial data
const int motorPin = 3;

int inPin = 2;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
void setup()
{  
  pinMode(motorPin, OUTPUT);
  pinMode(inPin, INPUT);    // declare pushbutton as input
}

void loop()
{ 
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released) 
    digitalWrite(motorPin, LOW);     
  }else{
    digitalWrite(motorPin, HIGH);  
  }  
}

Sir,

I have to run the arduino using c program for which I used serial communication. Serial addition is not causing a problem as far as I know. Secondly, Can you tell me if the circuit diagram is ok for my program?

nishantmsil: Sir,

I have to run the arduino using c program for which I used serial communication. Serial addition is not causing a problem as far as I know. Secondly, Can you tell me if the circuit diagram is ok for my program?

Your Motor should be wired (yellow wire) to pin 3 of arduino not to pin 9 as show your diagram...

I have done that yet it's not working :(

Please explain: 1. What your project should do 2. What you have done so far 3. What the setup does so far 4. Why that's not what it should do

lg, couka

nishantmsil:
I have done that yet it’s not working :frowning:

try to put in your loop the command: Serial.println(digitalRead(inPin)); // read input value
and see what’s the output when you press your button ! You need to debug it and isolate the problems…
put it to be the first thing to be executed in the loop, and if you get the expected result move it on next step of your code for debug…

couka: Please explain: 1. What your project should do: I run a c program the arduino will run and motor will start vibrating, and once I press push button, the vibration will stop. 2. What you have done so far: I programmed C program, I linked it with arduino, the vibration motor runs but pressing button doesn't stop motor 3. What the setup does so far: please check the image 4. Why that's not what it should do: I didn't understand this?

lg, couka

Your diagram shows a servo, but you said you are using a vibration motor. How many leads does the motor have, and are they labeled?

lg, couka

It is just indicative diagram which I used for my project. In place of servo I used Vibration motor

Hi, What are you using for a switch, can you measure the voltage at pin2 and see it change when you press the button. A picture of your project would help. Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png? (not a fritzy)

Thanks.. Tom... :)