2 DC motors with 2 potentiometers

Hello

I have a question for my programm.
I use 2 DC motors with 2 potentiometers.

Now i have the problem that the program dont turn on the second motor (Pot 2=A0)
Can you please resold my problem.
I think it is a little thing wath is wrom on it.

Many thanks

Regard
Reka6

sketch_2_motors_and_2_potentiometers.ino (1.09 KB)

Assuming you are using a UNO, pin 4 does NOT support analogWrite but on the other hand pin 3 does.
So I would suggest you swap the connections over and change your code to something like this:

OP’s code (amended):
(Compiles, NOT tested!)

int Pot1 = A1;
int Pot2 = A0;
int val;
int val2;
void setup() {
  Serial.begin(9600);
  //put your setup code here, to run once:
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(A1, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(A0, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int val = analogRead(A1);
  if (val > 1 && val < 490) {
    val = map (val, 1, 490, 255, 0);
    analogWrite (5, 0);
    analogWrite (6, val);
  }
  else if (val > 530 && val < 1023) {
    val = map (val, 530, 1023, 0, 255);
    analogWrite (6, 0);
    analogWrite (5, val);
  }
  else if (val > 491 && val < 529) {
    val = map (val, 491, 529, 0, 0);
    analogWrite (6, 0);
    analogWrite (5, 0);
  }

  int val2 = analogRead(A0);
  if (val2 > 1 && val2 < 490) {
    val2 = map (val2, 1, 490, 255, 0);
    analogWrite (4, 0);
    analogWrite (3, val2);
  }
  else if (val2 > 530 && val2 < 1023) {
    val2 = map (val2, 530, 1023, 0, 255);
    analogWrite (4, 0);
    analogWrite (3, val2);
  }
  else if (val2 > 491 && val2 < 529) {
    val2 = map (val2, 491, 529, 0, 0);
    analogWrite (4, 0);
    analogWrite (3, 0);
  }
  Serial.println(val);
  Serial.println(val2);
}

hope that helps…

Thank you sherzaad for your help.

I want to test your input.
I will repond you of the test.

Regards
Reka6

Assuming you are using a UNO, pin 4 does NOT support analogWrite but on the other hand pin 3 does. so I should suggest you sway the connections over and change your code to something like this:

OP’s code (amended):
(Compiles, NOT tested!)

int Pot1 = A1;
int Pot2 = A0;
int val;
int val2;
void setup() {
  Serial.begin(9600);
  //put your setup code here, to run once:
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(A1, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(A0, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int val = analogRead(A1);
  if (val > 1 && val < 490) {
    val = map (val, 1, 490, 255, 0);
    analogWrite (5, 0);
    analogWrite (6, val);
  }
  else if (val > 530 && val < 1023) {
    val = map (val, 530, 1023, 0, 255);
    analogWrite (6, 0);
    analogWrite (5, val);
  }
  else if (val > 491 && val < 529) {
    val = map (val, 491, 529, 0, 0);
    analogWrite (6, 0);
    analogWrite (5, 0);
  }

  int val2 = analogRead(A0);
  if (val2 > 1 && val2 < 490) {
    val2 = map (val2, 1, 490, 255, 0);
    analogWrite (4, 0);
    analogWrite (3, val2);
  }
  else if (val2 > 530 && val2 < 1023) {
    val2 = map (val2, 530, 1023, 0, 255);
    analogWrite (4, 0);
    analogWrite (3, val2);
  }
  else if (val2 > 491 && val2 < 529) {
    val2 = map (val2, 491, 529, 0, 0);
    analogWrite (4, 0);
    analogWrite (3, 0);
  }
  Serial.println(val);
  Serial.println(val2);
}

hope that helps…

sherzaad:
Assuming you are using a UNO, pin 4 does NOT support analogWrite but on the other hand pin 3 does. so I should suggest you sway the connections over and change your code to something like this:

OP’s code (amended):
(Compiles, NOT tested!)

int Pot1 = A1;

int Pot2 = A0;
int val;
int val2;
void setup() {
 Serial.begin(9600);
 //put your setup code here, to run once:
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(A1, INPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(A0, INPUT);

}

void loop() {
 // put your main code here, to run repeatedly:
 int val = analogRead(A1);
 if (val > 1 && val < 490) {
   val = map (val, 1, 490, 255, 0);
   analogWrite (5, 0);
   analogWrite (6, val);
 }
 else if (val > 530 && val < 1023) {
   val = map (val, 530, 1023, 0, 255);
   analogWrite (6, 0);
   analogWrite (5, val);
 }
 else if (val > 491 && val < 529) {
   val = map (val, 491, 529, 0, 0);
   analogWrite (6, 0);
   analogWrite (5, 0);
 }

int val2 = analogRead(A0);
 if (val2 > 1 && val2 < 490) {
   val2 = map (val2, 1, 490, 255, 0);
   analogWrite (4, 0);
   analogWrite (3, val2);
 }
 else if (val2 > 530 && val2 < 1023) {
   val2 = map (val2, 530, 1023, 0, 255);
   analogWrite (4, 0);
   analogWrite (3, val2);
 }
 else if (val2 > 491 && val2 < 529) {
   val2 = map (val2, 491, 529, 0, 0);
   analogWrite (4, 0);
   analogWrite (3, 0);
 }
 Serial.println(val);
 Serial.println(val2);
}




hope that helps....

Hallo

I have testet the propsition program, but ist dosenˋt work.
So i have now change PIN 4 to PIN 9 and itˋs work.

Regards
Reka6

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.