Hello,
I have a small Actuonix (Firgelli) Linear Actuator with built in potentiometer for position feedback (which shows position of the linear actuators tip 0-1000,). I would like to program it to move to position A, then position B, then position C.
I have it successfully running backward and forward. My program allows me to set the speed and duration the linear actuator should move forward and backward, but I cannot figure out how to control it by position. I tried with a series of If and else statements but this did not work and in theory could only make it move to position a and back to position b in a loop. I require 3 positions.
Does anyone have any ideas how I could do this? I am new to Arduino, so would very much appreciate and be grateful for your advice.
Extra Info: I am using an Uno, I have attached my code, the Linear actuator specifications (I am using the 6V L12-P 30cm stroke), and I am also using a TB6612FNG Dual Motor Driver Carrier.
#define AIN1 2
#define BIN1 7
#define AIN2 4
#define BIN2 8
#define PWMA 5
#define PWMB 6
#define STBY 9
const int feedback = A0; //potentiometer from actuator
int position_LA = 0; //potentiometer from actuator
int prev;
void setup()
{
pinMode(feedback, INPUT);//feedback from actuator
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(STBY, OUTPUT);
Serial.begin(9600);
enable();
}
void loop()
{
prev = position_LA;
position_LA = analogRead(A0); // read the input on analog pin 0:
if((position_LA >= prev) && position_LA < 750)
{
fwd(150);
}
else if (( position_LA < prev) && position_LA > 250)
{
rev(150);
}
delay(20);
Serial.print(" Position LA = ");
Serial.println(position_LA);
}//end void loop
void fwd(int speed)
{ digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, speed);
}
void rev(int speed)
{ digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);
analogWrite(PWMA, speed);
}
void brake()
{ digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, HIGH);
analogWrite(PWMA, 0);
}
void standby()
{ digitalWrite(STBY, LOW);
}
void enable()
{ digitalWrite(STBY, HIGH);
}
If I wanted to move backward or forward I would put...
//reverse for 2 seconds
rev(155); //reverse at speed 155
delay(2000); //for 2 seconds
or
fwd(155);
delay(2000)
As I mentioned, new to Arduino so If you have a better way of doing this would appreciate the advice.
Thanks for reading this and for future advice!
Melissa