Servo Motor(SG90)

아두위키 : Arduwiki
ArduWiki (토론 | 기여)님의 2024년 3월 24일 (일) 14:24 판 (Created page with "{{#seo:|title=아두위키 : 아두이노 서보 모터(SG90) 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, 서보 모터(SG90), 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 서보 모터(SG90)를 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}} File:Sg90대표이미지.jpg|center|class=...")
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

A product that can control the rotation angle according to the signal.

It is used in applications like robot joints due to its precise position control.

The rotation angle range is from 0 degrees to 180 degrees.

Specifications

  • Operating Voltage: 5V
  • Current Consumption: 0.2A ~ 0.7A
  • Angle Range: 0° ~ 180°

Required Hardware

  • SG90 Servo Motor
  • Arduino Board
  • Jumper Cables

Connection

Servor motor Arduino
S D7
+ 5V
- GND

Connection

  • Servo (Standard Library)

Example Code

// Using the servo library
#include <Servo.h>
// Using pin 7
#define pin 7

// Declare a servo object
Servo servo;

// Declare a variable for the angle
int pos = 60;

void setup() {
  Serial.begin(9600);
  // Set the pin number for the servo motor
  servo.attach(pin);
  // Set the initial angle for the servo motor
  servo.write(pos);
  Serial.println("Serial start");
  Serial.print("default degree : ");
  Serial.println(pos);
}

void loop() {
  if (Serial.available()) {
    char contrl = Serial.read();
    if (contrl == 'a') { // When 'a' is input in the serial monitor, increase by 60 degrees
      if (pos == 180)
        Serial.println("max angle");
      else {
        pos = pos + 60;
        Serial.print("degree : ");
        Serial.println(pos);
        servo.write(pos);
      }
    } else if (contrl == 'b') { // When 'b' is input in the serial monitor, decrease by 60 degrees
      if (pos == 0)
        Serial.println("min angle");
      else {
        pos = pos - 60;
        Serial.print("degree : ");
        Serial.println(pos);
        servo.write(pos);
      }
    }
  }
}

Execution Result