How to Control Large Linear Actuators with Arduino
Source: InternetPublisher:qoistoochee128 Keywords: Actuator Arduino Updated: 2024/05/27
This article will show you how to use an Arduino and two buttons to perform basic manual control of a large linear actuator. In the first set of code, the first button extends the actuator and the second button retracts the actuator. In the second set of code, the two buttons move the linear actuator to a preset position.
Large linear actuators traditionally have five wires. Two wires are used to power the motor and three wires go to an internal potentiometer to read the position. The two relays are used to switch the positive and negative power to the motor to determine the direction the piston will travel. The first bit of the code does not use this, the second does to achieve the target position. Let's get started.
Step 1: Wiring
Step 2: Code 1 - Manual Control
This section of code shows how to use an Arduino and two buttons to do basic manual control of a large linear actuator. The first button extends the actuator and the second button retracts it.
const int button1Pin = 2; // the number of the pushbutton1 pin
const int button2Pin = 4; // the number of the pushbutton2 pin
const int relay1Pin = 7; // the number of the Realy1 pin
const int relay2Pin = 8; // the number of the Relay2 pin
// variables will change:
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status
const int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
//start serial connection
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
// initialize the relay pin as an output:
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
}
void loop(){
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
//print out the value of the pushbutton
Serial.println(sensorValue);
// read the state of the pushbutton values:
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
// check if the pushbutton1 is pressed.
// if it is, the buttonState is HIGH:
// we also ensure tha the other button is not pushed to avoid conflict
if (button1State == HIGH && button2State == LOW) {
// turn relay1 on:
digitalWrite(relay1Pin, HIGH);
}
// When we let go of the button, turn off the relay
else if (digitalRead(relay1Pin) == HIGH) {
// turn relay1 off:
digitalWrite(relay1Pin, LOW);
}
// repeat the same procedure for the second pushbutton
if (button1State == LOW && button2State == HIGH) {
// turn relay2 on:
digitalWrite(relay2Pin, HIGH);
}
// When we let go of the button, turn off the relay
else if (digitalRead(relay2Pin) == HIGH) {
// turn relay2 off:
digitalWrite(relay2Pin, LOW);
}
}
Step 3: Code 2 - Preset Position Using Position Feedback
This section of code shows how to do basic control of a large linear actuator using an Arduino and two buttons, each preset to a position.
const int button1Pin = 2; // the number of the pushbutton1 pin
const int button2Pin = 4; // the number of the pushbutton2 pin
const int relay1Pin = 7; // the number of the Realy1 pin
const int relay2Pin = 8; // the number of the Relay2 pin
const int sensorPin = 0; // select the input pin for the potentiometer
// variables will change:
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status
int sensorValue = 0; // variable to store the value coming from the sensor
int goalPosition = 350;
int CurrentPosition = 0;
boolean Extending = false;
boolean Retracting = false;
void setup() {
//start serial connection
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
// initialize the relay pin as an output:
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
//preset the relays to LOW
digitalWrite(relay1Pin, LOW);
digitalWrite(relay2Pin, LOW);
}
void loop(){
// read the value from the sensor:
CurrentPosition = analogRead(sensorPin);
// print the results to the serial monitor:
Serial.print(“Current = ” );
Serial.print(CurrentPosition);
Serial.print(“ Goal = ”);
Serial.println(goalPosition);
// read the state of the pushbutton values:
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
if (button1State == HIGH) {
// set new goal position
goalPosition = 300;
if (goalPosition 》 CurrentPosition) {
Retracting = false;
Extending = true;
digitalWrite(relay1Pin, HIGH);
digitalWrite(relay2Pin, LOW);
Serial.println(“Extending”);
}
else if (goalPosition 《 CurrentPosition) {
Retracting = true;
Extending = false;
digitalWrite(relay1Pin, LOW);
digitalWrite(relay2Pin, HIGH);
Serial.println(“Retracting”);
}
}
if (button2State == HIGH) {
// set new goal position
goalPosition = 500;
if (goalPosition 》 CurrentPosition) {
Retracting = false;
Extending = true;
digitalWrite(relay1Pin, HIGH);
digitalWrite(relay2Pin, LOW);
Serial.println(“Extending”);
}
else if (goalPosition 《 CurrentPosition) {
Retracting = true;
Extending = false;
digitalWrite(relay1Pin, LOW);
digitalWrite(relay2Pin, HIGH);
Serial.println(“Retracting”);
}
}
if (Extending = true && CurrentPosition 》 goalPosition) {
//we have reached our goal, shut the relay off
digitalWrite(relay1Pin, LOW);
boolean Extending = false;
Serial.println(“IDLE”);
}
if (Retracting = true && CurrentPosition 《 goalPosition){
//we have reached our goal, shut the relay off
digitalWrite(relay2Pin, LOW);
boolean Retracting = false;
Serial.println(“IDLE”);
}
}
The above is all the functional code required for the project, and it can be accepted at this step.
Step 4: Expand
Now that you can control a large linear actuator, what are you going to do with it? You could make a table that can be transformed to allow you to sit or stand. You could also use some light sensors to make a solar panel that tracks the sun.
- Share a board game electronic dice circuit
- How to Design an Automatic IoT Egg Incubator Using ESP8266
- How to Design a Solar Cellular Weather Station Using Particle Boron
- Making a Smart Blind Pole Using Arduino Uno and Ultrasonic Sensor
- Design of a tomato sorting machine based on Raspberry Pi
- Satellite TV Set Top Box Remote Controller
- DIY Solar Detector
- Making an Off-Grid Solar PV System
- How to Build a Low-Cost Arduino MiniCNC Plotter
- Discrete component laser driver circuit
- How does an optocoupler work? Introduction to the working principle and function of optocoupler
- 8050 transistor pin diagram and functions
- What is the circuit diagram of a TV power supply and how to repair it?
- Analyze common refrigerator control circuit diagrams and easily understand the working principle of refrigerators
- Hemisphere induction cooker circuit diagram, what you want is here
- Circuit design of mobile phone anti-theft alarm system using C8051F330 - alarm circuit diagram | alarm circuit diagram
- Humidity controller circuit design using NAND gate CD4011-humidity sensitive circuit
- Electronic sound-imitating mouse repellent circuit design - consumer electronics circuit diagram
- Three-digit display capacitance test meter circuit module design - photoelectric display circuit
- Advertising lantern production circuit design - signal processing electronic circuit diagram