# 스위치 서보 모터 제어

## 스위치 서보 모터 제어

### 결선도

![](/files/-Mf5Wb2niAFQUxZDSk7c)

### 샘플 코드

```cpp
#include <Servo.h>
int SERVO = 10;
int SWITCH = 2;
Servo servo;
void setup()
{
  Serial.begin(9600);
  servo.attach(SERVO);
  pinMode(SWITCH, INPUT);
  delay(1000);
}

void loop()
{
  int input = digitalRead(SWITCH);
  //Serial.println(input);
  if(input == HIGH){
   	servo.write(150); 
  }
  else{
    servo.write(30);
  }
}
```

### 컴파일

`Ctrl+R` 또는 스케치 메뉴의 `확인/컴파일`을 눌러 컴파일을 진행한다.

### 업로드

`Ctrl+U` 또는 스케치 메뉴의 `업로드`를 눌러 업로드를 진행한다.

### 실행 결과

스위치를 누르면 서보 모터가 회전하는 것을 알 수 있다.

### 코드 설명


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sysout.co.kr/base-language/arduino/arduino-control/servo-motor-control/switch-servo-motor-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
