Actuator Control with Arduino and Motor Driver

Hi, we are trying to use a switch to control a linear actuator. During steady state, we want the actuator to constantly be retracting and then when the switch is activated we want the actuator to extend. Currently, we have gotten the actuator extend constantly, and once the switch is activated, it stops the actuator from moving any further, until the switch is released. We have also gotten this action to happen in reverse, meaning the actuator only extends while the switch is held in its enabled position. The motor driver we are currently using can be found [Pololu - VNH2SP30 Motor Driver Carrier MD01B]here. Again, we need the actuator to constantly be in the retracting position, and once the switch is pressed, it changes the direction, extending the actuator. The driver is an H-bridge and that is how we have been trying to deal with achieving the two different directions for the actuator to travel in. Our current code is as follows:

int posy = 3; // positive y button
int negy = 4; // negative y button
int t_actuatorA = 8; // Throttle Actuator In A
int t_actuatorB = 9; // Throttle Actuator In B

int b_actuatorA = 10; // Brake Actuator In A
int b_actuatorB = 11; // Brake Actuator In B

// variables will change:
int forward = 0;
int brake = 0;

// variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(t_actuatorA, OUTPUT);
pinMode(t_actuatorB, OUTPUT);
pinMode(posy, INPUT);
pinMode(b_actuatorA, OUTPUT);
pinMode(b_actuatorB, OUTPUT);
pinMode(negy, INPUT);
}

void loop(){
// read the state of the pushbutton value:
forward = digitalRead(posy);
brake = digitalRead(negy);

if (forward == LOW && brake == LOW) { // initiate actuators as LOW = STEADY STATE
digitalWrite(t_actuatorA, HIGH);
digitalWrite(t_actuatorB, LOW);
digitalWrite(b_actuatorA, HIGH);
digitalWrite(b_actuatorB, LOW);
}

else if (forward == LOW && brake == HIGH) { // if brake button is switched
digitalWrite(t_actuatorA, LOW);
digitalWrite(t_actuatorB, HIGH);
digitalWrite(b_actuatorA, LOW);
digitalWrite(b_actuatorB, HIGH);
}
else if (forward == HIGH && brake == LOW) { //if throttle button is switched
digitalWrite(t_actuatorA, LOW);
digitalWrite(t_actuatorB, HIGH);
digitalWrite(b_actuatorA, HIGH);
digitalWrite(b_actuatorB, LOW);
}
}

Thanks

Read this before posting a programming question

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

stevekap25:
Hi, we are trying to use a switch to control a linear actuator. During steady state, we want the actuator to constantly be retracting and then when the switch is activated we want the actuator to extend. Currently, we have gotten the actuator extend constantly, and once the switch is activated, it stops the actuator from moving any further, until the switch is released. We have also gotten this action to happen in reverse, meaning the actuator only extends while the switch is held in its enabled position. The motor driver we are currently using can be found [Pololu - VNH2SP30 Motor Driver Carrier MD01B]here. Again, we need the actuator to constantly be in the retracting position, and once the switch is pressed, it changes the direction, extending the actuator. The driver is an H-bridge and that is how we have been trying to deal with achieving the two different directions for the actuator to travel in. Our current code is as follows:

int posy = 3;     // positive y button

int negy = 4;        // negative y button
int t_actuatorA =  8;      // Throttle Actuator In A
int t_actuatorB = 9; // Throttle Actuator In B

int b_actuatorA =  10;      // Brake Actuator In A
int b_actuatorB = 11; // Brake Actuator In B

// variables will change:
int forward = 0; 
int brake = 0;

// variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
pinMode(t_actuatorA, OUTPUT);     
pinMode(t_actuatorB, OUTPUT);     
pinMode(posy, INPUT);   
pinMode(b_actuatorA, OUTPUT);
pinMode(b_actuatorB, OUTPUT);
pinMode(negy, INPUT);
}

void loop(){
  // read the state of the pushbutton value:
  forward = digitalRead(posy);
  brake = digitalRead(negy);

if (forward == LOW && brake == LOW) {    // initiate actuators as LOW = STEADY STATE
digitalWrite(t_actuatorA, HIGH);
digitalWrite(t_actuatorB, LOW);
digitalWrite(b_actuatorA, HIGH); 
digitalWrite(b_actuatorB, LOW); 
}

else if (forward == LOW && brake == HIGH) { // if brake button is switched
digitalWrite(t_actuatorA, LOW);
digitalWrite(t_actuatorB, HIGH);
digitalWrite(b_actuatorA, LOW);
digitalWrite(b_actuatorB, HIGH);
}
else if (forward == HIGH && brake == LOW) { //if throttle button is switched
digitalWrite(t_actuatorA, LOW);
digitalWrite(t_actuatorB, HIGH);
digitalWrite(b_actuatorA, HIGH);
digitalWrite(b_actuatorB, LOW);
}
  }




Thanks

Look to me like it will only react when the button is down. Read this please:

It would be good to mention how the switches are wired. Using the internal pullup resistors makes wiring far simpler.