Help with Programming using 3 POT to a Motor Shield

I am working on a project to use 3 POT to operate two motors using a Arduino and a Arduino Motor Shield

The Joystick I have has 3 POT
POT voltage Outputs:
Y POT: in Center Position reads 2.4 VDC, All the way forward reads 1.5 VDC, all the way backwards reads 3.5 VDC
+X POT: in Center Position reads 1.5 VDC, All the way to the right reads 3.5 VDC
-X POT: in Center Position reads 1.5 VDC, All the way to the Left reads 3.5 VDC

The Y axis is to drive both motors forward or backwards. As of now I have a Scratch that will perform this action

The X axis is to resist one motor from the other; that way I can turn the project left or right as the joystick gets moved left or right. if the joystick is moved forward the project will move forward (straight) but during the forward of the joystick if the operator moves the stick left or right it will turn the project.

Below is what I have already....need help on how to configure the scratch for the other two POTs, also the max output mA to the motors needs to be 100mA

Thanks
*/
int rightBrake=9;
int leftBrake=8;
int readPin=A2;
int readVal;
float V2=0;
void setup() {
pinMode(readPin,INPUT);
pinMode(rightBrake,OUTPUT);
pinMode(leftBrake,OUTPUT);
pinMode(12,OUTPUT); //Channel A Direction Pin Initialize
pinMode(13,OUTPUT); //Channel B Direction Pin Initialize
Serial.begin(9600);
}

void loop() {
if (analogRead(readPin) > 512)
{
readVal=analogRead(readPin);
V2=(5./1023.)readVal;
digitalWrite(rightBrake,LOW);
digitalWrite(leftBrake,LOW);
digitalWrite(13, LOW); //Channel B Direction Reverse
analogWrite(11, 0.5
analogRead(readPin)-255); //Channel B Speed

digitalWrite(12, HIGH); //Channel A Direction Reverse
analogWrite(3, 0.5*analogRead(readPin)-255); //Channel A Speed

int sensorValue = analogRead(readPin);

Serial.println(V2);

delay(150);
}

if(analogRead(readPin) < 505)
{
readVal=analogRead(readPin);
V2=(5./1023.)readVal;
digitalWrite(rightBrake,LOW);
digitalWrite(leftBrake,LOW);
digitalWrite(13, HIGH); //Channel B Direction Forward
analogWrite(11, 255-0.5
analogRead(readPin)); //Channel B Speed

digitalWrite(12, LOW); //Channel A Direction Forward
analogWrite(3, 255-0.5*analogRead(readPin)); //Channel A Speed

int sensorValue = analogRead(readPin);

Serial.println(V2);

delay(150);
}

}

It would be helpful if you named all your pins instead of using names for some and numbers for others.. And it would be helpful if you used Left and Right instead of Channel A and Channel B. You have a "readPin" but no YPin, XPlusPin or XMinusPin.

You specify the values in volts but the raw analogRead() results would be more useful. Start with this sketch. Put in the right pin numbers! Run it with Serial Monitor open and note down the three values when the joystick is at the center and the four limits (forward, backward, left, and right). Report back with those numbers.

// Names for the Analog Input (AI) pins:
const byte Y_AIPin = A2;
const byte XPlus_AIPin = A3;
const byte XMinus_AIPin = A4;


void setup()
{
  Serial.begin(115200);
}


void loop()
{
  Serial.print("Y=");
  Serial.print(analogRead(Y_AIPin));
  Serial.print("\tX+=");
  Serial.print(analogRead(XPlus_AIPin));
  Serial.print("\tX-=");
  Serial.println(analogRead(XMinus_AIPin));
  delay(500);
}

johnwasser I thanks you for your inputs and updated my notes and Sketch accordingly

I am working on a project to use 3 POT on one Joystick to operate two motors using a Arduino and a Arduino Motor Shield

The Joystick I have has 3
POT voltage Outputs:
Y POT: in Center Position reads 2.4 VDC, All the way forward reads 1.5 VDC, all the way backwards reads 3.5 VDC
+X POT: in Center Position reads 1.5 VDC, All the way to the right reads 3.5 VDC
-X POT: in Center Position reads 1.5 VDC, All the way to the Left reads 3.5 VDC

POT 0 to 1023 Input reading on Arduino:
Y POT Connected to A2: in Center Position reads 507, All the way forward reads 300, all the way backwards reads 711
+X POT Connected to A3: in Center Position reads 305, All the way to the right reads 712
-X POT Connected to A4: in Center Position reads 305, All the way to the Left reads 712

The Y axis is to drive both motors forward or backwards. As of now I have a Sketch that will perform this action

The X axis is to resist one motor from the other; that way I can turn the project left or right as the joystick gets moved left or right. if the joystick is moved forward the project will move forward (straight) but during the forward of the joystick if the operator moves the stick left or right it will turn the project.

Note: XPlus_AIPin (A3) needs to be linked to analogWrite (11) and XMinus_AIPin (A4) needs to be linked to analogWrite (3)

Need XPlus_AIPin (A3) or XMinus_AIPin (A4) when in the center position of the Joystick reading 305 doesn’t affect the output Voltage to analogWrite (11) or analogWrite (3) but if XPlus_AIPin (A3) or XMinus_AIPin (A4) increases grater than 306 to 712 than analogWrite (11) or analogWrite (3) will get decreased in voltage depending on the value is apply to XPlus_AIPin (A3) or XMinus_AIPin (A4)

Below is what I have already....need help on how to configure the sketch for the other two POTs, also the max output mA to the motors needs no greater than 100mA

Thanks

*/

// Names for the Analog Input (AI) pins:
 const byte Y_AIPin = A2;       //Move Forward Nuture Reverse on Joystick
 const byte XPlus_AIPin = A3;   //Turn Right on the Joystick
 const byte XMinus_AIPin = A4;  //Turn Left on the Joystick
 int rightBrake=9;  
 int leftBrake=8;
void setup() {
 pinMode(Y_AIPin,INPUT);
 pinMode(rightBrake,OUTPUT);
 pinMode(leftBrake,OUTPUT);
 pinMode(12,OUTPUT);     //Channel A Direction Pin Initialize
 pinMode(13,OUTPUT);     //Channel B Direction Pin Initialize
 Serial.begin(9600);
}

void loop() {
 if (analogRead(Y_AIPin) > 512)
 {
   digitalWrite(rightBrake,LOW);  //Release Right Brake on Motor Shield
   digitalWrite(leftBrake,LOW);   //Release Left Brake on Motor Shield
   digitalWrite(13, LOW); //Channel B Direction Reverse
   analogWrite(11, 0.5*analogRead(Y_AIPin)-255);  //Channel B Speed 

   digitalWrite(12, HIGH); //Channel A Direction Reverse
   analogWrite(3, 0.5*analogRead(Y_AIPin)-255);  //Channel A Speed
   
   int sensorValue = analogRead(Y_AIPin);
   
   Serial.print("Y=");
   Serial.print(analogRead(Y_AIPin));
   Serial.print(" \tX+=");
   Serial.print(analogRead(XPlus_AIPin));
   Serial.print(" \tX-=");
   Serial.println(analogRead(XMinus_AIPin));
   
   delay(150);
 }
 
 if(analogRead(Y_AIPin) < 505) 
 {
   digitalWrite(rightBrake,LOW);
   digitalWrite(leftBrake,LOW);
   digitalWrite(13, HIGH); //Channel B Direction Forward
   analogWrite(11, 255-0.5*analogRead(Y_AIPin));  //Channel B Speed
   
   digitalWrite(12, LOW); //Channel A Direction Forward
   analogWrite(3, 255-0.5*analogRead(Y_AIPin));  //Channel A Speed 

    
   int sensorValue = analogRead(Y_AIPin);
   
   Serial.print("Y=");
   Serial.print(analogRead(Y_AIPin));
   Serial.print(" \tX+=");
   Serial.print(analogRead(XPlus_AIPin));
   Serial.print(" \tX-=");
   Serial.println(analogRead(XMinus_AIPin));
   
   delay(150);   
 }
 
}

cajunman64:

Quote from: cajunman64POT 0 to 1023 Input reading on Arduino:
Y POT Connected to A2: in Center Position reads 507, All the way forward reads 300, all the way backwards reads 711
+X POT Connected to A3: in Center Position reads 305, All the way to the right reads 712
-X POT Connected to A4: in Center Position reads 305, All the way to the Left reads 712

I would start with something like:

// Names for the Analog Input (AI) pins:
const byte Y_AIPin = A2; // Full Forward=300, Full Reverse = 711
const int Y_FullForward = 300;
const int Y_FullReverse = 711;


const byte XLeft_AIPin = A3;  // 305 to 712 left
const byte XRight_AIPin = A4; // 305 to 712 right


const int SteeringMax = 64;  // Adjust to get enough steering action.
const int ThrottleMax = 255 - SteeringMax;  // Allow room for steering without overflow.
const int DeadZone = 10;


void setup()
{
  // Initialize the motor control pins
}


void loop()
{
  int throttle = map(analogRead(Y_AIPin), Y_FullReverse, Y_FullForward, -ThrottleMax, ThrottleMax);
  int combinedX = analogRead(XRight_AIPin) - analogRead(XLeft_AIPin);  // -407 left to +407 right
  int steering = map(combinedX, -407, +407, -SteeringMax, +SteeringMax);


  // For the left motor, go faster for turning right (positive steering) and slower for turning left (negative steering)
  int speedLeft = constrain(throttle + steering, -255, +255);
  // Opposite for the right motor
  int speedRight = constrain(throttle - steering, -255, +255);


  // Run the motors:
  if (speedLeft < -DeadZone)
  {
    // Run left motor backwards at PWM -speedLeft
  }
  else if (speedLeft > DeadZone)
  {
    // Run left motor forward at PWM speedLeft
  }
  else
  {
    // Stop left motor
  }


  // Run the motors:
  if (speedRight < -DeadZone)
  {
    // Run right motor backwards at PWM -speedRight
  }
  else if (speedRight > DeadZone)
  {
    // Run right motor forward at PWM speedRight
  }
  else
  {
    // Stop right motor
  }
}