05-16 00:01
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[์•„๋‘์ด๋…ธ] ์„œ๋ณด ๋ชจํ„ฐ ์ œ์–ด ๋ณธ๋ฌธ

IoT/Arduino

[์•„๋‘์ด๋…ธ] ์„œ๋ณด ๋ชจํ„ฐ ์ œ์–ด

miinsun 2021. 12. 3. 18:02

 

๐Ÿ’ป ์‹ค์Šต ํ™˜๊ฒฝ

Board : Arduino UNO
Language : C

 

๐Ÿ’ฌ ์š”๊ตฌ ์‚ฌํ•ญ

์„œ๋ธŒ ๋ชจํ„ฐ๋ฅผ ์—ฐ๊ฒฐ
์‹œ๋ฆฌ์–ผ ์ฐฝ์—์„œ ํšŒ์ „ ๊ฐ์„ ์ž…๋ ฅ ๋ฐ›๊ธฐ
์ž…๋ ฅ ๋ฐ›์€ ํšŒ์ „ ๊ฐ์œผ๋กœ ์„œ๋ธŒ๋ชจํ„ฐ๋ฅผ ํšŒ์ „

 

- ํšŒ๋กœ๋„ ๊ฐœ์š”

์„œ๋ธŒ๋ชจํ„ฐ ๋ชจ๋“ˆ Arduino UNO
Brown Wire GND
Red Wire 5V
Orange Wire 9 or Other PWN port

 

๐Ÿ“Œ Code

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
  Serial.println("Servo motion version 2");
}

void loop() {

  if(Serial.available()){
    
    int input = Serial.parseInt();

    if(Serial.read() == '\n'){
      myservo.write(input);
      Serial.print("Move to: ");
      Serial.println(input);
    }
  }
}
Comments