0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何使用Arduino控制大型線性執(zhí)行器

科技觀察員 ? 來源:Wade Filewich ? 作者:Wade Filewich ? 2022-04-24 17:25 ? 次閱讀

本文將向你展示如何使用 Arduino 和兩個按鈕對大型線性執(zhí)行器進行基本的手動控制。在第一組代碼中,第一個按鈕伸出執(zhí)行器,第二個按鈕縮回執(zhí)行器。在第二組代碼中,兩個按鈕將線性執(zhí)行器移動到預設位置。

大型線性致動器傳統(tǒng)上具有五根導線。兩根線用于為電機供電,三根線連接到內(nèi)部電位計以讀取位置。這兩個繼電器用于切換電機的正負電源,以確定活塞的行進方向。代碼的第一位不使用這個,第二個使用這個來達到目標??位置。讓我們開始吧。

第 1 步:接線

pYYBAGJlF9iAWpmAAAIMrzRhiB4344.png

第 2 步:代碼 1 - 手動控制

此部分代碼顯示了如何使用 Arduino 和兩個按鈕對大型線性執(zhí)行器進行基本手動控制。第一個按鈕伸出致動器,第二個按鈕縮回致動器。

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 和兩個按鈕對大型線性執(zhí)行器進行基本控制,每個按鈕預設到一個位置。

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

在可以控制大型線性執(zhí)行器之后,你打算用它做什么?您可以制作一張可以變形的桌子,以變換坐姿或站姿。同時你還可以使用一些光傳感器,制作一個跟蹤太陽的太陽能電池板。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 執(zhí)行器
    +關(guān)注

    關(guān)注

    5

    文章

    374

    瀏覽量

    19284
  • Arduino
    +關(guān)注

    關(guān)注

    187

    文章

    6455

    瀏覽量

    186348
收藏 人收藏

    評論

    相關(guān)推薦

    如何使用Arduino和光學系列線性致動來實現(xiàn)同步控制

    諸如Arduino之類的外部控制器中。多個線性執(zhí)行器之間的同步運動對于某些客戶應用的成功至關(guān)重要,一種常見的做法是打開兩個活板門的兩個線性
    發(fā)表于 09-02 06:44

    具有執(zhí)行器飽和與隨機非線性擾動的離散系統(tǒng)模型預測控制_石宇靜

    具有執(zhí)行器飽和與隨機非線性擾動的離散系統(tǒng)模型預測控制_石宇靜
    發(fā)表于 01-07 15:26 ?0次下載

    帶觸覺反饋的壓電執(zhí)行器(低電壓/薄型)PiezoHapt?執(zhí)行器的開發(fā)

    驅(qū)動的同時,支持各種振動模式。與以往用于振動的偏心旋轉(zhuǎn)電機執(zhí)行器、線性執(zhí)行器線性諧振執(zhí)行器)相比,本產(chǎn)品具有世界最薄級別*1的厚度(約0.
    發(fā)表于 04-11 11:25 ?1874次閱讀

    安華高科技:大型家電控制電機和執(zhí)行器的解決者!

    安華高科技可以為大型家電提供種類豐富的解決方案,主要解決控制電機和執(zhí)行器,以及增強產(chǎn)品的用戶界面和表現(xiàn)效果方面的問題。
    的頭像 發(fā)表于 06-22 09:32 ?4560次閱讀
    安華高科技:<b class='flag-5'>大型</b>家電<b class='flag-5'>控制</b>電機和<b class='flag-5'>執(zhí)行器</b>的解決者!

    汽車控制系統(tǒng)中的電子控制單元和傳感以及執(zhí)行器

    電子控制單元(ECU)是汽車電子控制系統(tǒng)的“大腦”,它對各傳感輸入的電信號以及部分執(zhí)行器的反饋電信號進行綜合分析與處理,給傳感提供參考電
    發(fā)表于 08-04 10:49 ?8567次閱讀

    執(zhí)行器由什么組成_執(zhí)行器的工作原理

    在過程控制系統(tǒng)中,執(zhí)行器執(zhí)行機構(gòu)和自動化調(diào)節(jié)機構(gòu)兩部分組成。自動化調(diào)節(jié)機構(gòu)通過執(zhí)行元件直接改變生產(chǎn)過程的參數(shù),使生產(chǎn)過程滿足預定的要求。執(zhí)行
    發(fā)表于 01-21 15:18 ?1.1w次閱讀
    <b class='flag-5'>執(zhí)行器</b>由什么組成_<b class='flag-5'>執(zhí)行器</b>的工作原理

    氣動執(zhí)行器的組成_氣動執(zhí)行器選型

    氣動執(zhí)行器的調(diào)節(jié)機構(gòu)的種類和構(gòu)造大致相同,主要是執(zhí)行機構(gòu)不同。因此在氣動執(zhí)行器介紹時分為執(zhí)行機構(gòu)和調(diào)節(jié)閥兩部分。氣動執(zhí)行器
    發(fā)表于 01-21 15:43 ?3946次閱讀

    電動執(zhí)行器和風門執(zhí)行器之間的差別是什么

    風門執(zhí)行器的作用: 風門執(zhí)行器關(guān)鍵作用在供熱系統(tǒng)尾端,根據(jù)與溫度控制裝置一起連動,調(diào)整室溫。假如房間內(nèi)總面積很大,能夠安裝2個地采暖環(huán)城路,這時候只需應用一個溫度控制器串聯(lián)風門
    發(fā)表于 02-18 17:19 ?2489次閱讀

    推動線性執(zhí)行器設計的多項因素

    線性執(zhí)行器可將電機轉(zhuǎn)子固有的旋轉(zhuǎn)運動轉(zhuǎn)化為適用于各類大小負載的直線運動。它由電機、直線導軌和驅(qū)動控制電子元件組成,此外還可能包含有線/無線連接和控制方案。雖然
    的頭像 發(fā)表于 11-05 14:44 ?2563次閱讀

    從單個Arduino輸出引腳控制多個繼電器或其他執(zhí)行器

    電子發(fā)燒友網(wǎng)站提供《從單個Arduino輸出引腳控制多個繼電器或其他執(zhí)行器.zip》資料免費下載
    發(fā)表于 11-18 11:37 ?0次下載
    從單個<b class='flag-5'>Arduino</b>輸出引腳<b class='flag-5'>控制</b>多個繼電器或其他<b class='flag-5'>執(zhí)行器</b>

    使用DAC精確控制線性執(zhí)行器

    工業(yè)執(zhí)行器的有效控制需要精確、可重復的控制線性執(zhí)行器控制具有高精度
    的頭像 發(fā)表于 12-19 13:56 ?1754次閱讀
    使用DAC精確<b class='flag-5'>控制線性</b><b class='flag-5'>執(zhí)行器</b>

    Arduino控制小型線性執(zhí)行器

    電子發(fā)燒友網(wǎng)站提供《用Arduino控制小型線性執(zhí)行器.zip》資料免費下載
    發(fā)表于 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'>執(zhí)行器</b>

    氣動執(zhí)行器與電動執(zhí)行器:哪個更好?

    氣動執(zhí)行器與電動執(zhí)行器:哪個更好?
    的頭像 發(fā)表于 03-13 16:30 ?4747次閱讀
    氣動<b class='flag-5'>執(zhí)行器</b>與電動<b class='flag-5'>執(zhí)行器</b>:哪個更好?

    BeagleBone Black Wireless、MotorCape和線性執(zhí)行器

    電子發(fā)燒友網(wǎng)站提供《BeagleBone Black Wireless、MotorCape和線性執(zhí)行器.zip》資料免費下載
    發(fā)表于 07-05 10:34 ?0次下載
    BeagleBone Black Wireless、MotorCape和<b class='flag-5'>線性</b><b class='flag-5'>執(zhí)行器</b>

    氣動執(zhí)行器換電動執(zhí)行器怎么換

    氣動執(zhí)行器和電動執(zhí)行器是工業(yè)自動化領(lǐng)域中常見的兩種驅(qū)動方式。它們各自有其特點和優(yōu)勢,適用于不同的應用場景。在某些情況下,可能需要將氣動執(zhí)行器更換為電動執(zhí)行器,以滿足特定的需求。 了解氣
    的頭像 發(fā)表于 07-10 14:47 ?632次閱讀