반응형

카메라의 회전과 물총의 발사를 위하여 아두이노에 서보모터를 작동시키는 방법을 알아보겠다.


먼저 서보모터를 사용하기 위해서는 서보모터를 연결시켜야한다.


우리는 서보모터를 2개 사용하기 때문에 아래와 같이 연결하였다.



위의 사진처럼 연결하면 되지만 사진이 잘 보이지 않는 관계로 그림을 함께 추가하였다.


사진 출처 [피지컬 컴퓨팅 교육]

사진을 간소화하면 아래의 그림과 같이 표현할 수 있다.


7번과 9번에 서보모터를 연결하였다.


서보모터를 사용하는 방법은 아두이노에서 제공하는 예제를 통하여 사용할 수 있다.



위의 예제 파일을 열면 아래와 같은 코드가 써있는 창을 확인할 수 있다.


/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#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
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
view raw Sweep.ino hosted with ❤ by GitHub

위의 코드에서 알아야 할 코드는


Servo myservo;        // 서보모터 변수 선언


myservo.attach(9);    // 선언한 서보모터 변수에 9번에 연결된 모터를 연결


myservo.write(pos);    // 서보모터 변수에 연결된 모터를 pos 각도로 회전


위의 코드들이다.


이제 저 코드들을 응용하여, 서보모터에 카메라와 물총의 트리거를 연결시켜 사용할 수 있다.

반응형

+ Recent posts