본문 바로가기
만들기/아두이노

아두이노 서보모터 회전운동을 왕복운동으로

by 훨훨날아 2022. 4. 9.

MG996R 서보모터를 이용해서 회전운동을 왕복운동으로 바꾸는 장치를 만들어보았다.

준비물: MG996R 서보모터, 아두이노 우노, 3D프린터

갈색 - GND 연결
빨강 -  + 연결
주황 - 아두이노 9번핀 연결

 

 

아두이노 코드

#include <Servo.h> 
 
int servoPin = 9;

Servo servo; 

int angle = 0; // servo position in degrees 

void setup() 
{ 
    servo.attach(servoPin); 
} 


void loop() 
{ 
  // scan from 0 to 180 degrees
  for(angle = 0; angle < 70; angle++) 
  { 
    servo.write(angle); 
    delay(20); 
  } 
  servo.detach();
  delay(2000); 
  servo.attach(servoPin); 
  // now scan back from 180 to 0 degrees
  for(angle = 70; angle > 0; angle--) 
  { 
    servo.write(angle); 
    delay(20); 
  }

 

3D프린팅 파츠

slide v1.stl
0.04MB
bar v3.stl
0.03MB
holder v2.stl
0.02MB

 

잘 움직이지만 약간 고정이 안되서 볼트너트를 이용해서 고정시켜야할 것 같다.

 

참고

http://wiki.vctec.co.kr/opensource/arduino/servocontrol

반응형