這篇文章來源于DevicePlus.com英語網(wǎng)站的翻譯稿。
目錄
? 第一部分
什么是伺服電機(jī)?
伺服電機(jī)的類型
所需電壓和電源
? 第二部分
基于Arduino程序的伺服控制
伺服電機(jī)可以做什么?
? 第三部分
伺服控制電燈開關(guān)
電燈開關(guān)的遠(yuǎn)程控制
4. 基于Arduino程序的伺服控制
Arduino對(duì)伺服電機(jī)控制的方式大致有兩種。
PWM(脈沖寬度調(diào)制)是一種通過打開和關(guān)閉脈沖信號(hào)來控制電機(jī)的方法。通過直接使用PWM來控制伺服電機(jī)可以實(shí)現(xiàn)步進(jìn)式轉(zhuǎn)動(dòng)。但是對(duì)于更復(fù)雜的項(xiàng)目,您可以使用Arduino IDE中包含的伺服電機(jī)庫。
Arduino IDE → [File] → [Examples] → [10.StarterKit BasicKit] → [p05_ServoMoodindicator]
該程序可以根據(jù)模擬引腳0(A0)的輸入值來更改伺服電機(jī)的角度。在模擬引腳上使用電位計(jì)或光學(xué)傳感器等可變電阻,通過電阻值的變化來實(shí)現(xiàn)電機(jī)的轉(zhuǎn)動(dòng)。
伺服電機(jī)庫函數(shù)
伺服電機(jī)庫基于兩種類型的指令:1)指定要發(fā)送到伺服電機(jī)的控制信號(hào)的引腳編號(hào)。2)指定伺服電機(jī)轉(zhuǎn)動(dòng)時(shí)的角度。
代碼—示例
myServo.attach(9); //Specify the servo motor's signal pin
代碼—示例
myServo.write(angle); //Move the servomotor to a specific angle
以下電路是使用FEETECH FS90微伺服電機(jī)的示例。該伺服電機(jī)的工作電壓是6V。由于工作時(shí)的電流是200 mA,因此伺服電機(jī)由四節(jié)AA電池串聯(lián)供電(6V)。
圖6:示例電路圖
圖7:伺服電機(jī)控制電路
圖8: p05_ServoMoodIndicator
代碼—示例
/* Arduino Starter Kit example Project 5 - Servo Mood Indicator This sketch is written to accompany Project 5 in the Arduino Starter Kit Parts required: servo motor 10 kilohm potentiometer 2 100 uF electrolytic capacitors Created 13 September 2012 by Scott Fitzgerald https://www.arduino.cc/starterKit This example code is part of the public domain */ // include the servo library #includeServo myServo; // create a servo object int const potPin = A0; // analog pin used to connect the potentiometer int potVal; // variable to read the value from the analog pin int angle; // variable to hold the angle for the servo motor void setup() { myServo.attach(9); // attaches the servo on pin 9 to the servo object Serial.begin(9600); // open a serial connection to your computer } void loop() { potVal = analogRead(potPin); // read the value of the potentiometer // print out the value to the serial monitor Serial.print("potVal: "); Serial.print(potVal); // scale the numbers from the pot angle = map(potVal, 0, 1023, 0, 179); // print out the angle for the servo motor Serial.print(", angle: "); Serial.println(angle); // set the servo position myServo.write(angle); // wait for the servo to get there delay(15); }
5. 伺服電機(jī)可以做什么?
讓我們簡要回顧一下使用伺服電機(jī)可以完成的工作。以下是兩種典型工作方式:
I. 按下按鈕
伺服電機(jī)可以控制轉(zhuǎn)動(dòng)的角度。這就是為什么伺服電機(jī)最適于開發(fā)按鈕控制的機(jī)械系統(tǒng)。您可以像下面的視頻中那樣制作一些有趣的設(shè)備,并且也可以開發(fā)出僅通過一個(gè)按鈕來實(shí)現(xiàn)控制的多種設(shè)備,如房間里的開關(guān)等等。
II. 移動(dòng)物體
在使用Arduino控制電機(jī)的第三部分——制造一輛通過伺服電機(jī)控制轉(zhuǎn)向的RC車中,我們使用LEGO制造了一臺(tái)RC車。我們安裝了通過伺服電機(jī)進(jìn)行控制的轉(zhuǎn)向部件。伺服電機(jī)可以用于多種器件,但是它通常用于“移動(dòng)”部件/物體,例如移動(dòng)機(jī)器人汽車或機(jī)器人手臂等。
DevicePlus 編輯團(tuán)隊(duì)
設(shè)備升級(jí)版適用于所有熱愛電子和機(jī)電一體化的人。
審核編輯黃宇
-
控制電路
+關(guān)注
關(guān)注
82文章
1719瀏覽量
136130 -
伺服電機(jī)
+關(guān)注
關(guān)注
85文章
2060瀏覽量
58264
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論