Help with Motorized faders

Hi, I am new at programming with Arduino. I have been trying to make the faders move and stop at the right position. I am trying to use the following approach: I need the potentiometer to move to 555 so I wrote some code that adds and subtracts 5 of the desire number. (550-560) so I need the fader to stop at any point in between that set of numbers. I am trying to make the motor go slower so that the fader has less inertia and is easier to control. I am encountering a problem that says that "too many arguments to function 'void L293D'". Im not sure what to do about this, and id appreciate some advise. I am driving the motor with an H bridge.

#define P1A 6 
#define P2A 5 
#define EN12 9
void L293D ();
int potmeterPin = A0;              
int currentpot = 0;               
int potmeterPin2 = A3;
int potmeterVal2 = 0;
int upperset;
int lowerset;
const int motorDown = 5; 
const int motorUp = 6;
const int speedStep =15;
const int speedDelay = 1000;



void setup() {
  Serial.begin(9600); 
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT); 
  pinMode(P1A, OUTPUT);
  pinMode(P2A, OUTPUT);
  pinMode(EN12, OUTPUT);
 
}

void loop() {
  
  currentpot = analogRead(potmeterPin);    
  Serial.println(currentpot);
    
potmeterVal2 = analogRead(potmeterPin2);
Serial.println(potmeterVal2);

  
  
upperset = potmeterVal2 + 5;
 Serial.println(upperset); 
 lowerset = potmeterVal2 - 5;
 Serial.println(lowerset);

  if ( currentpot > lowerset) {
if (currentpot == lowerset){
L293D('R',90, 0);// stop motor
  delay(2000);
}
else (currentpot >= lowerset) { 
L293D('R',90, 0);// stop motor
  delay(2000);
}

}


Function Code

void L293D(char dir,int spd, int en)
{
  if(dir =='L')
  {
    if(en ==0){
       Serial.println(" CW Motor Stopped");
    }else{
       Serial.print(" Rotating CW: "); 
       Serial.println(spd);       
    }
    digitalWrite(EN12 ,en);
    analogWrite(P1A,spd);
    digitalWrite(P2A,LOW);       
   
  }else{
    if(en ==0){
       Serial.println(" CCW Motor Stopped");
    }else{
       Serial.print(" Rotating CCW: "); 
       Serial.println(spd);   
    }    
    digitalWrite(EN12 ,en);    
    digitalWrite(P1A,LOW);
    analogWrite(P2A,spd); 
  }
}

Hello cambodromo3
Try this modified sketch.

#define P1A 6
#define P2A 5
#define EN12 9
void L293D ();
int potmeterPin = A0;
int currentpot = 0;
int potmeterPin2 = A3;
int potmeterVal2 = 0;
int upperset;
int lowerset;
const int motorDown = 5;
const int motorUp = 6;
const int speedStep = 15;
const int speedDelay = 1000;

void setup() {
  Serial.begin(9600);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(P1A, OUTPUT);
  pinMode(P2A, OUTPUT);
  pinMode(EN12, OUTPUT);

}

void loop() {

  currentpot = analogRead(potmeterPin);
  Serial.println(currentpot);

  potmeterVal2 = analogRead(potmeterPin2);
  Serial.println(potmeterVal2);

  upperset = potmeterVal2 + 5;
  Serial.println(upperset);
  lowerset = potmeterVal2 - 5;
  Serial.println(lowerset);

  if ( currentpot > lowerset) {
    if (currentpot == lowerset) {
      L293D('R', 90, 0); // stop motor
      delay(2000);
    }
    else if (currentpot >= lowerset) {
      L293D('R', 90, 0); // stop motor
      delay(2000);
    }

  }
}
//  Function Code

void L293D(char dir, int spd, int en)
{
  if (dir == 'L')
  {
    if (en == 0) {
      Serial.println(" CW Motor Stopped");
    } else {
      Serial.print(" Rotating CW: ");
      Serial.println(spd);
    }
    digitalWrite(EN12 , en);
    analogWrite(P1A, spd);
    digitalWrite(P2A, LOW);

  } else {
    if (en == 0) {
      Serial.println(" CCW Motor Stopped");
    } else {
      Serial.print(" Rotating CCW: ");
      Serial.println(spd);
    }
    digitalWrite(EN12 , en);
    digitalWrite(P1A, LOW);
    analogWrite(P2A, spd);
  }
}

Have a nice day and enjoy programming in C++ and learning.
MIND THE GAP

Here is your code with corrections, formatted and posted according to the forum guidelines. You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar after formatting the code with the IDE autoformat function (ctrl-t or Tools, Auto Format).
code tags new

#define P1A 6
#define P2A 5
#define EN12 9
void L293D ();
int potmeterPin = A0;
int currentpot = 0;
int potmeterPin2 = A3;
int potmeterVal2 = 0;
int upperset;
int lowerset;
const int motorDown = 5;
const int motorUp = 6;
const int speedStep = 15;
const int speedDelay = 1000;

void setup()
{
   Serial.begin(9600);
   pinMode(5, OUTPUT);
   pinMode(6, OUTPUT);
   pinMode(P1A, OUTPUT);
   pinMode(P2A, OUTPUT);
   pinMode(EN12, OUTPUT);

}

void loop()
{

   currentpot = analogRead(potmeterPin);
   Serial.println(currentpot);

   potmeterVal2 = analogRead(potmeterPin2);
   Serial.println(potmeterVal2);

   upperset = potmeterVal2 + 5;
   Serial.println(upperset);
   lowerset = potmeterVal2 - 5;
   Serial.println(lowerset);

   if ( currentpot > lowerset)
   {
      if (currentpot == lowerset)
      {
         L293D('R', 90, 0); // stop motor
         delay(2000);
      }
      else if (currentpot >= lowerset)  // ********* added if
                                        // else can't have an argument
      {
         L293D('R', 90, 0); // stop motor
         delay(2000);
      }
   }
} // ****************** added }

// Function Code  ******************* added //

void L293D(char dir, int spd, int en)
{
   if (dir == 'L')
   {
      if (en == 0)
      {
         Serial.println(" CW Motor Stopped");
      }
      else
      {
         Serial.print(" Rotating CW: ");
         Serial.println(spd);
      }
      digitalWrite(EN12 , en);
      analogWrite(P1A, spd);
      digitalWrite(P2A, LOW);

   }
   else
   {
      if (en == 0)
      {
         Serial.println(" CCW Motor Stopped");
      }
      else
      {
         Serial.print(" Rotating CCW: ");
         Serial.println(spd);
      }
      digitalWrite(EN12 , en);
      digitalWrite(P1A, LOW);
      analogWrite(P2A, spd);
   }
}

Your code was missing a } to close loop(), a comment symbol before " Function Code" and an if with the else with arguments.

Thank you for the help, now I don't get the that error.

I want to be able to move the motor until it reaches at certain point inside the set of numbers described on the post. I have a 2nd potentiometer attached and I want the motorized fader to mimic what that potentiometer is doing to a 5+- or error?, any thoughts on how is the best way to accomplish this? I am using an H gate to control the motor

Did you try the code in post #2?

I did with a good result, the fader just goes to one side and stays there

What error ?

"too many arguments to function 'void L293D'" , its not happening anymore

Then why not just run with that code, adapt it as needed to your use case?

sorry I misspelled *without. its not working as I want

How does your program know the position of the fader motor? Is there positional feedback to the program from the fader motor?

Please post a schematic diagram of the system. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

In what way(s), precisely?

this is secret and classified :nerd_face:

I am using a motorized potentiometer, an H gate, one rotatory potentiometer, 1 9v battery as the power supply for the H Bridge L293D.

The pins are as follows.
pin 3 is the values coming from the rotatory potentiometer (values 0-1023)

pin5 is P2A on the H Bridge

pin6 is P2A on the H Bridge

pin 9 is EN12 on the H Bridge

pin 0 is the values coming from the motorized fader (that's how it nows where it is at any given moment) (values 0-1023)

the motor its just staying in one side instead of following the values that the second potentiometer is giving

I would love to have access to that classified information :sweat_smile:

For the purposes of a system that works, photos and text are sufficient. But for a system that doesn't work, the verification of a real schematic is an absolute necessity. Please provide one.

what tool can I use to create a schematic that is easy to read?

Has the system hardware ever been proven? This could be a wiring or design flaw.

A pen. I use KiCad, but it takes a while to learn.