Chapterبەش 5 · Lectureوانە 5.6

Actuators: DC Motors, Encoders and Servosجووڵێنەرەکان: ماتۆڕەکانی DC، کۆدکەرەکانی هەنگاوبەهەنگاو و ماتۆڕەکانی سێرڤۆ

Actuators turn commands into action. A DC motor needs a driver (an H-bridge) and its own supply, never a pin; an encoder measures its turning so the board can close the loop; a positional servo goes to any angle set by the width of a pulse every 20 ms; a continuous-rotation servo turns speed instead of angle and needs limit switches. Ends with choosing a motor for the smart cage's cover.

فەرمان دەکەن بە کار. پێویستی بە () و خۆی هەیە، هەرگیز پین نا؛ سووڕانەوەکەی دەپێوێت تا بۆردەکە خولەکە دابخات؛ شوێنی دەچێتە سەر هەر گۆشەیەک کە پانایی لە هەموو ⁦20 ms⁩ـدا دیاری دەکات؛ لە جیاتی گۆشە خێرایی وەردەگرێت و پێویستی بە هەیە. بە هەڵبژاردنی بۆ بەرگی قەفەزە هۆشمەندەکە کۆتایی دێت.

22 min read21 خولەک خوێندنەوە · 20 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain what an actuator is and name the common ones, keeping mains loads away from boards.
  • Explain why a DC motor needs a driver, how an H-bridge reverses it and how PWM sets its speed.
  • Use an encoder's pulses to measure distance, speed and direction, and stop a motor at a target.
  • Set a positional servo to any angle with the Servo library and relate the angle to the pulse width.
  • Control a continuous-rotation servo and choose a motor for a real job.
  • ڕوونی بکەیتەوە چییە، باوەکانیان ناو ببەیت و بارەکانی کارەبای ماڵ لە بۆرد دوور بخەیتەوە.
  • ڕوونی بکەیتەوە بۆچی پێویستی بە هەیە، چۆن پێچەوانەی دەکاتەوە و چۆن خێراییەکەی دیاری دەکات.
  • بەکار بهێنیت بۆ پێوانی دووری، خێرایی و ئاراستە و لە ئامانجێکدا ڕابگریت.
  • شوێنی بە Servo بخەیتە سەر هەر گۆشەیەک و گۆشەکە بە پانایی ببەستیتەوە.
  • کۆنترۆڵ بکەیت و بۆ کارێکی ڕاستەقینە هەڵبژێریت.

From sensing to doingلە هەستکردنەوە بۆ کردن

Sensors bring the world into the board; actuators let the board change the world. An actuator turns an electrical command into a physical action: a turn, a push, a sound, light, heat. The smart cage at the end of this course needs one to pull a cover over the birds at dusk and back at dawn. This lesson compares the motors that can do it: DC motors with a driver, encoders that report the turning, and servos.

جیهان دەهێننە ناو بۆردەکەوە؛ ڕێگە بە بۆردەکە دەدەن جیهان بگۆڕێت. فەرمانێکی کارەبایی دەکات بە کارێکی جەستەیی: سووڕانەوەیەک، پاڵنانێک، دەنگێک، ڕووناکی، گەرمی. قەفەزە هۆشمەندەکەی کۆتایی ئەم کۆرسە پێویستی بە یەکێکیانە تا لە ئێوارەدا بەرگێک بەسەر باڵندەکاندا بکێشێت و لە بەرەبەیاندا لایبدات. ئەم وانەیە ئەو دەتوانن ئەمە بکەن بەراورد دەکات: لەگەڵ ، کە سووڕانەوەکە ڕاپۆرت دەکات و .

The pair sensor–actuator first appears in Sensors measure, actuators move; the AI course meets it in agents and robots (Actuators).

جووتی – یەکەم جار لە هەستەوەرەکان دەپێون، جووڵێنەرەکان دەجووڵێنن دەردەکەوێت؛ کۆرسی لە بریکار و ڕۆبۆتدا دەیبینێت (جووڵێنەرەکان).

Three boxes in a row: sense, an LDR, it is getting dark; decide, the board, close the cover; act, a driver and a motor pull the cover. An arrow goes on to a cage whose purple cover is half drawn. A dashed green arrow returns from act to decide: feedback, an encoder or a limit switch reports where the cover is. Below: an actuator turns the board's command into movement.سێ سندووق لە ڕیزێکدا: هەستکردن، LDR، تاریک دەبێت؛ بڕیاردان، بۆرد، بەرگەکە دابخە؛ کردن، درایڤەری ماتۆڕ و ماتۆڕ بەرگەکە دەکێشن. تیرێک دەڕوات بۆ قەفەزێک کە بەرگە مۆرەکەی تا نیوە کێشراوە. تیرێکی پچڕپچڕی سەوز لە کردنەوە دەگەڕێتەوە بۆ بڕیاردان: فیدباک، کۆدکەری هەنگاوبەهەنگاو یان سویچی سنوور دەڵێت بەرگەکە لە کوێیە. لە خوارەوە: جووڵێنەر فەرمانی بۆردەکە دەکات بە جووڵە.
Sense, decide, act — and check what really happened.هەستکردن، بڕیاردان، کردن — و پشکنینی ئەوەی بە ڕاستی ڕووی دا.CêIT

Actuators you will meetئەو جووڵێنەرانەی دەیانبینیت

Small IoT projects mostly use these: a DC gear motor that spins (wheels, fans, the string of a cover); a servo motor that goes to an angle (a flap, a valve); a stepper motor that moves in exact steps (3D printers, camera sliders); a water pump; a relay that switches another circuit; and simple output devices such as a buzzer or an LED. Drones use brushless motors driven by an ESC, which this course does not repeat (Brushless motors, The ESC).

پڕۆژە بچووکەکانی IoT زۆرتر ئەمانە بەکار دەهێنن: گێڕدار کە دەسووڕێت (چەرخ، پانکە، پەتی بەرگێک)؛ کە دەچێتە سەر گۆشەیەک (دەرچەیەک، زمانەیەک)؛ کە بە هەنگاوی ورد دەجووڵێت (چاپەری سێڕەهەندی، سڵایدەری کامێرا)؛ پەمپی ئاو؛ کە تر هەڵ و دەکوژێنێتەوە؛ و ئامێری دەرچوونی سادەی وەک یان . بەکار دەهێنن کە دەیانجووڵێنێت. ئەم کۆرسە ئەوانە دووپاتە ناکاتەوە (ماتۆڕە بێفڵچەکان، کۆنترۆڵکەری خێرایی).

Six tiles: DC gear motor, spins wheels, fans and the cover's string; servo motor, goes to an angle for a flap or a valve; stepper motor, exact steps for 3D printers; water pump, a small motor inside that waters plants; relay, switches another circuit; buzzer and LED, simple output devices for sound and light. Below in orange: mains loads such as heaters and coolers never connect to a board; low voltage only in these labs.شەش کارت: ماتۆڕی DCـی گێڕدار، چەرخ، پانکە و پەتی بەرگەکە دەسووڕێنێت؛ ماتۆڕی سێرڤۆ، دەچێتە سەر گۆشەیەک بۆ دەرچەیەک یان زمانەیەک؛ ماتۆڕی هەنگاوی، هەنگاوی ورد بۆ چاپەری سێڕەهەندی؛ پەمپی ئاو، ماتۆڕێکی بچووک لە ناویدا کە ئاو دەداتە ڕووەکەکان؛ ڕیلەی، سووڕێکی تر هەڵ و دەکوژێنێتەوە؛ بەزەر و LED، ئامێری دەرچوونی سادە بۆ دەنگ و ڕووناکی. لە خوارەوە بە پرتەقاڵی: بارە گەورەکانی کارەبای ماڵ وەک گەرمکەرەوە و ساردکەرەوە هەرگیز ڕاستەوخۆ لە بۆرد نادرێن؛ لەم تاقیگانەدا تەنیا ڤۆڵتیەی نزم.
Turning, pointing, stepping, pumping, switching.سووڕانەوە، ئاماژەکردن، هەنگاونان، پەمپکردن، هەڵکردن و کوژاندنەوە.CêIT

The DC motor: it spins while current flowsماتۆڕی DC: تا تەزوو هەبێت دەسووڕێت

A DC motor has fixed magnets and a rotor with coils. Brushes and a split ring (the commutator) keep switching the current in the coils, so the magnets always pull the rotor further round. More voltage, more speed; swap the two wires and it turns the other way. Left to itself, a DC motor turns freely: it does not know where it is and stops only when the current stops.

موگناتیسی جێگیر و بەشێکی سووڕاوی بە پێچی کارەبایی هەیە. فڵچەکان و ئەڵقەیەکی لەتکراو (گۆڕەرەکە) بەردەوام ناو پێچەکان دەگۆڕن، بۆیە موگناتیسەکان هەمیشە بەشە سووڕاوەکە زیاتر دەسووڕێنن. زیاتر، خێرایی زیاتر؛ دوو وایەرەکەی ئاڵوگۆڕ بکە و بە پێچەوانەوە دەسووڕێت. ئەگەر بە خۆی بهێڵرێتەوە، بە ئازادی دەسووڕێت: نازانێت لە کوێیە و تەنیا کاتێک دەوەستێت کە دەبڕێت.

Small motors spin fast but weakly, so a gearbox is added: a gear motor trades speed for turning force (torque). A yellow TT motor, for example, has a 1:48 gearbox and turns its shaft about 200 times a minute at 6 V. In the cage project a gear motor with an encoder can wind the cover's string to remove and replace the cover.

بچووکەکان خێرا بەڵام لاواز دەسووڕێن، بۆیە گێڕبۆکسێک زیاد دەکرێت: گێڕدار خێرایی دەدات بە هێزی سووڕاندن (). بۆ نموونە TTـی زەرد گێڕبۆکسێکی ⁦1:48⁩ـی هەیە و بە ⁦6 V⁩ تەوەرەکەی نزیکەی ⁦200⁩ جار لە خولەکێکدا دەسووڕێنێت. لە پڕۆژەی قەفەزەکەدا گێڕدار بە دەتوانێت پەتی بەرگەکە بپێچێتەوە تا بەرگەکە لابدات و دایبداتەوە.

Left, a DC motor cut across: a red N magnet and a blue S magnet inside the can, a rotor with three copper coils in the middle and a green arrow showing it turn; labels: magnets (fixed), coils on the turning rotor, brushes and commutator switch the current; + and − on the two wires, swap them and it turns the other way. Right, a gear motor: the motor and a yellow gearbox with three gears and a slow output shaft; motor fast and weak, shaft slow and strong; e.g. a TT motor, 1:48, about 200 rpm at 6 V.چەپ، ماتۆڕی DCـێک کە بڕاوە: موگناتیسێکی سووری N و موگناتیسێکی شینی S لە ناو قاپەکەدا، بەشێکی سووڕاو بە سێ پێچی مسی لە ناوەڕاستدا و تیرێکی سەوز کە سووڕانەوەکەی پیشان دەدات؛ نووسینەکان: موگناتیس (جێگیر)، پێچی کارەبایی لەسەر بەشە سووڕاوەکە، فڵچە و گۆڕەرەکە تەزووەکە دەگۆڕن؛ + و − لەسەر دوو وایەرەکە، ئاڵوگۆڕیان بکە و بە پێچەوانەوە دەسووڕێت. ڕاست، ماتۆڕی DCـی گێڕدار: ماتۆڕەکە و گێڕبۆکسێکی زەرد بە سێ گێڕ و تەوەرەیەکی هێواشی دەرچوون؛ ماتۆڕ خێرا و لاواز، تەوەرە هێواش و بەهێز؛ بۆ نموونە ماتۆڕی TT، 1:48، نزیکەی 200 rpm بە 6 V.
Magnets and coils make it turn; gears make it slow and strong.موگناتیس و پێچ دەیسووڕێنن؛ گێڕ هێواش و بەهێزی دەکات.CêIT

Never drive a motor straight from a pinهەرگیز ماتۆڕێک ڕاستەوخۆ لە پینێکەوە مەجووڵێنە

A pin can give a few milliamps: about 20 mA on an UNO R3, 8 mA on an UNO R4, 7 mA on the MKR WAN 1310 (5 V boards and 3.3 V boards). A small TT gear motor takes about 150 mA when it runs free and over 1 A when it starts or is blocked. A motor coil also kicks back a voltage spike when it is switched off, and its brushes make electrical noise.

پینێک دەتوانێت چەند میلی‌ئەمپێرێک بدات: نزیکەی ⁦20 mA⁩ لەسەر ⁦UNO R3⁩، ⁦8 mA⁩ لەسەر ⁦UNO R4⁩، ⁦7 mA⁩ لەسەر ⁦MKR WAN 1310⁩ (بۆردەکانی ⁦5 V⁩ و بۆردەکانی ⁦3.3 V⁩). گێڕداری بچووکی TT کاتێک بە ئازادی دەسووڕێت نزیکەی ⁦150 mA⁩ وەردەگرێت و کاتێک دەست پێدەکات یان دەگیرێت زیاتر لە ⁦1 A⁩. هەروەها پێچی کاتێک دەکوژێنرێتەوە بڕێک بەرز دەداتەوە و فڵچەکانی ژاوەژاوی کارەبایی دروست دەکەن.

Horizontal bars on a ten-times scale from 1 mA to 3 A: MKR WAN 1310 pin 7 mA, UNO R4 pin 8 mA, UNO R3 pin 20 mA (blue), TT gear motor running about 150 mA (orange), TT gear motor blocked about 1.5 A (red). Note: each grid line is ten times more; a motor on a pin burns the pin and resets the board.شریتی ئاسۆیی لەسەر پێوەرێکی دە هێندەیی لە 1 mA تا 3 A: پینی MKR WAN 1310 7 mA، پینی UNO R4 8 mA، پینی UNO R3 20 mA (شین)، ماتۆڕی TT لە کاردا نزیکەی 150 mA (پرتەقاڵی)، ماتۆڕی TT گیراو نزیکەی 1.5 A (سوور). تێبینی: هەر هێڵێک دە هێندەیە؛ ماتۆڕ لەسەر پین پینەکە دەسووتێنێت و بۆردەکە دەکوژێنێتەوە.
Milliamps from a pin, hundreds of milliamps for a motor.میلی‌ئەمپێر لە پینێکەوە، سەدان میلی‌ئەمپێر بۆ .CêIT

The H-bridge: forward, backward, stopپردی H: پێشەوە، دواوە، وەستان

To reverse a motor without swapping wires by hand, a driver uses an H-bridge: four electronic switches (transistors) around the motor, drawn like the letter H. Close the top-left and bottom-right switches and the current crosses the motor from left to right; close the other diagonal and it crosses from right to left, so the motor turns the other way. Close both lower switches and the motor's ends are joined: it brakes fast. Never close both switches on one side: that joins the supply straight to GND, a short circuit — driver chips are built so this cannot happen.

بۆ پێچەوانەکردنەوەی بەبێ ئاڵوگۆڕی وایەر بە دەست، بەکار دەهێنێت: چوار ئەلیکترۆنی () لە دەوری ، کە وەک پیتی H دەکێشرێن. سەرەوەی چەپ و خوارەوەی ڕاست دابخە و لە چەپەوە بۆ ڕاست بە تێدەپەڕێت؛ لارەکەی تر دابخە و لە ڕاستەوە بۆ چەپ تێدەپەڕێت، بۆیە بە پێچەوانەوە دەسووڕێت. هەردوو خوارەوە دابخە و دوو سەری پێکەوە دەبەسترێن: بە خێرایی دەوەستێت. هەرگیز هەردوو یەک لا دامەخە: ئەوە سەرچاوەکە ڕاستەوخۆ بە GNDـەوە دەبەستێت، — چیپەکانی وا دروست کراون کە ئەمە ڕوو نەدات.

Animation in five steps on an H-bridge between +6 V and GND with switches S1, S2 (top) and S3, S4 (bottom) and a motor M in the middle. All open: no current, the motor coasts. S1 and S4 closed: a green current path from left to right, the motor turns one way; driver inputs IN1 HIGH, IN2 LOW, clockwise. S3 and S4 closed: both ends on GND, short brake. S2 and S3 closed: current from right to left, counterclockwise. Last, in red: never S1 and S3, +6 V straight to GND, a short circuit; the chip never allows this.
Animation in five steps on an H-bridge between +6 V and GND with switches S1, S2 (top) and S3, S4 (bottom) and a motor M in the middle. All open: no current, the motor coasts. S1 and S4 closed: a green current path from left to right, the motor turns one way; driver inputs IN1 HIGH, IN2 LOW, clockwise. S3 and S4 closed: both ends on GND, short brake. S2 and S3 closed: current from right to left, counterclockwise. Last, in red: never S1 and S3, +6 V straight to GND, a short circuit; the chip never allows this.
Which diagonal is closed decides the direction.کام لار داخراوە ئاراستەکە دیاری دەکات.CêIT

The H-bridge: forward, backward, stopپردی H: پێشەوە، دواوە، وەستان

Driver boards: L298N and TB6612FNGبۆردی درایڤەری ماتۆڕ: ⁦L298N⁩ و ⁦TB6612FNG⁩

A motor driver chip holds two H-bridges and the logic around them. From the board it takes small signals: two direction inputs per motor (IN1, IN2) and a speed input fed with PWM (PWM: on and off, faster than the eye); the motor current comes from the motor's own supply (VM). The old L298N handles up to 46 V and 2 A per bridge, but its transistors lose 1.8–3.2 V at 1 A, so a 6 V battery gives the motor only about 3–4 V. The TB6612FNG uses MOSFETs: 1.2 A per motor (3.2 A for short peaks), a motor supply up to 13.5 V and logic from 2.7 to 5.5 V.

چیپێکی دوو و لۆجیکی دەوروبەریان هەڵدەگرێت. لە بۆردەکەوە بچووک وەردەگرێت: بۆ هەر دوو ئاراستە (⁦IN1⁩، ⁦IN2⁩) و خێرایی کە بە پڕ دەکرێتەوە (مۆدیولەیشنی پانایی تڕپە: هەڵکردن و کوژاندنەوە، لە چاو خێراتر)؛ لە خودی دێت ⁦(VM)⁩. ⁦L298N⁩ـی کۆن تا ⁦46 V⁩ و ⁦2 A⁩ بۆ هەر پردێک دەگرێت، بەڵام لە ⁦1 A⁩ـدا ⁦1.8–3.2 V⁩ بەفیڕۆ دەدەن، بۆیە پاترییەکی ⁦6 V⁩ تەنیا نزیکەی ⁦3–4 V⁩ دەداتە . ⁦TB6612FNG⁩ MOSFET بەکار دەهێنێت: ⁦1.2 A⁩ بۆ هەر (⁦3.2 A⁩ بۆ لووتکەی کورت)، تا ⁦13.5 V⁩ و لۆجیک لە ⁦2.7⁩ تا ⁦5.5 V⁩.

IN1پینی ⁦IN1⁩IN2پینی ⁦IN2⁩TB6612FNG does⁦TB6612FNG⁩ چی دەکات
HIGHLOWturns one way (CW), speed from PWMبە یەک ئاراستە دەسووڕێت ⁦(CW)⁩، خێرایی لە
LOWHIGHturns the other way (CCW)بە ئاراستەکەی تر دەسووڕێت ⁦(CCW)⁩
HIGHHIGHshort brake: stops fastڕاگرتنی خێرا: بە خێرایی دەوەستێت
LOWLOWstop (with PWM HIGH): the motor is let go and coastsوەستان (بە HIGH): بەرەڵا دەکرێت و بە خۆی دەوەستێت
An Arduino UNO wired to a red TB6612FNG driver board: pin 5 to PWMA, pin 8 to AIN2, pin 7 to AIN1, pin 4 to STBY, 5V to VCC and GND to GND. A pack of four AA cells, 6 V, goes to VM and GND on the other side; A01 and A02 go to a small gear motor. Notes: UNO 7, 8 = direction, 5 = speed (PWM), 4 = STBY; VCC = logic 5 V, VM = motor battery; join the grounds; the pin only sends small signals, the battery's current goes through the driver to the motor.Arduino UNO بەستراو بە بۆردێکی سووری درایڤەری ماتۆڕی TB6612FNG: پینی 5 بۆ PWMA، پینی 8 بۆ AIN2، پینی 7 بۆ AIN1، پینی 4 بۆ STBY، 5V بۆ VCC و GND بۆ GND. پاترییەکی چوار AA، 6 V، لە لاکەی ترەوە دەچێت بۆ VM و GND؛ A01 و A02 دەچن بۆ ماتۆڕێکی گێڕداری بچووک. تێبینی: UNO 7، 8 = ئاراستە، 5 = خێرایی (PWM)، 4 = STBY؛ VCC = لۆجیکی 5 V، VM = پاتریی ماتۆڕ؛ زەوییەکان یەک بخە؛ پینەکە تەنیا سیگناڵەکانی بچووک دەنێرێت، تەزووی پاترییەکە بە درایڤەری ماتۆڕەکەدا دەچێتە ماتۆڕەکە.
Small signals from the board, big current from the battery. بچووک لە بۆردەوە، گەورە لە پاترییەوە.CêIT

The H-bridge: forward, backward, stopپردی H: پێشەوە، دواوە، وەستان

Code: forward, brake, backwardکۆد: پێشەوە، ڕاگرتن، دواوە

The sketch wraps the truth table in three small functions. STBY goes HIGH once to wake the driver; then the motor runs forward at speed 200 for 2 s, brakes for 1 s, runs backward at 120 for 2 s and brakes again.

لە سێ بچووکدا دادەنێت. STBY جارێک دەبێتە HIGH تا بەئاگا بێت؛ پاشان 2 چرکە بە خێرایی ⁦200⁩ بەرەو پێشەوە دەسووڕێت، 1 چرکە ڕادەگیرێت، 2 چرکە بە ⁦120⁩ بەرەو دواوە دەسووڕێت و دیسان ڕادەگیرێت.

A DC gear motor through a TB6612FNGماتۆڕی DCـی گێڕدار لە ڕێگەی ⁦TB6612FNG⁩motor_driver.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// A DC gear motor through a TB6612FNG driver (Arduino UNO): forward, brake, backward
const int ain1 = 7;      // direction input 1
const int ain2 = 8;      // direction input 2
const int pwma = 5;      // speed: a PWM pin (~5)
const int stby = 4;      // HIGH = the driver is awake

void setup() {
  Serial.begin(9600);
  pinMode(ain1, OUTPUT);
  pinMode(ain2, OUTPUT);
  pinMode(pwma, OUTPUT);
  pinMode(stby, OUTPUT);
  digitalWrite(stby, HIGH);
}

void forward(int speed) {      // speed 0-255
  digitalWrite(ain1, HIGH);
  digitalWrite(ain2, LOW);
  analogWrite(pwma, speed);
}

void backward(int speed) {
  digitalWrite(ain1, LOW);
  digitalWrite(ain2, HIGH);
  analogWrite(pwma, speed);
}

void brake() {                 // both inputs HIGH: short brake
  digitalWrite(ain1, HIGH);
  digitalWrite(ain2, HIGH);
  analogWrite(pwma, 0);
}

void loop() {
  Serial.println("forward, speed 200");
  forward(200);
  delay(2000);
  Serial.println("brake");
  brake();
  delay(1000);
  Serial.println("backward, speed 120");
  backward(120);
  delay(2000);
  Serial.println("brake");
  brake();
  delay(1000);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 13

STBY HIGH: the driver is awake.

STBY HIGH: بەئاگایە.

Lineدێڕی 16-20

Forward: IN1 HIGH, IN2 LOW, speed as a PWM value 0–255.

پێشەوە: ⁦IN1 HIGH⁩، ⁦IN2 LOW⁩، خێرایی وەک نرخێکی ⁦0–255⁩.

Lineدێڕی 22-26

Backward: the two inputs swapped.

دواوە: دوو ئاڵوگۆڕ کراون.

Lineدێڕی 28-32

Both HIGH: a short brake.

هەردووکیان HIGH: ڕاگرتنی خێرا.

Pin levels from the checker over 6 seconds: AIN1 (pin 7) HIGH, LOW from 3 to 5 s, HIGH again; AIN2 (pin 8) LOW, then HIGH from 2 s; PWMA (pin 5) 200 = 78 % from 0 to 2 s and 120 = 47 % from 3 to 5 s. Strips below: forward, brake, backward, brake.ئاستی پینەکان لە پشکنەرەکەوە لە ماوەی 6 چرکەدا: AIN1 (پینی 7) HIGH، لە 3 تا 5 چرکە LOW، دیسان HIGH؛ AIN2 (پینی 8) LOW، پاشان لە چرکەی 2ـەوە HIGH؛ PWMA (پینی 5) 200 = 78% لە 0 تا 2 چرکە و 120 = 47% لە 3 تا 5 چرکە. شریتەکانی خوارەوە: پێشەوە، ڕاگرتن، دواوە، ڕاگرتن.
Two direction pins and one speed pin tell the whole story.دوو پینی ئاراستە و یەک پینی خێرایی هەموو چیرۆکەکە دەگێڕنەوە.CêIT

Encoders: the motor reports backکۆدکەری هەنگاوبەهەنگاو: ماتۆڕەکە ڕاپۆرت دەداتەوە

A DC motor alone cannot say how far it has turned. An encoder on its shaft can: in a gear motor it is usually an incremental encoder, a magnet ring (or a slotted disc) with two small sensors, A and B, that give a pulse for every small step of rotation. The encoder only measures. It does not choose the direction or stop the motor — the driver does that, on the board's command.

بە تەنیا ناتوانێت بڵێت چەندی سووڕاوە. لەسەر تەوەرەکەی دەتوانێت: لە گێڕداردا زۆرجار ، ئەڵقەیەکی موگناتیس (یان قرسێکی کونکراو) بە دوو بچووکی A و B کە بۆ هەر هەنگاوێکی بچووکی سووڕانەوە دەدەن. تەنیا دەپێوێت. ئاراستە هەڵنابژێرێت و ڕاناگرێت — ئەمە دەکات، بە فەرمانی بۆردەکە.

  • Count the pulses → how far the shaft has turned (the position).
  • Pulses per second → how fast it turns.
  • Which of A and B rises first → which way it turns: A and B are a quarter of a pulse apart (quadrature).
  • بژمێرە ← تەوەرەکە چەندی سووڕاوە (شوێن).
  • لە چرکەیەکدا ← چەند خێرا دەسووڕێت.
  • کامیان لە A و B یەکەم بەرز دەبێتەوە ← بە کام ئاراستەدا دەسووڕێت: A و B چارەکێکی لە یەکتر دوورن.

After power-up it knows nothing: the count starts at 0 wherever the shaft is. So a project first drives to a known place, such as a limit switch at one end (homing), and counts from there.

دوای هەڵکردن هیچ نازانێت: ژماردنەکە لە 0ـەوە دەست پێدەکات لە هەر شوێنێکدا تەوەرەکە بێت. بۆیە پڕۆژەیەک سەرەتا دەچێتە شوێنێکی ناسراو (وەک لە سەرێکدا) و لەوێوە دەژمێرێت.

Left, a magnet ring of red and blue sectors on a motor shaft, with two black sensors A and B beside it and a green arrow for the turning. Right, two square pulse trains A (blue) and B (orange), B a quarter of a pulse later than A; turning one way, A rises before B. Lists: count the pulses, how far it turned; pulses per second, how fast; which one rises first, which way. In orange: it measures, it does not drive; the driver sets direction and speed.چەپ، ئەڵقەیەکی موگناتیسی بەشە سوور و شینەکان لەسەر تەوەرەی ماتۆڕێک، بە دوو هەستەوەری ڕەشی A و B لە تەنیشتیەوە و تیرێکی سەوز بۆ سووڕانەوەکە. ڕاست، دوو ڕیزە تڕپەی چوارگۆشەی A (شین) و B (پرتەقاڵی)، B چارەکێکی تڕپەیەک لە دوای A؛ بە یەک ئاراستە، A پێش B بەرز دەبێتەوە. لیستەکان: ژماردنی تڕپەکان، چەندی سووڕاوە؛ تڕپە لە چرکەیەکدا، چەند خێرا؛ کامیان یەکەم بەرز دەبێتەوە، بە کام ئاراستەدا. بە پرتەقاڵی: دەپێوێت، نایجووڵێنێت؛ درایڤەری ماتۆڕ ئاراستە و خێرایی دیاری دەکات.
Two sensors, two pulse trains: distance, speed and direction.دوو ، دوو ڕیزە : دووری، خێرایی و ئاراستە.CêIT

Encoders: the motor reports backکۆدکەری هەنگاوبەهەنگاو: ماتۆڕەکە ڕاپۆرت دەداتەوە

An encoder gear motor's six wiresشەش وایەری ماتۆڕی DCـێکی گێڕدار بە کۆدکەری هەنگاوبەهەنگاوەوە

A gear motor with an encoder usually has six wires: two for the motor (to the driver's outputs, never to the board) and four for the encoder: VCC and GND (3.3–5 V from the board), A and B (to two input pins). Most motor encoders use Hall sensors with open outputs, so set the pins to INPUT_PULLUP or add pull-up resistors (INPUT_PULLUP). The number of pulses per turn is printed on the motor's data sheet: count pulses per turn of the output shaft, which is the motor's figure times the gear ratio.

گێڕدار بە زۆرجار شەش وایەری هەیە: دووان بۆ (بۆ دەرچوونەکانی ، هەرگیز بۆ بۆردەکە) و چواریان بۆ : VCC و ⁦GND (3.3–5 V⁩ لە بۆردەکەوە)، A و B (بۆ دوو پینی ). زۆربەی ماتۆڕ Hall بە دەرچوونی کراوە بەکار دەهێنن، بۆیە پینەکان بکە بە INPUT_PULLUP یان زیاد بکە (⁦INPUT_PULLUP⁩). ژمارەی بۆ هەر سووڕانەوەیەک لە نووسراوە: بۆ هەر سووڕانەوەیەکی تەوەرەی دەرچوون بژمێرە، کە ژمارەکەی جارانی ڕێژەی گێڕەکان.

Encoders: the motor reports backکۆدکەری هەنگاوبەهەنگاو: ماتۆڕەکە ڕاپۆرت دەداتەوە

Closed loop: count, compare, correctخولی داخراو: بژمێرە، بەراورد بکە، ڕاستی بکەرەوە

With an encoder the board can close the loop (Closed-loop control): it sets a target, runs the motor, counts the pulses and brakes when the count reaches the target. This sketch counts rising edges of channel A by checking the pin on every pass of loop(); real projects count with an interrupt (attachInterrupt()) so no pulse is ever missed, even when the sketch is busy.

بە بۆردەکە دەتوانێت خولەکە دابخات (کۆنترۆڵی خولی داخراو): ئامانجێک دادەنێت، دەسووڕێنێت، دەژمێرێت و کاتێک ژمارەکە گەیشتە ئامانجەکە ڕایدەگرێت. ئەم بە پشکنینی پینەکە لە هەر خولێکی loop()ـدا کەناڵی A دەژمێرێت؛ پڕۆژە ڕاستەقینەکان بە (attachInterrupt()) دەژمێرن تا هیچ لەدەست نەچێت، تەنانەت کاتێک سەرقاڵە.

Run until 30 pulses, then brakeبسووڕێ تا ⁦30⁩ تڕپە، پاشان ڕابگرەencoder_count.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// Closed loop: run the motor until the encoder has sent 30 pulses, then brake
const int ain1 = 7;
const int ain2 = 8;
const int pwma = 5;
const int stby = 4;
const int encoderA = 2;      // channel A of the motor's encoder
const long target = 30;      // pulses to travel

long count = 0;
int lastA = HIGH;
bool moving = true;

void setup() {
  Serial.begin(9600);
  pinMode(ain1, OUTPUT);
  pinMode(ain2, OUTPUT);
  pinMode(pwma, OUTPUT);
  pinMode(stby, OUTPUT);
  pinMode(encoderA, INPUT_PULLUP);
  digitalWrite(stby, HIGH);
  digitalWrite(ain1, HIGH);    // forward
  digitalWrite(ain2, LOW);
  analogWrite(pwma, 150);
  Serial.println("motor on");
}

void loop() {
  int a = digitalRead(encoderA);
  if (a == HIGH && lastA == LOW) {   // a rising edge: one more pulse
    count++;
    if (count % 10 == 0) {
      Serial.print(count);
      Serial.println(" pulses");
    }
  }
  lastA = a;

  if (moving && count >= target) {   // compare with the set point
    digitalWrite(ain1, HIGH);        // brake
    digitalWrite(ain2, HIGH);
    analogWrite(pwma, 0);
    moving = false;
    Serial.print("target reached at ");
    Serial.print(millis());
    Serial.println(" ms: brake");
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 29-30

A rising edge (LOW before, HIGH now) is one more pulse.

(پێشتر LOW، ئێستا HIGH) ترە.

Lineدێڕی 38-42

Compare with the target; brake once it is reached.

بەراورد لەگەڵ ئامانجەکەدا؛ کە گەیشتێ، ڕایبگرە.

Five boxes in a loop: target 30 pulses; compare, is count below 30?; driver, run or brake; motor turns; encoder, count++. A green arrow runs from the encoder back to the comparison: feedback, every pulse goes back to the comparison. Note: without the encoder the board can only guess with timed runs; with it, it knows.پێنج سندووق لە خولێکدا: ئامانج 30 تڕپە؛ بەراورد، ئایا ژمارە لە خوار 30ـەوەیە؟؛ درایڤەری ماتۆڕ، بیسووڕێنە یان ڕایبگرە؛ ماتۆڕ دەسووڕێت؛ کۆدکەری هەنگاوبەهەنگاو، count++. تیرێکی سەوز لە کۆدکەری هەنگاوبەهەنگاوەوە دەگەڕێتەوە بۆ بەراوردەکە: فیدباک، هەر تڕپەیەک دەگەڕێتەوە بۆ بەراوردەکە. تێبینی: بەبێ کۆدکەری هەنگاوبەهەنگاو بۆردەکە تەنیا دەتوانێت بە کات مەزەندە بکات؛ لەگەڵیدا، دەزانێت.
The encoder closes the loop. خولەکە دادەخات.CêIT

The servo: a motor that goes to an angleماتۆڕی سێرڤۆ: ماتۆڕێک کە دەچێتە سەر گۆشەیەک

A hobby servo motor (such as the 9 g SG90) is a small DC motor, a gearbox, a position sensor (a variable resistor on the output shaft) and a control board in one box: its own closed loop. You tell it an angle; it turns until its sensor reports that angle and then holds it. A positional (standard) servo can be set to any angle in its range, usually about 0–180°, not only to 0°, 90° and 180°. It has three wires: brown (or black) GND, red 5 V, and orange (or yellow) for the signal.

هۆبی (وەک ⁦SG90⁩ـی ⁦9 g⁩) بچووک، گێڕبۆکسێک، شوێن ( لەسەر تەوەرەی دەرچوون) و بۆردێکی کۆنترۆڵە لە یەک سندووقدا: خولی داخراوی خۆی. گۆشەیەکی پێ دەڵێیت؛ دەسووڕێت تا ئەو گۆشەیە ڕاپۆرت دەکات و پاشان ڕایدەگرێت. شوێنی (ئاسایی) دەتوانرێت بخرێتە سەر هەر گۆشەیەک لە نێوان سنوورەکانیدا، زۆرجار نزیکەی ⁦0–180°⁩، نەک تەنیا ⁦0°⁩، ⁦90°⁩ و ⁦180°⁩. سێ وایەری هەیە: قاوەیی (یان ڕەش) GND، سوور ⁦5 V⁩ و پرتەقاڵی (یان زەرد) بۆ .

A servo opened up: a small motor, a train of three gears that make it slow and strong, a blue position sensor (a variable resistor) under the output gear, a green control board, and the horn on the output shaft. Three wires: GND (brown), 5 V (red), signal (orange). Side panel, its own closed loop: 1 the pulse says go to 90°; 2 the sensor says now at 60°; 3 the board runs the motor; 4 at 90° it stops and holds. SG90: about 180° in all, 9 g.ماتۆڕی سێرڤۆیەک کە کراوەتەوە: ماتۆڕێکی بچووک، ڕیزێک لە سێ گێڕ کە هێواش و بەهێزی دەکەن، هەستەوەرێکی شینی شوێن (بەرگری گۆڕاو) لە ژێر گێڕی دەرچووندا، بۆردێکی سەوزی کۆنترۆڵ و باسکەکە (هۆرن) لەسەر تەوەرەی دەرچوون. سێ وایەر: GND (قاوەیی)، 5 V (سوور)، سیگناڵ (پرتەقاڵی). بەشی تەنیشت، خولی داخراوی خۆی: 1 تڕپەکە دەڵێت بڕۆ بۆ 90°؛ 2 هەستەوەرەکە دەڵێت ئێستا گۆشەکە 60°؛ 3 بۆردەکە ماتۆڕەکە دەسووڕێنێت؛ 4 کە گەیشتە 90° دەوەستێت و دەمێنێتەوە. SG90: نزیکەی 180° بە گشتی، 9 g.
A motor, gears, a position sensor and a controller in one box.، گێڕ، شوێن و کۆنترۆڵکەرێک لە یەک سندووقدا.CêIT

The servo: a motor that goes to an angleماتۆڕی سێرڤۆ: ماتۆڕێک کە دەچێتە سەر گۆشەیەک

Pulse width sets the angleپانایی تڕپە گۆشەکە دیاری دەکات

The signal wire gets one pulse about every 20 ms (50 times a second); the width of the pulse is the angle. The SG90's data sheet shows a 20 ms period and pulses of about 0.5 to 2.4 ms across its whole turn, with the middle near 1.45–1.5 ms; older copies of the sheet give the classic 1–2 ms of RC servos. Arduino's Servo library sends 544 µs for 0° and 2400 µs for 180° by default:

وایەری نزیکەی هەموو ⁦20 ms⁩ جارێک وەردەگرێت (⁦50⁩ جار لە چرکەیەکدا)؛ پانایی گۆشەکەیە. ⁦SG90⁩ ⁦20 ms⁩ و نزیکەی ⁦0.5⁩ تا ⁦2.4 ms⁩ بۆ تەواوی سووڕانەوەکەی پیشان دەدات، ناوەڕاستەکەی نزیکەی ⁦1.45–1.5 ms⁩ـە؛ کۆپیی کۆنتری پەڕەکە ⁦1–2 ms⁩ـی کلاسیکی سێرڤۆکانی RC دەدات. Servoـی Arduino بە شێوەی بنەڕەت ⁦544 µs⁩ بۆ ⁦0°⁩ و ⁦2400 µs⁩ بۆ ⁦180°⁩ دەنێرێت:

tpulse=544 μs+angle×2400−544180 μs90∘⇒544+928=1472 μst_{pulse} = 544\,\mu\text{s} + \text{angle} \times \frac{2400 - 544}{180}\,\mu\text{s} \qquad 90^\circ \Rightarrow 544 + 928 = 1472\,\mu\text{s}
Animation in six steps: a pulse train with a 20 ms period whose pulse gets wider, drawn four times wider so it can be seen, next to a servo whose horn turns on a half circle from 0° to 180°: write(0) 544 µs, horn left; write(45) 1008 µs; write(90) 1472 µs, horn up; write(135) 1936 µs; write(180) 2400 µs, horn right; and back to write(90).
Animation in six steps: a pulse train with a 20 ms period whose pulse gets wider, drawn four times wider so it can be seen, next to a servo whose horn turns on a half circle from 0° to 180°: write(0) 544 µs, horn left; write(45) 1008 µs; write(90) 1472 µs, horn up; write(135) 1936 µs; write(180) 2400 µs, horn right; and back to write(90).
A wider pulse, a bigger angle. پانتر، گۆشەی گەورەتر.CêIT

The servo: a motor that goes to an angleماتۆڕی سێرڤۆ: ماتۆڕێک کە دەچێتە سەر گۆشەیەک

Code: move a servo to four anglesکۆد: ماتۆڕی سێرڤۆیەک بۆ چوار گۆشە ببە

The Servo library hides the pulses: attach(pin) starts them, write(angle) sets the width, and the servo holds the angle until the next write. On a servo whose full turn needs other pulse widths, give your own limits: attach(9, 500, 2400) for an SG90 that follows its data sheet.

Servo دەشارێتەوە: attach(pin) دەستیان پێ دەکات، write(angle) پاناییەکە دیاری دەکات و گۆشەکە ڕادەگرێت تا ⁦write()⁩ـی داهاتوو. لەسەر کە تەواوی سووڕانەوەکەی پانایی تری دەوێت، سنووری خۆت بدە: attach(9, 500, 2400) بۆ ⁦SG90⁩ـێک کە بەدوای دەڕوات.

Four angles, one per second (UNO, pin 9)چوار گۆشە، چرکەی یەکێک (UNO، پینی ⁦9⁩)servo_angles.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// A positional servo (SG90) on pin 9 of an UNO: four angles, one per second
#include <Servo.h>

Servo flap;                        // the servo that moves a small flap
const int angles[] = {0, 90, 180, 45};

void setup() {
  Serial.begin(9600);
  flap.attach(9);                  // default pulses: 544 us = 0°, 2400 us = 180°
}

void loop() {
  for (int i = 0; i < 4; i++) {
    flap.write(angles[i]);         // go to this angle and hold it
    Serial.print("write(");
    Serial.print(angles[i]);
    Serial.print("): pulse ");
    Serial.print(map(angles[i], 0, 180, 544, 2400));
    Serial.println(" us every 20 ms");
    delay(1000);
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 9

attach(): pulses start, 544–2400 µs for 0–180°.

⁦attach()⁩: دەست پێدەکەن، ⁦544–2400 µs⁩ بۆ ⁦0–180°⁩.

Lineدێڕی 14

write(): the servo turns to the angle and holds it.

⁦write()⁩: بۆ گۆشەکە دەسووڕێت و ڕایدەگرێت.

Lineدێڕی 18

map() shows the pulse width the library sends for each angle.

⁦map()⁩ ئەو پانایی پیشان دەدات کە بۆ هەر گۆشەیەک دەینێرێت.

A half circle with marks every 15°: 0° 544 µs at the left, 45° 1008 µs, 90° 1472 µs at the top, 135° 1936 µs and 180° 2400 µs at the right; a blue horn points at 60° with write(60) and 1163 µs. Side panel: pulse width to angle; Servo library default 544–2400 µs = 0–180°; SG90 data sheet about 0.5–2.4 ms; classic RC servos 1–2 ms; one pulse every 20 ms (50 Hz); attach(pin, min, max) fits your servo.نیوەبازنەیەک بە نیشانە لە هەر 15°ـێکدا: 0° 544 µs لە چەپ، 45° 1008 µs، 90° 1472 µs لە سەرەوە، 135° 1936 µs و 180° 2400 µs لە ڕاست؛ باسکێکی شین ئاماژە بۆ 60° دەکات بە write(60) و 1163 µs. بەشی تەنیشت: پانایی تڕپە ← گۆشە؛ بنەڕەتی کتێبخانەی Servo 544–2400 µs = 0–180°؛ پەڕەی تایبەتمەندییەکانی SG90 نزیکەی 0.5–2.4 ms؛ ماتۆڕەکانی سێرڤۆی کلاسیکی RC 1–2 ms؛ هەموو 20 ms جارێک تڕپەیەک (50 Hz)؛ attach(pin, min, max) بۆ ماتۆڕی سێرڤۆکەی خۆت ڕێکی دەخات.
Any angle from 0° to 180°, each with its own pulse width.هەر گۆشەیەک لە ⁦0°⁩ تا ⁦180°⁩، هەریەکە بە پانایی خۆی.CêIT

The servo: a motor that goes to an angleماتۆڕی سێرڤۆ: ماتۆڕێک کە دەچێتە سەر گۆشەیەک

Powering a servo, and the pins it borrowsوزەدان بە ماتۆڕی سێرڤۆ و ئەو پینانەی بە قەرز دەیانبات

One small servo such as the SG90 (4.8–5 V) can take its power from the UNO's 5V pin. Two or more, or bigger ones, need a separate 5 V supply, with its GND joined to the board's GND. One more thing to know: on the UNO R3 and other small AVR boards (not the Mega), the Servo library takes over a timer, so analogWrite() (PWM) on pins 9 and 10 stops working while servos are attached — even if no servo is on those pins. Choose other PWM pins for LEDs or motor speed.

بچووکی وەک ⁦SG90 (4.8–5 V)⁩ دەتوانێت وزەکەی لە پینی ⁦5V⁩ـی UNOـەوە وەربگرێت. دووان یان زیاتر، یان گەورەتر، ⁦5 V⁩ـی جیایان دەوێت، بە GNDـەکەی بەستراو بە GNDـی بۆردەکەوە. شتێکی تریش: لەسەر ⁦UNO R3⁩ و بۆردە بچووکەکانی تری AVR (نەک Mega)، Servo دەگرێتە دەست، بۆیە تا بەستراون analogWrite() () لەسەر پینەکانی 9 و ⁦10⁩ کار ناکات — تەنانەت ئەگەر هیچ لەسەر ئەو پینانە نەبێت. بۆ یان خێرایی پینی تر هەڵبژێرە.

Continuous-rotation servos: speed instead of angleسێرڤۆی خولانەوەی بەردەوام: خێرایی لە جیاتی گۆشە

A continuous-rotation servo looks like a positional one but spins round and round. The same pulses now set speed and direction: write(90) (about 1.5 ms) stops it; below 90 it turns one way, above 90 the other, faster the further from 90. Many have a small trim screw so that write(90) really stops them. They are sold ready-made (for example the FS90R); you do not have to modify a servo. A positional servo can be modified — the end stop removed and its position sensor fixed in the middle — but the result is the same thing: it no longer knows where it is.

وەک شوێنییەکە دەردەکەوێت بەڵام بە بەردەوامی دەخولێتەوە. هەمان ئێستا خێرایی و ئاراستە دیاری دەکەن: write(90) (نزیکەی ⁦1.5 ms⁩) ڕایدەگرێت؛ لە خوار ⁦90⁩ بە ئاراستەیەک دەسووڕێت، لە سەرووی ⁦90⁩ بە ئەوی تر، تا دوورتر لە ⁦90⁩ خێراتر. زۆربەیان بورغییەکی بچووکی ڕێکخستنیان هەیە تا بە ⁦write(90)⁩ ڕێک بوەستن. بە ئامادەیی دەفرۆشرێن (بۆ نموونە ⁦FS90R⁩)؛ پێویست ناکات دەستکاری بکەیت. شوێنی دەتوانرێت دەستکاری بکرێت — ڕێگرەکەی کۆتایی لادەبرێت و شوێنەکەی لە ناوەڕاستدا جێگیر دەکرێت — بەڵام ئەنجامەکە هەمان شتە: ئیتر نازانێت لە کوێیە.

A continuous-rotation servo: stop, slow, full speed both waysسێرڤۆی خولانەوەی بەردەوام: وەستان، هێواش، تەواوی خێرایی بە هەردوو ئاراستەcontinuous_servo.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// A continuous-rotation servo (for example an FS90R) on pin 9: speed, not angle
#include <Servo.h>

Servo wheel;

void setup() {
  Serial.begin(9600);
  wheel.attach(9);
}

void loop() {
  Serial.println("write(90): stop");
  wheel.write(90);
  delay(1000);
  Serial.println("write(70): slow, one way");
  wheel.write(70);
  delay(2000);
  Serial.println("write(0): full speed, the same way");
  wheel.write(0);
  delay(2000);
  Serial.println("write(180): full speed, the other way");
  wheel.write(180);
  delay(2000);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 13

90: stop (if the trim is set right).

⁦90⁩: وەستان (ئەگەر ڕێکخستنەکە دروست بێت).

Lineدێڕی 16

70: slowly one way.

⁦70⁩: بە هێواشی بە ئاراستەیەک.

Lineدێڕی 19-22

0 and 180: full speed in opposite directions.

0 و ⁦180⁩: تەواوی خێرایی بە دوو ئاراستەی پێچەوانە.

Two panels. Positional (standard): a servo with its horn on a half circle; write(0…180) = an angle, it holds that angle, it knows where it is, only about half a turn; for a flap or a pointer. Continuous rotation: a servo inside a full circle with an arrow; write(90) ≈ stop, below 90 one way, above 90 the other, further from 90 = faster, any number of turns but no position; to stop at a place: a limit switch, an encoder or timing.دوو بەش. شوێنی (ئاسایی): ماتۆڕی سێرڤۆیەک کە باسکەکەی لەسەر نیوەبازنەیەکە؛ write(0…180) = گۆشەیەک، لەو گۆشەیەدا دەمێنێتەوە، دەزانێت لە کوێیە، تەنیا نزیکەی نیو سووڕانەوە؛ بۆ دەرچەیەک یان نیشاندەرێک. خولانەوەی بەردەوام: ماتۆڕی سێرڤۆیەک لە ناو بازنەیەکی تەواودا بە تیرێکەوە؛ write(90) ≈ وەستان، خوار 90 بە ئاراستەیەک، سەرووی 90 بە ئەوی تر، دوورتر لە 90 = خێراتر، هەر ژمارەیەک سووڕانەوە بەڵام بێ شوێن؛ بۆ وەستان لە شوێنێک: سویچی سنوور، کۆدکەری هەنگاوبەهەنگاو یان کات.
Same pulses, different meaning: angle or speed.هەمان ، واتای جیاواز: گۆشە یان خێرایی.CêIT

Continuous-rotation servos: speed instead of angleسێرڤۆی خولانەوەی بەردەوام: خێرایی لە جیاتی گۆشە

Stopping in the right place: a limit switchوەستان لە شوێنی دروست: سویچی سنوور

A continuous servo cannot say where the cover is, so a limit switch at the end of its travel does: the moving cover presses it, the pin reads LOW (with INPUT_PULLUP), and the sketch stops the servo at once. The cage's cover needs two, one at the open end and one at the closed end.

ناتوانێت بڵێت بەرگەکە لە کوێیە، بۆیە لە کۆتایی ڕێگاکەیدا دەیڵێت: بەرگە جووڵاوەکە دەیپەستێنێت، پینەکە LOW دەخوێنێتەوە (بە INPUT_PULLUP) و یەکسەر ڕادەگرێت. بەرگی قەفەزەکە دووانی دەوێت، یەکێک لە کۆتایی کراوە و یەکێک لە کۆتایی داخراو.

Close the cover until the switch is pressedبەرگەکە دابخە تا سویچی سنوورەکە دەپەستێنرێتcover_close.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// Close a cover with a continuous servo; a limit switch says where to stop
#include <Servo.h>

Servo cover;
const int closedSwitch = 3;     // limit switch to GND: pressed = LOW
bool closing = true;

void setup() {
  Serial.begin(9600);
  pinMode(closedSwitch, INPUT_PULLUP);
  cover.attach(9);
  cover.write(70);              // turn slowly to pull the cover closed
  Serial.println("closing the cover");
}

void loop() {
  if (closing && digitalRead(closedSwitch) == LOW) {   // the end is reached
    cover.write(90);            // stop
    closing = false;
    Serial.print("switch pressed at ");
    Serial.print(millis());
    Serial.println(" ms: cover closed, servo stopped");
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 10

The switch joins pin 3 to GND when pressed: INPUT_PULLUP reads LOW.

کە پەستێنرا پینی 3 بە GNDـەوە دەبەستێت: ⁦INPUT_PULLUP LOW⁩ دەخوێنێتەوە.

Lineدێڕی 17-18

Pressed while closing: write(90) stops the servo.

لە کاتی داخستندا پەستێنرا: ⁦write(90)⁩ ڕادەگرێت.

A purple moving part pushes towards a black limit switch with a lever and a roller; the switch has three gold pins. Caption: pressed, the board stops the motor.بەشێکی مۆری جووڵاو بەرەو سویچی سنوورێکی ڕەش بە باسک و خڕۆکەیەکەوە پاڵ دەنێت؛ سویچەکە سێ پینی زێڕینی هەیە. ڕوونکردنەوە: پەستێنرا، بۆردەکە ماتۆڕەکە ڕادەگرێت.
The cover itself tells the board it has arrived.خودی بەرگەکە بە بۆردەکە دەڵێت گەیشتووە.CêIT

Choosing a motor for the cage coverهەڵبژاردنی ماتۆڕێک بۆ بەرگی قەفەزەکە

The cover hangs from a rail and is pulled by a string around a pulley. Four candidates, compared:

بەرگەکە لە ڕێڕەوێکەوە هەڵواسراوە و بە پەتێک بە دەوری دەکێشرێت. چوار هەڵبژاردە، بەراورد کراون:

MotorGoodباشWatch outئاگادار بە
positional servo شوێنیsimple; knows its angleسادە؛ گۆشەکەی دەزانێتonly about half a turn: fine for a flap, too short for a long stringتەنیا نزیکەی نیو سووڕانەوە: بۆ دەرچەیەک باشە، بۆ پەتێکی درێژ کورتە
continuous servocheap, simple, no driver neededهەرزان، سادە، ناوێتno position: needs two limit switchesبێ شوێن: پێویستی بە دوو هەیە
DC gear motor + encoder + driver گێڕدار + + knows distance and speed; strongدووری و خێرایی دەزانێت؛ بەهێزmost parts and code; still needs a home switchزۆرترین پارچە و کۆد؛ هێشتا سویچێکی سەرەتای دەوێت
stepper motor + driver + exact steps without an encoderهەنگاوی ورد بەبێ draws current even when still; can skip steps if overloadedتەنانەت لە کاتی وەستانیشدا دەکێشێت؛ ئەگەر بارگرانی لەسەر بێت دەتوانێت هەنگاو بپەڕێنێت

For a student build, a continuous servo with two limit switches is the simplest reliable choice; a DC gear motor with an encoder gives the most control, as the project report suggests. Either way, wait until it has been dark (or light) for some minutes before moving, so a cloud cannot fool the cover (No flicker at dusk). The whole design comes together in the project, in Closing and opening the cover.

بۆ دروستکردنێکی قوتابی، بە دوو سادەترین هەڵبژاردەی جێی متمانەیە؛ گێڕدار بە زۆرترین کۆنترۆڵ دەدات، وەک ڕاپۆرتی پڕۆژەکە پێشنیاری دەکات. بە هەر شێوەیەک، پێش جووڵاندن چاوەڕێ بکە تا چەند خولەکێک تاریک (یان ڕووناک) بێت، تا هەورێک نەتوانێت بەرگەکە هەڵبخەڵەتێنێت (بێ لەرزین لە ئێوارەدا). هەموو دیزاینەکە لە پڕۆژەکەدا کۆ دەبێتەوە، لە داخستن و کردنەوەی بەرگەکە.

Side view of a bird cage with a purple cover hanging from a rail; a string runs around two pulleys, and a small motor drives the left pulley; the cover's edge is tied to the string and an arrow shows it moving right. Two black limit switches sit on the rail, at the open end and at the closed end. Notes: two limit switches mark the ends; low voltage only, a 5–6 V motor; dark for a while, turn clockwise until the closed-end switch, stop.دیمەنی لاوەی قەفەزێکی باڵندە بە بەرگێکی مۆر کە لە ڕێڕەوێکەوە هەڵواسراوە؛ پەتێک بە دەوری دوو خلۆکەدا دەڕوات و ماتۆڕێکی بچووک خلۆکەی چەپ دەسووڕێنێت؛ لێواری بەرگەکە بە پەتەکەوە بەستراوە و تیرێک پیشان دەدات بەرەو ڕاست دەجووڵێت. دوو سویچی سنووری ڕەش لەسەر ڕێڕەوەکەن، لە کۆتایی کراوە و لە کۆتایی داخراو. تێبینی: دوو سویچی سنوور کۆتاییەکان دیاری دەکەن؛ تەنیا ڤۆڵتیەی نزم، ماتۆڕێکی 5–6 V؛ ماوەیەک تاریکە، میل‌سووڕی بسووڕێنە تا سویچی کۆتایی داخراو، بوەستە.
Motor, pulley, string, cover — and a switch at each end.، ، پەت، بەرگ — و سویچێک لە هەر کۆتاییەک.CêIT

Common mistakesهەڵە باوەکان

MistakeهەڵەBetterباشتر
A motor straight on a pin. ڕاستەوخۆ لەسەر پینێک.A motor driver and the motor's own supply. و خودی .
The motor supply and the board with separate grounds. و بۆرد بە زەویی جیا.Join the GNDs.GNDـەکان پێکەوە ببەستە.
Expecting the encoder to set the direction.چاوەڕوانیی ئەوە کە ئاراستە دیاری بکات.The driver sets it; the encoder measures. دیاری دەکات؛ دەپێوێت.
Believing a positional servo only goes to 0°, 90° and 180°.باوەڕکردن بەوەی شوێنی تەنیا دەچێتە سەر ⁦0°⁩، ⁦90°⁩ و ⁦180°⁩.Any angle: write(37) works.هەر گۆشەیەک: ⁦write(37)⁩ کار دەکات.
Modifying a servo to make it spin.دەستکاریکردنی بۆ ئەوەی بخولێتەوە.Buy a continuous-rotation servo. بکڕە.
A continuous servo stopped by timing alone. کە تەنیا بە کات ڕادەگیرێت.Limit switches (or an encoder) at the ends. (یان ) لە کۆتاییەکاندا.
analogWrite() on pins 9 or 10 while a servo is attached.⁦analogWrite()⁩ لەسەر پینی 9 یان ⁦10⁩ لە کاتێکدا بەستراوە.Use other PWM pins (UNO: 3, 5, 6, 11).پینی تر بەکار بهێنە (⁦UNO: 3⁩، 5، 6، ⁦11⁩).
Several servos on the board's 5V pin.چەند لەسەر پینی ⁦5V⁩ـی بۆرد.A separate 5 V supply, grounds joined. ⁦5 V⁩ـی جیا، زەوییەکان بەستراو.
A mains heater wired to the board.گەرمکەرەوەیەکی کارەبای ماڵ بەستراو بە بۆردەوە.Never: a certified device; LEDs stand in.هەرگیز: ئامێرێکی بڕوانامەدار؛ جێیان دەگرنەوە.

Exercisesڕاهێنانەکان

ExerciseڕاهێنانA pulse widthپانایی تڕپەیەک

With the Servo library's default limits, how long is the pulse for write(120)?

بە سنوورە بنەڕەتییەکانی Servo، ⁦write(120)⁩ چەند درێژە؟

Show answerوەڵامەکە پیشان بدە
544+120×2400−544180=544+1237.3≈1781 μs≈1.78 ms544 + 120 \times \frac{2400 - 544}{180} = 544 + 1237.3 \approx 1781\,\mu\text{s} \approx 1.78\,\text{ms}
ExerciseڕاهێنانHow many pulses?چەند تڕپە؟

The cover's string winds on a pulley 3 cm across. The encoder gives 20 pulses per turn of the output shaft. How many pulses move the cover 60 cm?

پەتی بەرگەکە بە دەوری ⁦3 cm⁩ پاندا دەپێچرێتەوە. بۆ هەر سووڕانەوەیەکی تەوەرەی دەرچوون ⁦20⁩ دەدات. چەند بەرگەکە ⁦60 cm⁩ دەجووڵێنێت؟

Hintئاماژە

One turn of the pulley moves the string by its circumference, π × diameter.

یەک سووڕانەوەی پەتەکە بەقەدەر چێوەکەی دەجووڵێنێت، π × تیرە.

Show answerوەڵامەکە پیشان بدە
one turn=π×3 cm≈9.42 cmturns=60÷9.42≈6.37pulses=6.37×20≈127\begin{aligned} \text{one turn} &= \pi \times 3\,\text{cm} \approx 9.42\,\text{cm} \\ \text{turns} &= 60 \div 9.42 \approx 6.37 \\ \text{pulses} &= 6.37 \times 20 \approx 127 \end{aligned}
ExerciseڕاهێنانBrake or coast?ڕاگرتن یان بەرەڵاکردن؟

With a TB6612FNG, what is the difference between IN1 = IN2 = HIGH and IN1 = IN2 = LOW? Which would you use to stop the cover exactly at a limit switch?

لەگەڵ ⁦TB6612FNG⁩، جیاوازیی ⁦IN1 = IN2 = HIGH⁩ و ⁦IN1 = IN2 = LOW⁩ چییە؟ کامیان بەکار دەهێنیت بۆ ڕاگرتنی بەرگەکە ڕێک لە ؟

Show answerوەڵامەکە پیشان بدە

Both HIGH is a short brake: the motor's ends are joined and it stops fast. Both LOW lets the motor go, and it coasts on. At a limit switch, brake.

هەردووکیان HIGH ڕاگرتنی خێرایە: دوو سەری پێکەوە دەبەسترێن و بە خێرایی دەوەستێت. هەردووکیان LOW بەرەڵا دەکات و بە خۆی بەردەوام دەبێت. لە ، ڕایبگرە.

ExerciseڕاهێنانClose, wait, openداخستن، چاوەڕوانی، کردنەوە

Extend the limit-switch sketch: close the cover until the switch on pin 3, wait 2 s, then open it until a second switch on pin 4.

درێژ بکەرەوە: بەرگەکە دابخە تا سویچی پینی 3، 2 چرکە چاوەڕێ بکە، پاشان بیکەرەوە تا سویچێکی دووەم لەسەر پینی 4.

Hintئاماژە

Use a variable for the step and millis() for the wait, so loop() keeps checking the switches.

بۆ هەنگاوەکە و ⁦millis()⁩ بۆ چاوەڕوانییەکە بەکار بهێنە، تا ⁦loop()⁩ بەردەوام سویچەکان بپشکنێت.

Show answerوەڵامەکە پیشان بدە
Answer: a small state machineوەڵام: ئامێرێکی دۆخی بچووکcover_close_open.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// Close the cover, wait, then open it again: one limit switch at each end
#include <Servo.h>

Servo cover;                    // a continuous-rotation servo
const int closedSwitch = 3;     // pressed = LOW (INPUT_PULLUP)
const int openSwitch = 4;       // pressed = LOW (INPUT_PULLUP)
int state = 0;                  // 0 closing, 1 waiting, 2 opening, 3 done
unsigned long waitStart = 0;

void setup() {
  Serial.begin(9600);
  pinMode(closedSwitch, INPUT_PULLUP);
  pinMode(openSwitch, INPUT_PULLUP);
  cover.attach(9);
  cover.write(70);              // one way: closing
  Serial.println("closing");
}

void loop() {
  if (state == 0 && digitalRead(closedSwitch) == LOW) {
    cover.write(90);            // stop
    state = 1;
    waitStart = millis();
    Serial.println("closed: waiting 2 s");
  } else if (state == 1 && millis() - waitStart >= 2000) {
    cover.write(110);           // the other way: opening
    state = 2;
    Serial.println("opening");
  } else if (state == 2 && digitalRead(openSwitch) == LOW) {
    cover.write(90);            // stop
    state = 3;
    Serial.println("open: stopped");
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

0 closing, 1 waiting, 2 opening, 3 done: one variable remembers the step.

0 داخستن، 1 چاوەڕوانی، 2 کردنەوە، 3 تەواو: یەک هەنگاوەکە لەبیر دەکات.

Summaryپوختە

  • Actuators turn commands into action: motors, pumps, relays, buzzers, LEDs. Mains loads never connect to a board.
  • A DC motor turns while current flows, reverses when the current reverses, and needs a motor driver (an H-bridge) and its own supply — never a pin.
  • An incremental encoder measures how far, how fast and which way; the driver sets direction and speed. Together they close the loop.
  • A positional servo goes to any angle (about 0–180°), set by a pulse every 20 ms: Servo library 544–2400 µs, SG90 about 0.5–2.4 ms.
  • A continuous-rotation servo (sold ready-made) turns speed and direction from the same pulses, write(90) ≈ stop, but it needs limit switches to know where it is.
  • فەرمان دەکەن بە کار: ، پەمپ، ، ، . بارەکانی کارەبای ماڵ هەرگیز بە بۆردەوە نابەسترێن.
  • تا هەبێت دەسووڕێت، کە پێچەوانە بوو پێچەوانە دەبێتەوە و پێویستی بە () و خۆی هەیە — هەرگیز پین نا.
  • دەپێوێت چەند، چەند خێرا و بە کام ئاراستەدا؛ ئاراستە و خێرایی دیاری دەکات. پێکەوە خولەکە دادەخەن.
  • شوێنی دەچێتە سەر هەر گۆشەیەک (نزیکەی ⁦0–180°⁩)، کە هەموو ⁦20 ms⁩ دیاری دەکات: ⁦Servo 544–2400 µs⁩، ⁦SG90⁩ نزیکەی ⁦0.5–2.4 ms⁩.
  • (بە ئامادەیی دەفرۆشرێت) لە هەمان خێرایی و ئاراستە وەردەگرێت، ⁦write(90)⁩ ≈ وەستان، بەڵام بۆ زانینی شوێنی خۆی پێویستی بە هەیە.
Review questionsپرسیارەکانی پێداچوونەوە
Why can a board not run a motor from a pin?بۆچی بۆرد ناتوانێت ماتۆڕێک لە پینێکەوە بجووڵێنێت؟

A pin gives 7–20 mA; even a small motor wants about 150 mA running and over 1 A when blocked, and its coil kicks back voltage spikes.

پینێک ⁦7–20 mA⁩ دەدات؛ تەنانەت بچووک لە کاردا نزیکەی ⁦150 mA⁩ و کاتێک دەگیرێت زیاتر لە ⁦1 A⁩ـی دەوێت و پێچەکەی بەرز دەداتەوە.

What is the difference between a positional and a continuous-rotation servo?جیاوازیی نێوان ماتۆڕی سێرڤۆی شوێنی و سێرڤۆی خولانەوەی بەردەوام چییە؟

The same pulse means an angle to the first and a speed and direction to the second; only the positional servo knows where it is.

هەمان بۆ یەکەمیان واتای گۆشەیەک دەدات و بۆ دووەمیان خێرایی و ئاراستە؛ تەنیا شوێنی دەزانێت لە کوێیە.

Which motor would you choose for the cage cover?کام ماتۆڕ بۆ بەرگی قەفەزەکە هەڵدەبژێریت؟

A continuous servo with two limit switches for a simple build, or a DC gear motor with an encoder, a driver and a home switch for the most control.

بە دوو بۆ دروستکردنێکی سادە، یان گێڕدار بە ، و سویچێکی سەرەتاوە بۆ زۆرترین کۆنترۆڵ.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

From Smoke Signals to Device-to-Cloudلە نیشانەی دووکەڵەوە تا پەیوەندیی ئامێر بۆ هەور

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.

Appearanceڕووکار

Modeدۆخ
Styleشێواز
Coloursڕەنگەکان

Saved on this device only.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.