如何使用Arduino控制大型线性执行器

本文将向你展示如何使用 arduino 和两个按钮对大型线性执行器进行基本的手动控制。在第一组代码中,第一个按钮伸出执行器,第二个按钮缩回执行器。在第二组代码中,两个按钮将线性执行器移动到预设位置。
大型线性致动器传统上具有五根导线。两根线用于为电机供电,三根线连接到内部电位计以读取位置。这两个继电器用于切换电机的正负电源,以确定活塞的行进方向。代码的第一位不使用这个,第二个使用这个来达到目标​​位置。让我们开始吧。
第 1 步:接线
第 2 步:代码 1 - 手动控制
此部分代码显示了如何使用 arduino 和两个按钮对大型线性执行器进行基本手动控制。第一个按钮伸出致动器,第二个按钮缩回致动器。
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);
}
}
第 3 步:代码 2 - 使用位置反馈预设位置
此部分代码显示了如何使用 arduino 和两个按钮对大型线性执行器进行基本控制,每个按钮预设到一个位置。
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(“\t 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”);
}
}
以上就是该项目所需的全部功能代码,到这一步就可以验收了。
第4步:拓展
在可以控制大型线性执行器之后,你打算用它做什么?您可以制作一张可以变形的桌子,以变换坐姿或站姿。同时你还可以使用一些光传感器,制作一个跟踪太阳的太阳能电池板。

未来国产FPGA芯片谁会挑大梁?
OPPOR17评测 兼顾科技属性和时尚属性的最佳产品
射频连接器随着行业不断的发展 国内市场前景良好
白光干涉仪和激光共聚焦仪的区别
UVLED固化机丨胶黏剂在锂电池上的应用
如何使用Arduino控制大型线性执行器
雷卯MMBZ27VC完全替代MMBZ27VCLT1
有什么值得入手的蓝牙耳机品牌?2022年蓝牙耳机品牌排行榜
Systemverilog中的union
联想Z5评测 新国民旗舰
DS2155移植到DS21458
TÜV南德携电子五所成功召开2023智能网联汽车安全技术大会
CMMF2011详解手机制造技术两大挑战
中国内地语音芯片产能快速扩张,已成为联电的可怕对手
解剖中国人:愿意花几十万买房 为何不舍得买2500元智能锁?
如何校验氢气检测仪呢?-欧森杰
I2C推挽结构和开漏结构
小爱同学可以实时查公交了,与高德地图合作开发
桁架机器人相比于人工的优势
航天宏图与农业农村部大数据发展中心成立联合实验室