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
L298N DC Motor Driver
Arduino UNO
12V Power Supply
Tactile Switch Buttons - 12mm Square
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 in1 = 2; // L298N IN1 connected to Arduino D2
const int in2 = 3; // L298N IN2 connected to Arduino D3
const int in3 = 4; // L298N IN3 connected to Arduino D4
const int in4 = 5; // L298N IN4 connected to Arduino D5
const int buttonExtend = 8; // Button to extend actuators connected to D8
const int buttonRetract = 9; // Button to retract actuators connected to D9
const int actuatorTime = 12903; // Time to move 4 inches (4 / 0.31 * 1000)
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(buttonExtend, INPUT);
pinMode(buttonRetract, INPUT);
}
void loop() {
if (digitalRead(buttonExtend) == HIGH) {
extendActuators();
}
if (digitalRead(buttonRetract) == HIGH) {
retractActuators();
}
}
void extendActuators() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(actuatorTime);
stopActuators();
}
void retractActuators() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(actuatorTime);
stopActuators();
}
void stopActuators() {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
This code initializes the pins connected to the L298N motor driver and the buttons. It then continuously checks the state of the buttons to either extend or retract the actuators. The actuators are controlled by setting the appropriate pins on the L298N motor driver high or low.