تعلم الوحدات · الدرس 2.8

المحرك المؤازر (Servo (SG90))

العودة إلى الدروس

المحرك المؤازر (Servo (SG90))

المحرك المؤازر (Servo) محرك ذو تروس يدور في هذا المثال حتى 180 درجة. ترسل UNO R3 نبضات تحدد الموضع المطلوب. السلك البني أرضي ويوصل بـ GND، والأحمر تغذية إلى 5V، والبرتقالي إشارة إلى المنفذ الرقمي 9.

المكونات المطلوبة

مواصفات SG90

المحرك المؤازر (Servo) وملحقاته
المحرك المؤازر (Servo) وملحقاته

توصيل الدائرة

المخطط الكهربائي لالمحرك المؤازر (Servo)
المخطط الكهربائي لالمحرك المؤازر (Servo)
توصيل أسلاك SG90 بلوحة أردوينو (UNO R3 Board)
توصيل أسلاك SG90 بلوحة أردوينو (UNO R3 Board)

رفع البرنامج والمكتبة

قبل رفع البرنامج، تأكد من توفر مكتبة Servo في بيئة Arduino IDE. إذا لم تكن مثبتة أو ظهرت رسالة تشير إلى مكتبة مفقودة، فاتبع خطوات التثبيت في قسم «ما هي المكتبات؟» وطرق تثبيتها في الدرس 1.5 «وميض LED وإضافة المكتبات».

افتح ملف البرنامج servo.ino من ملفات الدرس في بيئة Arduino IDE. بعد إتمام التوصيلات، وصّل لوحة أردوينو (UNO R3 Board) بالحاسوب بكابل توصيل (USB Cable)، ثم اضغط زر Upload (رفع) لنقل البرنامج إلى اللوحة وتشغيله عليها.

الكود

servo/servo.ino

//www.elegoo.com
//2018.12.19
#include <Servo.h>
/* After including the corresponding libraries,
   we can use the "class" like "Servo" created by the developer for us.
   We can use the functions and variables created in the libraries by creating 
   objects like the following "myservo" to refer to the members in ".".*/

Servo myservo;
//it created an object called myservo.
/*  you can see Servo as a complex date type(Including functions and various data types)
    and see myservo as variables.               */

void setup(){
  /*"attach" and "write" are both functions,
     and they are members contained in the complex structure of "Servo". 
     We can only use them if we create the object "myservo" for the complex structure of "Servo".
  */
  myservo.attach(9);//connect pin 9 with the control line(the middle line of Servo) 
  myservo.write(90);// move servos to center position -> 90°
} 
void loop(){
  myservo.write(90);// move servos to center position -> 90°
  delay(1000);
  myservo.write(60);// move servos to center position -> 60°
  delay(1000);
  myservo.write(90);// move servos to center position -> 90°
  delay(1000);
  myservo.write(150);// move servos to center position -> 120°
  delay(1000);
}

ملفات الدرس والمكتبات

المكتبات المرفقة

ملفات الدرس

100%

عرض الصورة

استخدم + و− للتكبير والتصغير، أو اضغط Esc للإغلاق.