Two Servos with DC Motor Pot interference

I have a setup with two servos controlled by two pots and a DC motor (one direction) with a pot speed control. I have the servos powered at 5.5 v with a buck converter. The whole thing is powered by a bench top power supply at 12V. The DC motor is run by a L298N Dual H Bridge.

ok, it works ok, but what’s happening, is one of the servo pots affects the speed of the DC motor. I’ve tried different pins and same result. I even used separate 5V supply for the pots (one off the buck converter and one off the 298).

The other servo pot has no effect on the DC motor speed. Why is this? any ideas?

#include <Servo.h>

Servo servo1;
Servo servo2;

int potA = A0;
int val1;
int potB = A1;
int val2;

const int motor1Pin = 4; 
const int motor2Pin = 5;
const int enablePin = 6;
int potC = A2;
int motorSpeed;

void setup()
{

  Serial.begin(9600);

  servo1.attach(11);
  servo2.attach(12);

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(enablePin, OUTPUT);

  digitalWrite(enablePin, HIGH);

}

void loop()
{

  val1 = analogRead(potA);            // reads the value of the potentiometer (value between 0 and 1023)
  val1 = map(val1, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  servo1.write(val1);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there

  val2 = analogRead(potB);            // reads the value of the potentiometer (value between 0 and 1023)
  val2 = map(val2, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  servo2.write(val2);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there

  motorSpeed = analogRead(potC);
  digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
  digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
  motorSpeed = map(motorSpeed, 0, 1023, 0, 255);
  analogWrite(enablePin, motorSpeed);

  Serial.println(potC);

}

I assume you have 10k linear pots,
and are not sharing pot supply/ground with motor currents on a breadboard.

Try reading the pots twice in a row.
That will use the second, more stable value.
Leo..

What's the best way to read the pots twice in a row?

stevex:
What's the best way to read the pots twice in a row?

motorSpeed = analogRead(potC);
motorSpeed = analogRead(potC);

I knew that. lol.