0

I have a linear actuator that I want to be able to slow down. Right now, the shaft moves too quickly. I'm not sure how to do this. I was looking into varSpeedServo.h library but couldn't implement it.

//Includes
#include <Servo.h> 

//Defines
#define LINEARACTUATORPIN 9        //Linear Actuator Digital Pin



const int button1Pin = 4;     // the number of the pushbutton pin


// variables will change:
int button1State = 0;         // variable for reading the pushbutton status


Servo LINEARACTUATOR;  // create servo objects to control the linear actuator

int linearValue = 10000;   //current positional value being sent to the linear actuator. 

void setup() 
{ 
  //initialize servo/linear actuator objects
  LINEARACTUATOR.attach(LINEARACTUATORPIN, 1050, 2000);      // attaches/activates the linear actuator as a servo object 

  // initialize the pushbutton pin as an input:
  pinMode(button1Pin, INPUT);   


  //use the writeMicroseconds to set the linear actuators to their default positions
  LINEARACTUATOR.writeMicroseconds(linearValue); 

} 

void loop() 
{ 

  // if the pushbutton is pressed set the linear value
  button1State = digitalRead(button1Pin);
  if (button1State == HIGH) {    
    // set the position value  
    delay(2000);  
    linearValue = 1050; 

  } 

    if (button1State == LOW) {    
    // set the position value  
    linearValue = 2000;  
  } 

  //use the writeMicroseconds to set the actuator to the new position
  LINEARACTUATOR.writeMicroseconds(linearValue); 
delay(3000);  
} 
0

Have you tried something like the following?

#define STEP 50

void loop() 
{ 

  // if the pushbutton is pressed set the linear value
  button1State = digitalRead(button1Pin);
  if (button1State == HIGH) {    
    // set the position value  
    if (linearValue > 1050)
       linearValue = max(linearValue-STEP,1050) ; 

  } 

    if (button1State == LOW) {    
    // set the position value  
    if (linearValue < 2000) 
       linearValue = min(linearValue+50,2000) ;  
  } 

  //use the writeMicroseconds to set the actuator to the new position
  LINEARACTUATOR.writeMicroseconds(linearValue); 
  delay(100);  
} 

By changing the STEP value (or the delay in the next-to-last line) you can change the speed of the servo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.