Hi there;
I am new about Arduino, I try to learn it. I want to control motor direction using pot. Motors speed is stable. When I turn right the pot, motor turning right. When I turn left the pot motor turning left.
Finally, when the motor turns left or right, is it possible that the motor stops when I stop turning the potentiometer?
So you want a motor to turn at a constant speed in both directions but use a pot whose centre position is motor off and right travel is say, clockwise and left travel is anti-clockwise.
Could be done but you would need a deadband somewhere near the centre that does nothing otherwise the motor will hunt from one direction to the other.
Your last request doesn't make much sense.
Why a pot if you're not controlling speed?
2 push buttons would suffice.
This is not garantied, but try this
int PotPin = A0;
int PotPos;
int lastPotPos;
int MotorPin1 = 3;
int MotorPin2 = 4;
void setup() {
// put your setup code here, to run once:
pinMode(MotorPin1, OUTPUT);
pinMode(MotorPin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
PotPos = analogRead(PotPin);
PotPos = map(PotPos, 0, 1023, 0, 200);
if (lastPotPos != PotPos) {
if (lastPotPos < PotPos) {
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, LOW);
} else if (lastPotPos > PotPos) {
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, HIGH);
} else {
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
}
} else if (lastPotPos = PotPos) {
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
lastPotPos = PotPos;
}
}
Finally, when the motor turns left or right, is it possible that the motor stops when I stop turning the potentiometer?
Do you mean like the Servo in the Servo library knob example?
Not quite. I made another change to my code. It should work, but like I said it might not work.