반응형
카메라의 회전과 물총의 발사를 위하여 아두이노에 서보모터를 작동시키는 방법을 알아보겠다.
먼저 서보모터를 사용하기 위해서는 서보모터를 연결시켜야한다.
우리는 서보모터를 2개 사용하기 때문에 아래와 같이 연결하였다.
위의 사진처럼 연결하면 되지만 사진이 잘 보이지 않는 관계로 그림을 함께 추가하였다.
사진 출처 [피지컬 컴퓨팅 교육]
사진을 간소화하면 아래의 그림과 같이 표현할 수 있다.
7번과 9번에 서보모터를 연결하였다.
서보모터를 사용하는 방법은 아두이노에서 제공하는 예제를 통하여 사용할 수 있다.
위의 예제 파일을 열면 아래와 같은 코드가 써있는 창을 확인할 수 있다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 | |
} | |
} |
위의 코드에서 알아야 할 코드는
Servo myservo; // 서보모터 변수 선언
myservo.attach(9); // 선언한 서보모터 변수에 9번에 연결된 모터를 연결
myservo.write(pos); // 서보모터 변수에 연결된 모터를 pos 각도로 회전
위의 코드들이다.
이제 저 코드들을 응용하여, 서보모터에 카메라와 물총의 트리거를 연결시켜 사용할 수 있다.
반응형
'프로젝트 > 딥 러닝 Smart Scarecrow (영상 인식)' 카테고리의 다른 글
[10]마무리 (Animal recognition using deep learning & Smart Scarecrow) (2) | 2017.11.11 |
---|---|
[9] 아두이노와 HTTP 통신 (0) | 2017.11.11 |
[7] 아두이노 환경 설정 (0) | 2017.11.10 |
[6] Apache2 Root Directory 변경 (0) | 2017.11.10 |
[5] Ubuntu 서버 구축(LAMP) (0) | 2017.10.19 |