This circuit controls two linear actuators using an L298N motor driver and an Arduino UNO. The actuators extend 4 inches when a button is pressed and retract to zero when another button is pressed. The actuators move at a rate of 0.31 inches per second.
Actuator Motor
Tactile Switch Buttons - 12mm Square
L298N DC Motor Driver
Arduino UNO
12V Power Supply
Resistor
/*
* This Arduino sketch controls two linear actuators using an L298N motor driver.
* The actuators extend 4 inches when a button is pressed and retract to zero
* when another button is pressed. The actuators move at a rate of 0.31 inches
* per second.
*/
const int buttonExtend1 = 8; // Button to extend actuator 1
const int buttonRetract1 = 9; // Button to retract actuator 1
const int buttonExtend2 = 10; // Button to extend actuator 2
const int buttonRetract2 = 11; // Button to retract actuator 2
const int in1 = 2; // L298N IN1
const int in2 = 3; // L298N IN2
const int in3 = 4; // L298N IN3
const int in4 = 5; // L298N IN4
const int actuatorTime = 12903; // Time to move 4 inches at 0.31 inches/sec
void setup() {
pinMode(buttonExtend1, INPUT);
pinMode(buttonRetract1, INPUT);
pinMode(buttonExtend2, INPUT);
pinMode(buttonRetract2, INPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop() {
if (digitalRead(buttonExtend1) == HIGH) {
extendActuator(in1, in2);
} else if (digitalRead(buttonRetract1) == HIGH) {
retractActuator(in1, in2);
}
if (digitalRead(buttonExtend2) == HIGH) {
extendActuator(in3, in4);
} else if (digitalRead(buttonRetract2) == HIGH) {
retractActuator(in3, in4);
}
}
void extendActuator(int pin1, int pin2) {
digitalWrite(pin1, HIGH);
digitalWrite(pin2, LOW);
delay(actuatorTime);
digitalWrite(pin1, LOW);
}
void retractActuator(int pin1, int pin2) {
digitalWrite(pin1, LOW);
digitalWrite(pin2, HIGH);
delay(actuatorTime);
digitalWrite(pin2, LOW);
}
This code initializes the pins for the buttons and motor driver, and in the main loop, it checks the state of the buttons to control the extension and retraction of the actuators. The extendActuator
and retractActuator
functions handle the actual movement of the actuators by setting the appropriate pins on the motor driver.