Hi, I am new to arduino, and I am trying to use a linear actuator with a built in pot have it's position controlled by a different linear pot. So moving the external pot should move the actuator to a corresponding position. The coding I am using is from Firgelli automation on their tutorial on how to do this. I have a BTS7960 IC high current dc motor driver to control the actuator, run by pin 9 and 10 on the pwm out. My question is, When I have the pot plugged in on it's own, in the serial monitor it shows the range as 0-1023 as I move it, as it should. But if I have the pot for the actuator, or "sensor" as this code refers to, it shows both readings as about 960 and the values do not change as I move the pot. Also, the serial monitor has a read function for "pot position" and "sensor position", and my understanding of the code is that the sensor position should show position of the actuator, and pot position should show position of the pot. However, If I plug the pot signal pin into either A0 or A1, it shows it under "sensor position" regardless of which pin it is plugged into, and pot position shows 0. I have tried reassigning pins to pins A1 and A2, and A2 and A3, and still the same problem. I did have a little bit of an arc issue where a wire for the ground touched the 12V supply. Could my board be toast? Or am I doing something wrong/is there something wrong with some of the code? I will attach a schematic of how it is wired and of the code.
Thanks in advance,
-Jared
/* Firgelli Automations
* Limited or no support: we do not have the resources for Arduino code support
*
* Program enables momentary direction control of actuator using push button
*/
#include <elapsedMillis.h>
elapsedMillis timeElapsed;
int RPWM = 10;
int LPWM = 11;
int sensorPin = A0;
int potPin = A1;
int potVal;
int sensorVal;
int Speed = 255;
int Buffer = 4;
int maxAnalogReading;
int minAnalogReading;
void setup() {
pinMode(RPWM, OUTPUT);
pinMode(LPWM, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(potPin, INPUT);
Serial.begin(9600);
maxAnalogReading = moveToLimit(1);
minAnalogReading = moveToLimit(-1);
}
void loop(){
potVal = map(analogRead(potPin), 0, 1023, minAnalogReading, maxAnalogReading);
sensorVal = analogRead(sensorPin);
if(potVal > (sensorVal+Buffer)){ //addition gives buffer to prevent actuator from rapidly vibrating due to noisy data inputs
driveActuator(1, Speed);
}
else if(potVal < (sensorVal-Buffer)){
driveActuator(-1, Speed);
}
else{
driveActuator(0, Speed);
}
Serial.print("Potentiometer Reading: ");
Serial.print(potVal);
Serial.print("\tActuator reading: ");
Serial.println(sensorVal);
delay(10);
}
int moveToLimit(int Direction){
int prevReading=0;
int currReading=0;
do{
prevReading = currReading;
driveActuator(Direction, Speed);
timeElapsed = 0;
while(timeElapsed < 200){ delay(1);} //keep moving until analog reading remains the same for 200ms
currReading = analogRead(sensorPin);
}while(prevReading != currReading);
return currReading;
}
void driveActuator(int Direction, int Speed){
switch(Direction){
case 1: //extension
analogWrite(RPWM, Speed);
analogWrite(LPWM, 0);
break;
case 0: //stopping
analogWrite(RPWM, 0);
analogWrite(LPWM, 0);
break;
case -1: //retraction
analogWrite(RPWM, 0);
analogWrite(LPWM, Speed);
break;
}
}

Hopefully that worked for the image of the drawing. How do I attach a JPEG?Preformatted text
