0Pricing
Arduino & IoT Academy · درس

Servo يتحكم فيه مقبض

وجّه Servo باستخدام مقياس جهد.

Servo يتحكم فيه مقبض درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Steer with a Knob

Time to take control by hand. Turn a potentiometer and the servo follows in real time, like a tiny steering wheel. 🎛️

The Plan

The idea is simple: read the knob, convert that number into an angle, and write it to the servo, over and over inside loop().

Read the Knob

Use analogRead() on the pot's pin. It gives back a number from 0 to 1023 that follows how far you've turned the knob.

int val = analogRead(A0);

The Range Mismatch

The knob speaks 0 to 1023, but the servo only understands 0 to 180. You need to convert between those two scales.

map() to the Rescue

The map() function rescales a number from one range into another. It's the perfect bridge from knob units to servo degrees.

int angle = map(val, 0, 1023, 0, 180);

Send It to the Servo

Now feed that mapped angle straight into write(). The servo snaps to whatever position your knob is pointing at.

myServo.write(angle);

The Whole Loop

Read, map, write: stack those three lines in loop() and the servo tracks your knob continuously.

void loop() {
  int val = analogRead(A0);
  int angle = map(val, 0, 1023, 0, 180);
  myServo.write(angle);
}

Let It Settle

Add a tiny delay() at the end of the loop. It gives the servo a moment to reach each position and smooths out the motion.

delay(15);

Wire the Pot

The potentiometer's outer pins go to 5V and ground, and the middle wiper pin goes to analog pin A0. That gives a clean sweep of voltage.

Tame the Jitter

Analog readings wobble a little, so the servo may jitter. Reading several times and averaging, or ignoring tiny changes, calms it down.

Flip the Direction

Want the servo to turn the opposite way? Just swap the map output to go from 180 to 0 instead of 0 to 180.

int angle = map(val, 0, 1023, 180, 0);

Quick Check

Let's connect the knob reading to a servo angle.

Recap

Read the pot, map 0 to 1023 into 0 to 180, then write that angle each loop. Now your hand directly steers the servo. 🙌

الأسئلة الشائعة

هل درس «Servo يتحكم فيه مقبض» مجاني؟

نعم — نص درس «Servo يتحكم فيه مقبض» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

ماذا ستتعلم في «Servo يتحكم فيه مقبض»؟

وجّه Servo باستخدام مقياس جهد. تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟

لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «Servo يتحكم فيه مقبض»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟

نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. كيف يعرف Servo زاويته
  2. مكتبة Servo وattach
  3. الحركة من 0 إلى 180
  4. Servo يتحكم فيه مقبض
← العودة إلى Arduino & IoT Academy