Automatic control of feedback linear actuator to a desired position

I want to move my feedback linear actuator automatically without using push buttons
The stroke of linear actuator is 4 inches
The maximum analog at 4 inches is 951
The minimum analog at 0 inches is 44
so i can have maximum of just 1 inch and move it automatically to this position
I send you my code using 2 push buttons

float pos; // Actuator Position

void setup() {
pinMode(A1, INPUT); // Configure Analog In pin 1 as an Input
pinMode(10, OUTPUT); // Configure pin 10 as an Output
pinMode(11, OUTPUT); // Configure pin 11 as an Output
pinMode(2, INPUT_PULLUP); // Input for Button
pinMode(3, INPUT_PULLUP); // Input for Button

Serial.begin(9600);
}

void loop() {
if(digitalRead(2) == HIGH & digitalRead(3) == LOW){
// Retract Actuator
analogWrite(10, 0);
analogWrite(11, 255);
pos = readPotentiometer(); // Print position value to the Serial Display
Serial.println(pos);
delay(1);
}
else if(digitalRead(2) == LOW & digitalRead(3) == HIGH){
// Extend Actuator
analogWrite(10, 255);
analogWrite(11, 0);
pos = readPotentiometer();
Serial.println(pos); // Print position value to the Serial Display
delay(1);
}
else{
// Stop Actuator
analogWrite(10, 0);
analogWrite(11, 0);
}
}

/Function to Read Potentiometer and Convert it to Inches/
float readPotentiometer(void){
return analogRead(A1);
}Preformatted text

Please edit your post to add code tags, as described in the "How to get the best out of the forum" post.

To get started, you will need to determine how the potentiometer reading is related to the extension of the actuator.

And it would be of immense help if you could supply a link to the detailed information on your linear actuator so we can all look at the information while you look at the information.

I mentioned it in the code at maximum extension it is 951 and at minimum retraction it is 44 but my question how to control it automatically because i used 2 push buttons and to make my desire stroke be at 1 inch maximum

Please edit your post to add code tags.

Move the actuator until the potentiometer reads the value expected for 1 inch extension.

how i can add code tags to my post ?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.