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?
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);
}
}
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?
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...
nishantmsil:
I have done that yet it's not working
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....
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.
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
What the setup does so far: please check the image
Why that's not what it should do: I didn't understand this?
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)