IoT/Arduino

[Arduino] Servo Motor

솔웅 2017. 1. 10. 09:53
반응형


※ Servo Motor


Circuit




Source Code


Include Servo Library



#include <Servo.h>

Servo myservo;
int pos = 0;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(9);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(pos = 0; pos < 180; pos += 1)
  {
    myservo.write(pos);
    delay(15);
  }
}



※ Servo Motor with variable resistor


Circuit


Source Code


#include <Servo.h>

Servo myservo;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(9);
}

void loop() {
  // put your main code here, to run repeatedly:
  myservo.write(map(analogRead(A0),0,1023,0,120));
  delay(15);
}


refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=s_B8KYE7xvI&index=10&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w



반응형