Arduino

Arduino:SG90伺服馬達實作

今天快速記錄下 SG90 伺服馬達的 arduino 程式碼。


Tinkercad 的模擬程式範例

PIN 腳位定義:

  • 橘色:控制訊號
  • 紅色:輸入電源 +(3~7.2V)
  • 棕色:共同接地

規格:

  • Weight: 9g
  • Dimension: 23×12.2x29mm
  • Stall torque: 1.8kg/cm(4.8v)
  • Gear type: POM gear set
  • Operating speed: 0.12 sec/60degree(4.8v)
  • Operating voltage: 4.8v~7.2V
  • Temperature range: 0℃_ 55℃
  • Dead band width: 1us
  • Power Supply: Through External Adapter
  • servo wire length: 25 cm
  • Servo Plug: JR (Fits JR and Futaba)
  • 轉動角度:最大90°

範例程式:

#include    //載入函式庫,這是內建的,不用安裝

Servo myservo;  // 建立SERVO物件

void setup() {
  myservo.attach(9);  // 設定要將伺服馬達接到哪一個PIN腳
}

void loop() {   
  myservo.write(0);  //旋轉到0度,就是一般所說的歸零
  delay(1000);
  myservo.write(90); //旋轉到90度
  delay(1000);
  myservo.write(180); //旋轉到180度
  delay(1000);
  myservo.write(90);
  delay(1000);
}
/*
  Sweep

  by BARRAGAN 
  This example code is in the public domain.

  modified 8 Nov 2013  by Scott Fitzgerald
  http://www.arduino.cc/en/Tutorial/Sweep
*/

#include 

int pos = 0;

Servo servo_9;

void setup()
{
  servo_9.attach(9, 500, 2500);

}

void loop()
{
  // sweep the servo from 0 to 180 degrees in steps
  // of 1 degrees
  for (pos = 0; pos <= 180; pos += 1) {
    // tell servo to go to position in variable 'pos'
    servo_9.write(pos);
    // wait 15 ms for servo to reach the position
    delay(15); // Wait for 15 millisecond(s)
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    // tell servo to go to position in variable 'pos'
    servo_9.write(pos);
    // wait 15 ms for servo to reach the position
    delay(15); // Wait for 15 millisecond(s)
  }
}

參考

1,630 則留言

  • rvwqxvxpc

    To play this pokie with real money, choose a reputable online casino for Aztec Gems by Pragmatic Play and prioritise platforms with licenses from recognised authorities, like the UK Gambling Commission or Malta Gaming Authority, for fairness & security. Look for casinos with positive reviews and transparent policies. Aztec Gems suits players seeking straightforward yet thrilling gameplay, especially those fond of medium volatility slots. Pragmatic play adalah penyedia game demo slot online seperti demo sweet bonanza secara gratis kepada slotmania. Melalui tema buah serta permen, slot demo sweet bonanza berhasil menarik perhatian para slotter Indonesia untuk mencoba bermain. Lantas karena itu kini demo slot sweet bonanza menjadi salah satu pilihan teratas dalam bermain slot gacor hari ini. Tak hanya sampai disitu saja, bahkan kini pragmatic play juga menyediakan versi terbaru dari game slot gacor ini. Berbagai turunan versi terbaru dari sweet bonanza seperti xmas ataupun versi gold juga turut hadir dalam akun demo slot pragmatic play terlengkap pada link kudaslot.
    https://punchfitacademy.fr/2025/05/27/breaking-down-aviator-game-pak-features-fairness/
    It is important to keep in mind that the terms and conditions for no deposit free spins bonuses vary based on the location of your gameplay. These bonus spins are attractive because they let you start playing without paying upfront, but usually come with a wagering requirement for any winnings from them. Each casino sets its own betting conditions, which could specify a particular number of bets you need to make with your winnings or the total amount you must wager. Nevertheless, if you managed to win a sufficient amount, you could potentially retain the entire sum. Knowing the details of every free spins offer is important in order to understand the requirements before joining. Some US casinos keep the minimum deposit down as much as possible, but in any case, if you make a deposit as a newbie at an online casino, chances are you will receive more free spins as a result.

留下一個回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *