Skip to content

Commit 78f246f

Browse files
committed
docs : 서보모터
1 parent 5e97aa9 commit 78f246f

File tree

1 file changed

+186
-2
lines changed

1 file changed

+186
-2
lines changed

부품&연결방법/모터.md

+186-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,180 @@
1-
# 📌
1+
# 📌 모터
2+
3+
- DC 모터
4+
5+
- 전원이 연결되면 연속으로 회전
6+
7+
- 정확한 위치 제어 어려움
8+
9+
- 서보 모터
10+
11+
- 정밀 제어 가능
12+
13+
- 스텝 모터
14+
15+
- 분할각 단위로만 회전 가능
16+
17+
- 하나의 펄스가 주어지면 분할각 만큼 회전하고 멈춤
18+
19+
<br><br>
20+
21+
### ✔ 서보 모터
22+
23+
- 0-180도 사이 회전
24+
25+
- PWM신호로 위치 제어
26+
27+
- 50Hz : 20ms
28+
29+
- 1ms : 0도 , 2ms : 180도
30+
31+
- 3개 연결선
32+
33+
- VCC : 붉은색
34+
35+
- GND : 검정색 갈색
36+
37+
- PWM출력 가능한 핀 : 노란색, 주황색 또는 흰색
38+
39+
40+
- **"Servo"**라이브러리
41+
42+
- 사용방법
43+
44+
1. "Servo"라이브러리
45+
46+
2. 객체 생성 : Servo myServo;
47+
48+
3. 제어핀 연결 : myServo.attach(servoPin);
49+
50+
4. 각도 지정 : myServo.write(angle);
51+
52+
- 연결방법
53+
54+
![image](https://user-images.githubusercontent.com/54584063/84380258-04589080-ac22-11ea-98ac-a5121c65324d.png)
55+
56+
- LAB
57+
58+
- 서보모터 제어
59+
60+
```c
61+
#include <Servo.h>
62+
63+
Servo myServo;
64+
int servoPin = 11;
65+
66+
void setup(){
67+
myServo.attach(servoPin);
68+
}
69+
70+
void loop(){
71+
int angle;
72+
for(angle=0; angle<180; angle++>){
73+
myServo.write(angle);
74+
delay(5);
75+
}
76+
for (angle=100; angle>0; angle--){
77+
myServo.write(angle);
78+
delay(5);
79+
}
80+
}
81+
```
82+
- 가변저항으로 서보 제어
83+
84+
```c
85+
#include <Servo.h>
86+
87+
Servo myServo;
88+
int servoPin = 11;
89+
90+
void setup(){
91+
myServo.attach(servoPin);
92+
}
93+
94+
void loop(){
95+
int value = analogRead(A0);
96+
int angle = map(value, 0, 1023, 0, 180);
97+
myServo.write(angle);
98+
}
99+
```
100+
- 가변저항값 -> 서보모터 회전 시간 제어
101+
102+
```c
103+
#include <Servo.h>
104+
105+
Servo myServo;
106+
int servoPin = 11;
107+
108+
void setup(){
109+
myServo.attach(servoPin);
110+
}
111+
112+
void loop(){
113+
time_current = millis();
114+
if (time_current - time_previous >= interval){
115+
time_previous = time_current;
116+
angle += angle_step;
117+
if (angle > 180){
118+
angle = 180;
119+
angle_stemp += -1
120+
}
121+
else if (angle < 0>){
122+
angle =0;
123+
angle_step *= -1;
124+
}
125+
myServo.write(angle);
126+
}
127+
int reading = analogRead(A0);
128+
int new_interval = map(reading, 0, 1023, 5, 20);
129+
if (new_interval != interval){
130+
interval = new_interval;
131+
Serial.print("Current Interval : ");
132+
Serial.println(interval);
133+
}
134+
}
135+
136+
```
137+
- 시리얼 모니터로 서보 제어
138+
139+
```c
140+
#include <Servo.h>
141+
142+
Servo myServo;
143+
144+
void setup(){
145+
myServo.attach(servoPin)
146+
}
147+
void loop(){
148+
while (Serial.available()){
149+
char data = Serial.read();
150+
if (data == '\n'){
151+
process_it = true;
152+
break;
153+
}
154+
buffer += data;
155+
}
156+
if (process_it) {
157+
process_it = false;
158+
int angle = buffer.toInt();
159+
Serial.print(String(">> ") + buffer);
160+
if (angle<0 || angle>180) {
161+
Serial.println("...invalid angle.");
162+
}else {
163+
Serial.println();
164+
myServo.write(angle);
165+
delay(3);
166+
}
167+
buffer = "";
168+
}
169+
}
170+
171+
```
172+
173+
174+
<br><br>
175+
176+
### ✔ DC 모터
177+
2178

3179
### ✔ 연결방법
4180

@@ -16,4 +192,12 @@
16192

17193
<br><br>
18194

19-
### 🔎 정리
195+
### 🔎 정리
196+
197+
- 서보모터
198+
199+
- 정밀한 위치제어 가능
200+
201+
- 0-180도 범위만 회전
202+
203+
- "Servo"라이브러리

0 commit comments

Comments
 (0)