Using 2 linear actuator with 4 limit switches


NEVER connect a motor directly to an Arduino, it would damage the Arduino.

I found this article that talks about how to use arduino with actuator, and they also provided an example of the code. But I am not sure how should I add the button into this code.

this is the link to the post: Using Relay And Arduino To Control Linear Actuator – Progressive Automations

Here is the code:

const int forwards = 7;
const int backwards = 6;//assign relay INx pin to arduino pin
void setup() {
pinMode(forwards, OUTPUT);//set relay as an output
pinMode(backwards, OUTPUT);//set relay as an output
}
void loop() {
 digitalWrite(forwards, LOW);
 digitalWrite(backwards, HIGH);//Activate the relay one direction, they must be different to move the motor
 delay(2000); // wait 2 seconds
 digitalWrite(forwards, HIGH);
 digitalWrite(backwards, HIGH);//Deactivate both relays to brake the motor
 delay(2000);// wait 2 seconds
 digitalWrite(forwards, HIGH);
 digitalWrite(backwards, LOW);//Activate the relay the other direction, they must be different to move the motor
 delay(2000);// wait 2 seconds
 digitalWrite(forwards, HIGH);
 digitalWrite(backwards, HIGH);//Deactivate both relays to brake the motor
 delay(2000);// wait 2 seconds
}

You can't use delay if You want to check buttons or end swiches.
Look for the topics "Blink without dekay", "Doing several things at the same time".

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