Total Tayangan Halaman

Sabtu, 21 Maret 2015

Tutorial Servo Menggunakan Arduino

Rangkaian
Komponen yang diperlukan:
  • 1 buah servo mikro
  • Kabel jumper
Skema rangkaian dapat dilihat pada gambar berikut:

Skema rangkaian Servo dengan Arduino

Kode Pemrograman
. Klik menu File > Examples > Servo > Sweep.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
// Sweep // by BARRAGAN <http://barraganstudio.com> // This example code is in the public domain. #include <Servo.h>  Servo myservo;  // create servo object to control a servo                 // a maximum of eight servo objects can be created  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>=1; 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   } }

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int servoPin = 9; int pulseTime; void setup() {   Serial.begin(9600);   pinMode(servoPin,OUTPUT); } void loop() {   pulseTime = 2100; //(the number of microseconds                     //to pause for (1500 90 degrees                     // 900 0 degrees 2100 180 degrees)   digitalWrite(servoPin, HIGH);   delayMicroseconds(pulseTime);   digitalWrite(servoPin, LOW);   delay(25); }

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
int servoPin = 9; int pulseTime; void setup() {   Serial.begin(9600);   pinMode(servoPin,OUTPUT); }  void loop() {   for(pulseTime = 900; pulseTime <= 2100; pulseTime += 50) {     Serial.println(pulseTime);     digitalWrite(servoPin, HIGH);     delayMicroseconds(pulseTime);     digitalWrite(servoPin, LOW);     delay(25);   }   for(pulseTime = 2100; pulseTime >= 900; pulseTime -= 50) {     Serial.println(pulseTime);     digitalWrite(servoPin, HIGH);     delayMicroseconds(pulseTime);     digitalWrite(servoPin, LOW);     delay(25);   } }

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
int servoPin = 9; int pulseTime; void setup() {   Serial.begin(9600);   pinMode(servoPin,OUTPUT); }  void loop() {   for(pulseTime = 600; pulseTime <= 2650; pulseTime += 50) {     Serial.println(pulseTime);     digitalWrite(servoPin, HIGH);     delayMicroseconds(pulseTime);     digitalWrite(servoPin, LOW);     delay(25);   }   for(pulseTime = 2650; pulseTime >= 600; pulseTime -= 50) {     Serial.println(pulseTime);     digitalWrite(servoPin, HIGH);     delayMicroseconds(pulseTime);     digitalWrite(servoPin, LOW);     delay(25);   } }

Tidak ada komentar:

Posting Komentar