Linear Actuator

Hello, I am fairly new to Arduino. I am Using an Arduino Uno with a HiLetgo BTS7960 43A High Power Motor Driver to control a 12v Linear actuator. I need it to open for 36 seconds when one button is pushed and close when a second button is pushed ( I have this part working). I need help with overriding the opening if the reverse button is pushed and vice versa for safety purposes.

byte mspeed=0;         // Variable speed for actuator
int ForwardActuator=5; // Pin for Linear actuator
int ReverseActuator=6; // Pin for Linear actuator


void setup(){
  
       pinMode(2,INPUT_PULLUP);         // Button to extend Actuator
       pinMode(3,INPUT_PULLUP);         // Button to retract Actuator

       pinMode(ForwardActuator,OUTPUT);
       pinMode(ReverseActuator,OUTPUT);

}
 void loop(){
  if(digitalRead(2)== LOW & digitalRead(3)==HIGH){
      mspeed=255;                           // Speed of actuator
      analogWrite(ForwardActuator,0);       // Sets the forward speed to 0
      analogWrite(ReverseActuator,mspeed);  // sets the reverse speed to max
      delay(36000);                         // Allows actuator to close for 36 seconds
  }
   else if(digitalRead(2)== HIGH & digitalRead(3)==LOW){
       mspeed=255;                          // Speed of actuator
       analogWrite(ForwardActuator,mspeed); // Sets the open speed to max
       analogWrite(ReverseActuator,0);      // Sets the reverse speed to 0
       delay(36000);                        // Allows actuator to open for 36 seconds
  } 
 
 }

I appreciate all help, Thank you!

Obviously, you have to get rid of the delays - you can't read a switch during a delay.

Take a look at blink without delay in the IDE, or the "doing multiple things at the same time" tutorial.

BlinkWithoutDelay

Arduino Multiple Things

Several Things at a Time

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