아두이노 우노 Q 서보 모터

이 튜토리얼은 Arduino UNO Q를 사용하여 서보 모터를 제어하는 방법을 보여줍니다. 구체적으로 다음을 배우게 됩니다:

Arduino UNO Q 서보 모터

필요한 하드웨어

1×Arduino UNO Q 아마존
1×USB Cable for Arduino Uno Q 아마존
1×서보 모터 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(추천) 아두이노 우노용 스크루 터미널 블록 쉴드 쿠팡 | 아마존
1×(추천) Sensors/Servo Expansion Shield for Arduino Uno 쿠팡 | 아마존
1×(추천) 아두이노 우노용 브레드보드 쉴드 쿠팡 | 아마존
1×(추천) 아두이노 우노용 케이스 쿠팡 | 아마존
1×(추천) 아두이노 우노용 프로토타이핑 베이스 플레이트 & 브레드보드 키트 아마존
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

서보 모터에 대해

서보 모터는 일반적으로 0도에서 180도까지 핸들을 회전할 수 있는 부품입니다. 객체의 각도를 제어하는 데 사용됩니다.

핀아웃

이 예제는 3개의 핀을 가진 서보 모터를 사용합니다:

  • VCC 핀: 빨간 선을 VCC(5V)에 연결합니다.
  • GND 핀: 검은색 또는 갈색 선을 GND(0V)에 연결합니다.
  • Signal 핀: 노란색 또는 주황색 선을 Arduino UNO Q 핀에서 오는 PWM 제어 신호를 받도록 연결합니다.
서보 모터 사용법 핀아웃

배선 다이어그램

온라인에서 서보 VCC가 Arduino의 5V 핀에 직접 연결되는 배선 다이어그램을 볼 수 있습니다. Arduino UNO Q 보드에 손상을 줄 수 있으므로 이 방법은 피하는 것이 좋습니다.

Arduino UNO Q 서보 모터 연결 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

Arduino UNO Q 보드를 보호하기 위해 서보 모터에 외부 전원 공급 장치를 사용하는 것이 가장 좋습니다. 아래 배선 다이어그램은 서보 모터를 외부 전원에 연결하는 방법을 보여줍니다.

Arduino UNO Q 서보 모터 external power supply 연결 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

외부 전원 공급 장치의 GND를 Arduino UNO Q 보드의 GND에 연결해야 합니다. 이 단계는 올바르게 작동하기 위해 매우 중요합니다.

서보 모터를 위한 프로그래밍 방법

  • 라이브러리를 포함합니다:
#include <Servo.h>
  • Servo 객체를 생성합니다:
Servo servo;

여러 서보 모터를 관리하려면 추가 Servo 객체를 선언하면 됩니다.

Servo servo1; Servo servo2;
  • Arduino UNO Q의 제어 핀을 서보 모터의 신호 핀(예: 핀 9)에 연결합니다.
servo.attach(9);
  • 마지막으로 필요한 각도(예: 90도)로 서보 모터를 회전합니다.
servo.write(90);

MCU 코드

Arduino UNO Q에는 두 개의 프로세서가 있습니다: STM32 MCU(실시간 하드웨어 제어 처리)와 Qualcomm MPU(Debian Linux 실행). 이 섹션에서는 STM32 MCU만 프로그래밍됩니다. Linux 측은 유휴 상태로 유지됩니다. 나중 섹션에서는 두 프로세서가 함께 작동하는 방법을 보여줄 것입니다.

코드는 서보 모터를 0°에서 180°로 부드럽게 쓸어 올리고 다시 돌아오며 계속 반복합니다:

/* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-servo-motor */ #include <Servo.h> Servo servo; void setup() { servo.attach(9); // Connect the servo signal wire to pin 9 servo.write(0); // Move to 0 degrees at startup } void loop() { // Sweep from 0 to 180 degrees for (int pos = 0; pos <= 180; pos += 1) { servo.write(pos); delay(10); } // Sweep from 180 back to 0 degrees for (int pos = 180; pos >= 0; pos -= 1) { servo.write(pos); delay(10); } }

빠른 단계

  • Arduino UNO Q를 처음 사용하시나요? 계속 진행하기 전에 아두이노 우노 Q 시작하기 튜토리얼을 따라 개발 환경을 준비하세요.
  • 컴포넌트 배선: 서보 신호 선을 핀 9에 연결하고, VCC를 5V 외부 공급 장치에 연결하며, GND를 외부 공급 장치와 Arduino UNO Q GND 모두에 연결합니다.
  • 연결: Arduino UNO Q를 USB-C 케이블로 컴퓨터에 연결합니다.
  • Arduino App Lab 열기: Arduino App Lab을 실행하고 Arduino UNO Q를 감지할 때까지 기다립니다.
  • 새 앱 만들기: Create New App 버튼을 클릭합니다.
create new app in 아두이노 app lab on Arduino UNO Q
  • 앱에 이름을 지정합니다. 예: DIYables_ServoMotor
  • Create를 클릭하여 확인합니다.
  • 새 앱 내에서 생성된 폴더 및 파일 집합이 표시됩니다.
아두이노 app lab app folders and files on Arduino UNO Q
  • sketch/sketch.ino 파일을 찾습니다. 이것은 MCU 스케치를 붙여넣을 위치입니다.
  • 스케치 붙여넣기: 위의 MCU 코드를 복사하여 스케치 파일에 붙여넣습니다. 다른 파일은 기본값으로 유지합니다.
    • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
    add sketch 라이브러리 in 아두이노 app lab on Arduino UNO Q
    • Search for Servo created by Michael Margolis, Arduino and click the Install button.
    My Apps / DIYables Apps
    Run
    Bricks
    No bricks added...
    Sketch Libraries
    No sketch libra...
    Files
    python
    sketch
    .gitignore
    README.md
    app.yaml
    sketch.ino
    Add sketch library
    Servo Michael Margolis, Arduino

    This library can control a great number of servos.
    It makes careful use of timers: the library can control 12 servos using only 1 timer.
    On the Arduino Due you can control up to 60 servos.

    1.2.1
    Install
    More Info
    • Search for Arduino_RouterBridge created by Arduino and click the Install button.
    My Apps / DIYables Apps
    Run
    Bricks
    No bricks added...
    Sketch Libraries
    No sketch libra...
    Files
    python
    sketch
    .gitignore
    README.md
    app.yaml
    sketch.ino
    Add sketch library
    Arduino_RouterBridge Arduino

    This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

    0.4.1
    Install
    More Info
    • 업로드: Arduino App Lab의 Run 버튼을 클릭하여 STM32로 컴파일 및 업로드합니다.
    click run 버튼 in 아두이노 app lab on Arduino UNO Q
    • 보기: 서보 모터는 0°에서 180°로 천천히 회전하다가 180°에서 0°로 천천히 돌아오며 계속 반복됩니다.

    서보 모터 속도 제어 방법

    map()millis() 함수를 사용하면 서보 모터의 속도를 부드럽게 조정하는 동시에 다른 코드가 중단 없이 실행되도록 할 수 있습니다.

    #include <Servo.h> Servo servo; #define MOVING_TIME 3000 // Duration (ms) for the servo to move from startAngle to stopAngle unsigned long moveStartTime; int startAngle = 30; int stopAngle = 90; void setup() { servo.attach(9); moveStartTime = millis(); } void loop() { unsigned long progress = millis() - moveStartTime; if (progress <= MOVING_TIME) { long angle = map(progress, 0, MOVING_TIME, startAngle, stopAngle); servo.write(angle); } }

    Linux + MCU Bridge 프로그래밍

    Arduino UNO Q에는 함께 작동하는 두 개의 프로세서가 있습니다: MPU(Qualcomm, Debian Linux 실행)와 MCU(STM32, Arduino 스케치를 실행하는 Zephyr OS). 이들은 Arduino_RouterBridge 라이브러리를 통해 RPC를 사용하여 통신합니다. 원본 시리얼 포트를 통해 통신하지 않습니다.

    • 서보는 MCU(STM32)에 연결됩니다. 신호 선이 핀 9에 배선됩니다. MCU는 PWM 서보 신호를 구동합니다.
    • MPU는 서보를 직접 제어할 수 없습니다. Bridge.call()을 통해 MCU의 함수를 호출하여 서보를 특정 위치로 이동해야 합니다.
    • MPU에는 Wi-Fi가 있습니다. MPU는 Wi-Fi가 있는 완전한 Debian Linux를 실행하므로 Telegram 명령을 수신하고 서보 위치를 원격으로 조정할 수 있습니다.
    • 통신: Linux 측의 Bridge.call()은 MCU 측의 Bridge.provide_safe() 함수를 호출합니다(servo.write()는 하드웨어 API이므로).
    • ⚠️ 예약됨: /dev/ttyHS1(Linux) 및 Serial1(MCU)은 Arduino Router에서 사용하므로 직접 열지 마세요.

    요약: MPU가 각도 명령 전송 → MCU가 서보 구동 → 서보가 위치로 이동.

    MCU 스케치 — Bridge 및 Monitor 출력이 포함된 서보 모터 제어:

    /* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-servo-motor */ #include "Arduino_RouterBridge.h" #include <Servo.h> Servo servo; void servo_left() { servo.write(0); Monitor.println("Servo: 0 degrees (left)"); } void servo_center() { servo.write(90); Monitor.println("Servo: 90 degrees (center)"); } void servo_right() { servo.write(180); Monitor.println("Servo: 180 degrees (right)"); } void setup() { Bridge.begin(); Monitor.begin(); servo.attach(9); servo.write(90); // Start at center position Bridge.provide_safe("left", servo_left); Bridge.provide_safe("center", servo_center); Bridge.provide_safe("right", servo_right); Monitor.println("Servo Motor Bridge ready"); } void loop() {}

    Python 스크립트(Arduino App Lab) — Linux에서 서보 제어:

    /* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-servo-motor */ from arduino.app_utils import * import time def loop(): print("Servo at 0 degrees (left)") Bridge.call("left") time.sleep(2) print("Servo at 90 degrees (center)") Bridge.call("center") time.sleep(2) print("Servo at 180 degrees (right)") Bridge.call("right") time.sleep(2) print("Servo at 90 degrees (center)") Bridge.call("center") time.sleep(2) App.run(user_loop=loop)
    • 참고: MCU 스케치에서 Bridge.begin()이 호출되었는지 확인하고 Linux 측에서 Python 스크립트를 실행하기 전에 스케치가 업로드되었는지 확인하세요.
    • ⚠️ 경고: 코드에서 /dev/ttyHS1(Linux의 경우) 또는 Serial1(MCU의 경우)을 직접 열지 마세요. 이들은 Arduino Router에서 예약되어 있으며 접근하면 Bridge가 손상됩니다.

    빠른 단계

    • MCU 스케치 업로드: Arduino App Lab을 열고 새 앱을 만들어서 Bridge MCU 스케치를 sketch/sketch.ino에 붙여넣고, ServoArduino_RouterBridge 라이브러리를 설치한 다음 Run을 클릭합니다.
    • Python 스크립트 추가: 위의 Python 코드를 같은 앱의 Python 탭에 붙여넣습니다.
    • 앱 실행: Run을 클릭하면 Python이 서보를 왼쪽, 중앙, 오른쪽, 중앙 위치로 자동으로 순환합니다.
    • 콘솔 확인: Console 탭 → MCU Monitor 서브탭을 열어서 서보 위치 메시지를 확인합니다.

    App Lab 콘솔 출력

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    Message (Enter to send a message to "Newbiely" on usb(2820070321))
    New Line
    9600 baud
    Servo Motor Bridge ready Servo: 0 degrees (left) Servo: 90 degrees (center) Servo: 180 degrees (right) Servo: 90 degrees (center)

    Telegram 통합

    Telegram을 통해 어디서나 서보 모터를 원격으로 제어할 수 있습니다.

    Telegram 봇이 아직 없으면 계속 진행하기 전에 아두이노 우노 Q - 텔레그램 봇을 참조하여 봇 토큰을 얻으세요.

    MCU 스케치: 이전 Bridge 섹션의 같은 MCU 스케치를 유지합니다. 변경 사항이 없습니다. 계속하기 전에 STM32에 이미 업로드되고 실행 중인지 확인하세요.

    Python 스크립트(Arduino App Lab) — 서보 모터 제어용 Telegram 봇:

    /* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-servo-motor */ from arduino.app_utils import * import requests import time BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" last_update_id = 0 def send_message(chat_id, text): requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}) def get_updates(): global last_update_id resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}) return resp.json().get("result", []) def loop(): global last_update_id updates = get_updates() for update in updates: last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if text == "/left": Bridge.call("left") send_message(chat_id, "Servo moved to 0 degrees (left).") elif text == "/center": Bridge.call("center") send_message(chat_id, "Servo moved to 90 degrees (center).") elif text == "/right": Bridge.call("right") send_message(chat_id, "Servo moved to 180 degrees (right).") else: send_message(chat_id, "Commands:\n/left — move to 0°\n/center — move to 90°\n/right — move to 180°") time.sleep(1) App.run(user_loop=loop)
    • 참고: YOUR_BOT_TOKEN을 Telegram의 @BotFather에서 얻은 토큰으로 바꾸세요.
    • /left를 보내서 서보를 0°로 이동합니다.
    • /center를 보내서 서보를 90°로 이동합니다.
    • /right를 보내서 서보를 180°로 이동합니다.

    빠른 단계

    • MCU 스케치 업로드: 이전 섹션의 Bridge MCU 스케치를 사용합니다(아직 업로드하지 않았으면 먼저 업로드합니다).
    • Telegram 스크립트 붙여넣기: 위의 Python 코드를 Arduino App Lab의 앱의 Python 탭에 복사합니다.
    • 토큰 설정: 스크립트의 YOUR_BOT_TOKEN을 실제 봇 토큰으로 바꾸세요.
    • 앱 실행: Run을 클릭하면 봇이 Telegram 메시지를 수신하기 시작합니다.
    • 테스트: /left를 보내면 서보가 0°로 이동합니다. /center를 보내면 90°로 이동합니다. /right를 보내면 180°로 이동합니다.

    App Lab 콘솔 출력

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /left [2026-04-29 12:00:01] Servo moved to 0 degrees (left). [2026-04-29 12:02:10] Telegram: /center [2026-04-29 12:02:10] Servo moved to 90 degrees (center). [2026-04-29 12:04:05] Telegram: /right [2026-04-29 12:04:05] Servo moved to 180 degrees (right).
    Telegram
    Telegram 12:45
    Welcome to Telegram!
    ArduinoBot 10:19
    Chatting with Arduino...
    telegram-botfather
    BotFather Yesterday
    Your bot has been created.

    ArduinoBot

    bot
    Today
    /left
    10:15 AM ✓✓
    Servo moved to 0 degrees (left).
    10:16 AM
    /center
    10:17 AM ✓✓
    Servo moved to 90 degrees (center).
    10:18 AM
    /right
    10:19 AM ✓✓
    Servo moved to 180 degrees (right).
    10:20 AM

    OpenClaw 통합

    이 튜토리얼에 OpenClaw를 적용할 수 있습니다. 아두이노 우노 Q - OpenClaw 튜토리얼의 지침을 참조하세요.

    애플리케이션/프로젝트 아이디어

    • 원격 카메라 팬: 카메라를 서보에 마운트하고 Telegram 명령으로 조준합니다.
    • 자동화된 밸브: 서보를 사용하여 Telegram 메시지로 트리거되는 물 밸브를 열거나 닫습니다.
    • 도어 잠금 메커니즘: 서보를 회전하여 도어 잠금을 원격으로 래치 또는 언래치합니다.
    • 태양열 추적기: MPU의 조도 센서 판독값을 사용하여 태양광 패널을 태양을 향하도록 유지합니다.
    • 로봇 팔 관절: 다중 서보 로봇 팔을 구축하고 Telegram을 통해 각 관절을 제어합니다.

    도전해보세요

    • 쉬움: 현재 서보 각도(왼쪽, 중앙 또는 오른쪽)를 보고하는 /status Telegram 명령을 추가합니다.
    • 중간: 1도씩 단계적으로 Bridge 콜백에서 위치 간 부드러운 이동을 구현합니다.
    • 고급: Telegram 명령으로 구성할 수 있는 여러 사전 설정 위치(/pos1, /pos2 등)를 추가합니다.