I am relatively new to this and am currently trying to make a project that has a linear actuator ( L12-R) to move a part of it,
This movement is controlled by an arduino nano and 2 non latching push buttons, 1 to move the actuator in and the other to move it out , when no button is pressed i would like the position to be held.
Having read that the actuator could directly replace a servo i set everything up and tested using a basic servo and the below code… all worked perfectly and i hoped to simply replace the servo with the actuator.
Once i had received the actuator and put it into the system i found i had very little control over it, i could change its direction but it would continue moving and not hold a position when the button was released.
Does the actuator position relate to the angular position of the servo ie 0-180 maps to 0- 100mm of travel?
Any help would be appreciated as i seem to be going round in circles.
arduino code as sourced from instructables.com/id/Servo-C … shbuttons/
[code]#include <Servo.h>
const int buttonPin = 2;
const int buttonPin2 = 4;
int buttonState = 0;
int buttonState2 = 0;
Servo servoA;
int position = 0;
void setup() {
servoA.attach(9);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2,INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
if(buttonState ==HIGH && position < 180){
servoA.write(position++);
delay(5);
}
if(buttonState2 == HIGH && position > 3){
servoA.write(position–);
delay(5);
}
}[/code]