i wan't to control my dc motor in situaion , my sensor is rain drop
-if sensor have signal (ex valuae >500)
+motor turn left in 10s then stop
-if sensor no signal (ex: valuae =0)
+motor turn right then stop
i'm just begin program arduino
thank you very much!!!
my code and my skecht
#include <AFMotor.h>
int potPin = 0; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor.setSpeed(200); // set the speed to 200/255
}
void loop() {
val = analogRead(potPin);
if(val > 500)
{ // read the value from the sensor
Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(500);
}
else
{ // stop the program for some time
Serial.print("tock");
motor.run(BACKWARD); // the other way
delay(500);
}
}
quangphuc91:
please help me , i don't know how stop my motor
Since you're using the AFMotor library to control the motor, you need to look at the documentation for that library and identify the method that stops the motor - and then call it, in the appropriate place in your code.
i want the motor stop until the sensor change signal
Then write your code like that.
You have been offered a lot of advice, you now have new code, it is time to post your code again so we can see where you are up to.
This is because you have some other code that turns it on.
We don't know what this code is because you have not posted your rewrite.
Unless you cooperate you can not get help.