הפרויקט הכי "רובוטי" עד כה: 4 מנועי סרוו ותושבות מתכת הופכים לזרוע עם 4 מפרקים. נלמד מה זה סרוו לעומק, איך מזינים אותו בכוח בלי לשרוף כלום, נבנה את הזרוע — ונלמד אותה לזוז. The most "robot" project yet: 4 servo motors and metal brackets become a 4-joint arm. We'll learn what a servo really is, how to power it without frying anything, build the arm — and teach it to move.
ניווט: חצים ← → במקלדת, או הכפתורים למטה · לחצו EN לבדיקת מונחים באנגלית Navigate: ← → arrow keys, or the buttons below · press עב for Hebrew
הכללים קודם; ההסברים מגיעים בהמשך השיעור. אם זוכרים רק שקופית אחת — שתהיה זו.Rules first; the reasons come later in the lesson. If you remember only one slide — make it this one.
מנוע רגיל (כמו במכונית) יודע רק להסתובב — מהר, לאט, קדימה, אחורה. הוא לא יודע איפה הוא נמצא. סרוו הוא חיה אחרת: אתם אומרים לו זווית (נניח 90°), והוא הולך לשם ונשאר שם. A plain motor (like in the car) only knows how to spin — fast, slow, forward, back. It has no idea where it is. A servo is a different animal: you tell it an angle (say 90°) and it goes there and stays there.
הסוד: בתוך הקופסה הקטנה יש ארבעה דברים יחד —The secret: inside that little box there are four things together —
גררו את הזווית — הסרוו "הולך" לשם:Drag the angle — the servo "goes" there:
| צבעColor | תפקידRole |
|---|---|
| חום / שחורBrown / black | GND (−) |
| אדוםRed | כוחPower V+ (5–6V) |
| כתום / צהובOrange / yellow | אות (Signal) — מהארדואינוSignal — from the Arduino |
הכוח לא בא מפין האות. האות הוא רק הוראה דקה: פעימה חשמלית שחוזרת כל 20 מילישניות (50 פעמים בשנייה). אורך הפעימה הוא הזווית: Power does not come from the signal pin. The signal is just a thin instruction: a pulse that repeats every 20 ms (50 times a second). The pulse's length is the angle:
גררו את אורך הפעימה — וראו את הזווית:Drag the pulse length — and watch the angle:
כל כמה מילישניות הסרוו עושה את אותו דבר:Every few milliseconds the servo does the same thing:
זו "בקרת משוב" (closed-loop). בגלל זה:That's closed-loop control. Because of it:
| מנוע DC (המכונית)DC motor (the car) | Servo | |
|---|---|---|
| מה שולטיםYou control | מהירות/כיווןspeed/direction | זוויתangle |
| יודע איפה הוא?Knows where it is? | לאNo | כןYes |
| צריך מגשר (L298N)?Needs an H-bridge? | כןYes | לאNo |
| מחזיק מקום?Holds position? | לאNo | כןYes |
לכן לזרוע צריך סרוו: מפרק חייב להגיע לזווית מדויקת ולהישאר שם תחת משקל.So an arm needs servos: a joint must reach a precise angle and stay there under weight.
כוח של סרוו נמדד בק"ג·ס"מ (מומנט). ה-RDS3115 נותן ~15 ק"ג·ס"מ ב-6V. פירושו: הוא יכול להחזיק 15 ק"ג במרחק 1 ס"מ מהציר — אבל רק ~1 ק"ג במרחק 15 ס"מ. A servo's strength is measured in kg·cm (torque). The RDS3115 gives ~15 kg·cm at 6V. Meaning: it can hold 15 kg at 1 cm from the shaft — but only ~1 kg at 15 cm.
זה למה הזרוע היותר ארוכה = יותר חלשה בקצה. מפרק הכתף (שנושא את כל השאר) עובד הכי קשה. That's why a longer arm = weaker at the tip. The shoulder joint (carrying everything else) works hardest.
שלנו: דיגיטלי (אחיזה חזקה ומדויקת) + MG (Metal Gear — גלגלי מתכת עמידים).Ours: digital (strong, precise holding) + MG (Metal Gear — durable metal gears).
גררו את המרחק מהציר — וראו כמה אפשר להרים:Drag the distance from the shaft — see how much it can lift:
15 kg·cm ÷ מרחקdistance
ספריית Servo כבר מגיעה עם ה-IDE. שלושה דברים זה כל הסיפור: The Servo library already ships with the IDE. Three things are the whole story:
הסקצ' הקלאסי להתחלה — "Sweep": הסרוו מטייל 0→180 וחזרה. אם זה עובד — החיווט והכוח תקינים, ואפשר לבנות. The classic starter — "Sweep": the servo travels 0→180 and back. If it works, your wiring and power are good and you can start building.
#include <Servo.h>
Servo joint; // controls one servo
const int SERVO_PIN = 9;
void setup() {
joint.attach(SERVO_PIN);
}
void loop() {
for (int a=0; a<=180; a++){ // 0 -> 180
joint.write(a);
delay(15);
}
for (int a=180; a>=0; a--){ // back
joint.write(a);
delay(15);
}
}📄 code/level1_servo_sweep.ino · ואז level2_servo_serial.ino — הקלידו זווית ב-Serial.📄 code/level1_servo_sweep.ino · then level2_servo_serial.ino — type an angle in Serial.
סרוו אחד מסוג RDS3115 יכול למשוך ~2.5 אמפר כשהוא נאבק בעומס. ארבעה ביחד — עד ~10 אמפר לרגע. כבל ה-USB נותן בערך 0.5 אמפר, והמייצב של הארדואינו עוד פחות. One RDS3115 can pull ~2.5 A when fighting a load. Four together — up to ~10 A for a moment. A USB cable gives about 0.5 A, and the Arduino's regulator even less.
לכל תלמיד: 4 סרוו, כמה תושבות אלומיניום (U/L), דיסקיות (horns) וברגים. התכלת־המתכת שבתמונה הן ה"שלד" של הזרוע. Per student: 4 servos, a few aluminum brackets (U/L), horns (disks) and screws. The metal brackets in the photo are the arm's "skeleton".
תושבת ה-U "עוטפת" סרוו ומחברת אותו לחלק הבא. כך כל סרוו הופך למפרק מסתובב: הגוף של הסרוו קבוע לחלק אחד, והדיסקית (שמסתובבת עם הציר) מחוברת לחלק השני. כשהציר מסתובב — המפרק מתכופף. The U-bracket "wraps" a servo and links it to the next part. That turns each servo into a rotating joint: the servo body is fixed to one part, and the horn (which turns with the shaft) is fixed to the next. When the shaft turns — the joint bends.
סרוו + תושבת = מפרק אחד. ארבעה כאלה = זרוע.servo + bracket = one joint. Four of them = an arm.
לפני שמחברים דיסקית לסרוו — מריצים קוד שמעמיד את כל הסרוו ב-90°. רק אז מרכיבים, כשהמפרק ב"אמצע". Before attaching a horn — run code that sets every servo to 90°. Only then assemble, with the joint at its "middle".
למה? אם תרכיבו מפרק בקצה הטווח, תקבלו תנועה רק לכיוון אחד. מ-90° יש לכם ±90° לכל צד. Why? If you assemble a joint at the end of its range, you only get motion one way. From 90° you have ±90° each way.
#include <Servo.h>
const int PINS[] = {3,5,6,9};
const int N = 4;
Servo servos[N];
void setup() {
for (int i=0; i<N; i++){
servos[i].attach(PINS[i]);
servos[i].write(90); // middle
}
}
void loop() { } // just hold 90📄 code/level1_center_all.ino📄 code/level1_center_all.ino
זרוע עם 4 מפרקים (4 DOF — דרגות חופש). מרכיבים מהבסיס כלפי מעלה, כל סרוו נושא את אלה שמעליו: A 4-joint arm (4 DOF — degrees of freedom). Build from the base up; each servo carries the ones above it:
4 DOF: בסיס · כתף · מרפק · תפסן4 DOF: base · shoulder · elbow · gripper
לספריית Servo לא אכפת מאיזה פין — כל פין דיגיטלי מתאים. נשאיר את D0/D1 פנויים ל-Serial, ונבחר ארבעה פינים נוחים בשילד. The Servo library doesn't care which pin — any digital pin works. We keep D0/D1 free for Serial and pick four convenient pins on the shield.
| מפרקJoint | Signal |
|---|---|
| base | D3 |
| shoulder | D5 |
| elbow | D6 |
| gripper | D9 |
גררו את ארבעת המחוונים — וראו את הזרוע זזה:Drag the four sliders — and watch the arm move:
בקוד: פקודה אחת למפרק — "<מפרק> <זווית>". דוגמה: 1 120 = כתף ל-120°. In code: one command per joint — "<joint> <angle>". Example: 1 120 = shoulder to 120°.
הזרוע בנויה וכל מפרק נשמע לנו. עכשיו: תנועה חלקה, דרכים נוחות "להניח" תנוחה, ולשמור רצף תנוחות שהזרוע תשחזר לבד — הרם-והנח. The arm is built and every joint obeys. Now: smooth motion, easy ways to "pose" it, and saving a sequence of poses the arm replays on its own — pick-and-place.
תזכורת משיעור 3: מפרידים בין "מה לעשות" ל"איך הפקודה מגיעה". חוזר גם כאן.Recall from Lesson 3: separate "what to do" from "how the command arrives". It returns here too.
write(150) אומר לסרוו "לך ל-150° עכשיו" — והוא קופץ לשם הכי מהר שהוא יכול. זה מכביד על גלגלי השיניים, מושך זרם גדול, ונראה קופצני. write(150) tells the servo "go to 150° now" — and it snaps there as fast as it can. That stresses the gears, pulls a big current, and looks jerky.
במקום זה: מתקדמים מעלה-מעלה בצעד קטן, עם delay זעיר בין צעד לצעד. זה "מחליק" את התנועה. Instead: step one degree at a time with a tiny delay between steps. That "glides".
void moveTo(int target, int stepDelay){
while (current != target){
current += (target > current) ? 1 : -1;
joint.write(current);
delay(stepDelay); // bigger = slower
}
}אותה תנועה — פעם בקפיצה, פעם חלק:Same move — once as a jump, once smooth:
הדרך הכי טבעית למצוא תנוחה טובה — ביד. פוטנציומטר אחד לכל מפרק: מסובבים כפתור, המפרק עוקב. ממש כמו בשיעור 5, ה-map() ממיר 0–1023 ל-0–180. The most natural way to find a good pose — by feel. One pot per joint: turn a knob, the joint follows. Just like Lesson 5, map() converts 0–1023 to 0–180.
int raw = analogRead(A0); // 0..1023
int angle = map(raw, 0,1023, 0,180);
servo.write(angle);מי שסיים את הבנייה ואת השליטה הידנית — בונה את ה-pendant, מוצא 4–6 תנוחות ל"הרם-והנח", ורושם אותן. הן יהיו ה"הקלטה" בשקופית הבאה. If you've finished the build and manual control — wire the pendant, find 4–6 poses for a pick-and-place, and write them down. They become the "recording" on the next slide.
תנוחה = הזוויות של כל 4 המפרקים ברגע אחד: {base, shoulder, elbow, gripper}. שומרים כמה תנוחות במערך, והזרוע עוברת ביניהן בחלקות — וזה הרם-והנח. A pose = the angles of all 4 joints at one moment: {base, shoulder, elbow, gripper}. Store several poses in an array and the arm glides between them — that's pick-and-place.
int POSES[][4] = {
{ 90, 90, 90, 20}, // home, open
{ 90, 60, 40, 20}, // reach down
{ 90, 60, 40, 80}, // grab
{ 90, 90, 90, 80}, // lift
{160, 90, 90, 80}, // rotate
{160, 60, 40, 20}, // lower & release
};הקסם משיעור 3 חוזר: פונקציות התנועה נשארות אותו דבר — רק מקור הפקודה מתחלף. אותה פקודת "<מפרק> <זווית>", עכשיו דרך Bluetooth. The Lesson-3 magic returns: the motion code stays the same — only the command's source changes. The same "<joint> <angle>", now over Bluetooth.
// over USB (Lesson 6, level 3):
int j = Serial.parseInt();
int a = Serial.parseInt();
servos[j].write(a);
// over Bluetooth - only the source changed:
int j = bt.parseInt();
int a = bt.parseInt();
servos[j].write(a);| תופעהSymptom | סיבה סבירהLikely cause |
|---|---|
| הארדואינו מתאתחלArduino resets | נפילת מתח — צריך ספק חזק יותרbrown-out — need a stronger supply |
| סרוו רועד/משתגעServo jitters/wild | אין גראונד משותףno common ground |
| זז הפוך / חצי טווחMoves backward / half range | לא אופס ל-90° לפני ההרכבהnot centered to 90° before assembly |
| חלש / "מוותר"Weak / "gives up" | עומס רחוק מדי מהציר (מומנט)load too far from shaft (torque) |
סרוו הוא מנוע שיודע איפה הוא ומחזיק זווית. זרוע היא בסך הכול כמה סרוו מתואמים — ותנוחה היא רשימת זוויות. כל השאר זה כוח נכון, גראונד משותף, ותיאום בקוד. A servo is a motor that knows where it is and holds an angle. An arm is just a few coordinated servos — and a pose is a list of angles. The rest is proper power, a common ground, and coordination in code.
💻 כל קבצי הקוד של השיעור — הורדה והסברAll of this lesson's code — download & walkthrough
כל הכבוד — בניתם רובוט אמיתי! 🦾 נתראה בשיעור הבא 👋Well done — you built a real robot! 🦾 See you next lesson 👋