0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

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

科技观察员 来源:Wade Filewich 作者:Wade Filewich 2022-04-24 17:25 次阅读

本文将向你展示如何使用 Arduino 和两个按钮对大型线性执行器进行基本的手动控制。在第一组代码中,第一个按钮伸出执行器,第二个按钮缩回执行器。在第二组代码中,两个按钮将线性执行器移动到预设位置。

大型线性致动器传统上具有五根导线。两根线用于为电机供电,三根线连接到内部电位计以读取位置。这两个继电器用于切换电机的正负电源,以确定活塞的行进方向。代码的第一位不使用这个,第二个使用这个来达到目标​​位置。让我们开始吧。

第 1 步:接线

pYYBAGJlF9iAWpmAAAIMrzRhiB4344.png

第 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步:拓展

在可以控制大型线性执行器之后,你打算用它做什么?您可以制作一张可以变形的桌子,以变换坐姿或站姿。同时你还可以使用一些光传感器,制作一个跟踪太阳的太阳能电池板。

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 执行器
    +关注

    关注

    5

    文章

    337

    浏览量

    19200
  • Arduino
    +关注

    关注

    184

    文章

    6427

    浏览量

    184826
收藏 人收藏

    评论

    相关推荐

    偏心转子马达与执行器的性能怎么改善?

    偏心转子马达 (ERM) 与线性谐振执行器 (LRA) 常用于智能手机与平板电脑应用,通过触觉效应提供触感反馈。虽然在进行触感设计时需要考虑许多特性,但用户感觉最明显的特征之一却是执行器的起动与停止时间。
    发表于 08-14 06:10

    如何使用Arduino和光学系列线性致动来实现同步控制

    诸如Arduino之类的外部控制器中。多个线性执行器之间的同步运动对于某些客户应用的成功至关重要,一种常见的做法是打开两个活板门的两个线性
    发表于 09-02 06:44

    具有执行器饱和与随机非线性扰动的离散系统模型预测控制_石宇静

    具有执行器饱和与随机非线性扰动的离散系统模型预测控制_石宇静
    发表于 01-07 15:26 0次下载

    带触觉反馈的压电执行器(低电压/薄型)PiezoHapt™执行器的开发

    驱动的同时,支持各种振动模式。与以往用于振动的偏心旋转电机执行器线性执行器线性谐振执行器)相比,本产品具有世界最薄级别*¹的厚度(约0.
    发表于 04-11 11:25 1766次阅读

    安华高科技:大型家电控制电机和执行器的解决者!

    安华高科技可以为大型家电提供种类丰富的解决方案,主要解决控制电机和执行器,以及增强产品的用户界面和表现效果方面的问题。
    的头像 发表于 06-22 09:32 4384次阅读
    安华高科技:<b class='flag-5'>大型</b>家电<b class='flag-5'>控制</b>电机和<b class='flag-5'>执行器</b>的解决者!

    气动执行器的组成_气动执行器选型

    气动执行器的调节机构的种类和构造大致相同,主要是执行机构不同。因此在气动执行器介绍时分为执行机构和调节阀两部分。气动执行器
    发表于 01-21 15:43 3635次阅读

    电动执行器和风门执行器之间的差别是什么

    风门执行器的作用: 风门执行器关键作用在供热系统尾端,根据与温度控制装置一起连动,调整室温。假如房间内总面积很大,能够安装2个地采暖环城路,这时候只需应用一个温度控制器串联风门
    发表于 02-18 17:19 1804次阅读

    为何欧玛执行器广受大家喜爱,它的功能有哪些

    欧玛执行器也叫闭环控制控制型电动执行器,这类电动执行机构除开具备对闸阀电源开关的控制功能之外,还
    发表于 03-18 11:25 806次阅读

    推动线性执行器设计的多项因素

    线性执行器可将电机转子固有的旋转运动转化为适用于各类大小负载的直线运动。它由电机、直线导轨和驱动控制电子元件组成,此外还可能包含有线/无线连接和控制方案。虽然
    的头像 发表于 11-05 14:44 2378次阅读

    罗托克执行器的基本配件都有哪些

    罗托克执行器主要可以用作与截断和接通介质,也能用在计算流体流速的调节和控制。罗托克执行器在工业发展上有一个如此具有重大的作用,其附件方面也有存在不少功劳,下面就是我们来看看罗托克执行器
    发表于 01-29 22:57 725次阅读

    HPLA电动线性执行器技术详解

    HPLA系列线性执行器应用于多种工业应用中,是一款非常坚固的硬化型线性执行器,提供高速、高加速度和长行程,并刚性结构相结合。它非常适合用于单轴配置或高速多轴龙门系统。HPLA滑块由安装
    的头像 发表于 11-09 15:19 485次阅读
    HPLA电动<b class='flag-5'>线性</b><b class='flag-5'>执行器</b>技术详解

    从单个Arduino输出引脚控制多个继电器或其他执行器

    电子发烧友网站提供《从单个Arduino输出引脚控制多个继电器或其他执行器.zip》资料免费下载
    发表于 11-18 11:37 0次下载
    从单个<b class='flag-5'>Arduino</b>输出引脚<b class='flag-5'>控制</b>多个继电器或其他<b class='flag-5'>执行器</b>

    使用DAC精确控制线性执行器

    工业执行器的有效控制需要精确、可重复的控制线性执行器控制具有高精度
    的头像 发表于 12-19 13:56 1309次阅读
    使用DAC精确<b class='flag-5'>控制线性</b><b class='flag-5'>执行器</b>

    Arduino控制小型线性执行器

    电子发烧友网站提供《用Arduino控制小型线性执行器.zip》资料免费下载
    发表于 12-29 13:53 1次下载
    用<b class='flag-5'>Arduino</b><b class='flag-5'>控制</b>小型<b class='flag-5'>线性</b><b class='flag-5'>执行器</b>

    BeagleBone Black Wireless、MotorCape和线性执行器

    电子发烧友网站提供《BeagleBone Black Wireless、MotorCape和线性执行器.zip》资料免费下载
    发表于 07-05 10:34 0次下载
    BeagleBone Black Wireless、MotorCape和<b class='flag-5'>线性</b><b class='flag-5'>执行器</b>