Potentiometer Not Reading Properly (Linear Actuators)

Hello,
I have recently started a project to move linear actuators when I move a toggle switch. I have gotten them to move with the switch, but I run into a problem with the potentiometer feedback of the actuators.

When I start to move the actuators the Pot reads 0 for about 2 inches; then goes in increments of 4 until about 80; then jumps all the way to 500; then from 500-750 it seems to run fine; then after that it jumps all the way to 1023 but the actuator isn’t full extended yet.

There is 12v being used to power the motors of the actuators and 6v being used to power the potentiometers of them actuators.

I have attached the code and specs of the actuator. If anyone has any idea of what I’m doing wrong, please help. I would be eternally grateful.

Thanks.

#include "CytronMotorDriver.h"
#include <stdio.h>

// Configure the motor driver.
CytronMD motor1(PWM_DIR, 3, 2); //PWM = Pin 3, DIR = Pin 2.
CytronMD motor2(PWM_DIR, 5, 2); //PWM = Pin 5, DIR = Pin 2.

int val = 0;

//Actuator Pots
int motor1Pot = A1;
int motor2Pot = A2;

//Toggle Switch
int keyUp = A0;
int keyDown = A5;

int m1PotVal;
int m2PotVal;
int m1PotValMap;
int m2PotValMap;

int sped=0;
void setup() {
  Serial.begin(9600);
  pinMode(keyUp, INPUT);
  pinMode(keyDown, INPUT);

  pinMode(motor1Pot, INPUT);
  pinMode(motor2Pot, INPUT);
}

void loop(){
  readPots();
  sped=0;
  Serial.print(analogRead(keyUp));
  Serial.print("      ");
  Serial.print(analogRead(keyDown));
  Serial.print("      ");
   
  if(analogRead(keyDown) == 1023){
    sped=255;
  }
     
  if(analogRead(keyUp)==1023){
    sped=-255;
  }
  motor1.setSpeed(sped);
  motor2.setSpeed(sped);
  delay(1);
}

void readPots(){
  m1PotVal = 0;
  m2PotVal = 0;
  
  m1PotVal = analogRead(motor1Pot);
  m2PotVal = analogRead(motor2Pot);

  Serial.print(m1PotVal);
  Serial.print("      ");
  Serial.print(m2PotVal);
  Serial.println(); 
}

Linear_Actuator_with_Potentiometer_PA-14P.pdf (1.72 MB)

There are some problems possible:

  • If you use a 5V-based board, the 6 volt served analogue input will give you not always correct values. The drive spec said, you should give 5V to the poti.
  • Correct grounding is an important point too.

If your cabeling an power concept is OK, then the best way is a calibration, like analogue value = f(stroke).

Derekbird02: There is 12v being used to power the motors of the actuators and 6v being used to power the potentiometers of them actuators.

You should check the output of your potentiometer with multimeter, and check whether you are getting a linear rise in voltage, I think you are not.

Moreover, in Arduino coding, if you are getting 5V on the pin then that means 1024 and as you are using 6V so clearly after 5V there won't be any increment in the value and it will remain 1024.

When I use a multi meter it works fine, and I switched the Pot voltage to a little less than 5v but I still run into the problem where they are fully retracted then I start to raise them they don’t start changing for a few inches, then it goes from 4-6-8-16-32-48-64-96 then jumps to 500ish then works perfectly fine all the way up but when I let go of the switch it goes to 1023.

Do you know why that might be doing that once I let go of the switch? Because it reads like 760ish while its fully extended and Im still holding the switch up but as soon as I let go goes to 1023