Robotika ● שיעור 4Lesson 4
→ חזרה← Back
קורס ארדואינו · מפגש 4Arduino course · Session 4

Bluetooth
המכונית מדברת
Bluetooth
the car talks

היום נחבר למכונית מודול Bluetooth, נשלח לה פקודות מהמחשב — והיא גם תענה לנו. נגלה שבלוטות' הוא בעצם כבל סיריאלי בלי חוט. Today we add a Bluetooth module to the car, send it commands from the computer — and it will answer back. We'll find out that Bluetooth is really a serial cable without the wire.

HC-05 — מה זה ואיך מחבריםwhat it is, how to wire it
F B L R S — פקודות מהמחשבcommands from the computer
D=23 — המכונית מדווחת חזרהthe car reports back

ניווט: חצים ← → במקלדת, או הכפתורים למטה · לחצו EN לבדיקת מונחים באנגלית Navigate: ← → arrow keys, or the buttons below · press עב for Hebrew

2מה נעשה היוםWhat we'll do today

הרעיון הגדולThe big idea

  • את Serial אתם כבר מכירים — Serial.println() שולח טקסט למחשב בכבלYou already know Serial — Serial.println() sends text to the computer over the cable
  • מודול ה-Bluetooth פשוט מחליף את הכבל. הקוד כמעט לא משתנהThe Bluetooth module simply replaces the cable. The code barely changes
  • ממציאים "שפה" קטנה בין המחשב למכונית: אות אחת = פקודה אחתWe invent a tiny "language" between computer and car: one letter = one command

הבנייה — בשלביםThe build — in levels

  • שלב 1: "שלום" דרך Bluetooth — המכונית מחזירה כל מה שכותביםLevel 1: "hello" over Bluetooth — the car echoes whatever you type
  • שלב 2: פקודות — מדליקים ומכבים LEDLevel 2: commands — turn an LED on and off
  • שלב 3: נוהגים במכונית מהמחשב (+ חיישן שמונע התנגשות)Level 3: drive the car from the computer (+ a sensor that prevents crashes)
  • שלב 3ב (אופציה): נוהגים מהטלפון עם אפליקציית Dabble (אנדרואיד)Level 3b (option): drive from the phone with the Dabble app (Android)
  • שלב 4: טלמטריה — המכונית מדווחת מרחק ומהירותLevel 4: telemetry — the car reports distance and speed
  • בונוס: נותנים למודול שם משלוBonus: give the module its own name
מי שמרגיש בטוח — ממשיך בקצב שלו עד שלב 4 והבונוס. כל השאר — עובדים יחד איתי על שלבים 1–3, לאט ולעומק.If you feel confident — go at your own pace up to Level 4 and the bonus. Everyone else — we work through Levels 1–3 together, slowly and in depth.

3מה בעצם עובר בכבל?What actually travels on the wire?

  • תקשורת סיריאלית = שני חוטים: TX (שולח) ו-RX (מקבל)Serial communication = two wires: TX (transmit) and RX (receive)
  • כל תו הוא בעצם מספר (קוד ASCII): 'F' = 70Every character is really a number (ASCII code): 'F' = 70
  • המספר נשלח כ-8 ביטים (0/1), אחד אחרי השניThe number is sent as 8 bits (0/1), one after the other
  • 9600 = ביטים לשנייה — בערך 960 תווים בשנייה. שני הצדדים חייבים להסכים על המהירות9600 = bits per second — about 960 characters a second. Both sides must agree on the speed
⚠️ כשלוחצים Enter, ה-Serial Monitor מוסיף תווים נסתרים: \n (שורה חדשה) ולפעמים גם \r. הם מגיעים לארדואינו כמו כל תו אחר — ונצטרך להתעלם מהם.⚠️ When you press Enter, the Serial Monitor adds hidden characters: \n (new line) and sometimes \r. They reach the Arduino like any other character — and we'll need to ignore them.

נסו: מה נשלח כשמקלידים?Try it: what gets sent when you type?

4Bluetooth = כבל סיריאלי בלי חוטBluetooth = a serial cable without the wire

USB cable Arduino TX / RX Computer Bluetooth Arduino TX/RX HC-05 Computer Serial.println("hi"); ← same code
  • מבחינת הארדואינו — אין הבדל. אותו Serial.print, אותו Serial.readFor the Arduino there is no difference. Same Serial.print, same Serial.read
  • מבחינת המחשב — המודול מופיע כעוד פורט COM, בדיוק כמו הארדואינו בכבלFor the computer — the module shows up as another COM port, just like the Arduino on the cable
  • טווח: בערך 10 מטר בחדר פתוחRange: roughly 10 meters in an open room

HC-05 או HC-06?HC-05 or HC-06?

שניהם עובדים היום באותה צורה. ל-HC-05 יש 6 רגליים וכפתור קטן, ל-HC-06 בדרך כלל 4 רגליים.Both work the same way today. The HC-05 has 6 pins and a small button; the HC-06 usually has 4 pins.

📱 אייפון לא יכול להתחבר ל-HC-05. המודול משתמש ב-Bluetooth "קלאסי", ואייפון מתחבר רק למודולים מסוג BLE. לכן היום עובדים מהמחשב (או מטלפון אנדרואיד).📱 iPhones can't connect to an HC-05. The module uses "Classic" Bluetooth, and iPhones only connect to BLE modules. So today we work from the computer (or an Android phone).

5איך ניגשים לרכיב חדש — 5 שאלותHow to approach a new part — 5 questions

זו השיטה לכל רכיב, בכל שיעור. היום נענה עליה יחד עבור ה-HC-05 — והשלבים של השיעור הם בדיוק התשובות.This is the method for every part, every lesson. Today we answer it together for the HC-05 — and the lesson's levels are exactly the answers.

1
מה הוא צריך לעשות? (משפט אחד)What should it do? (one sentence)
להעביר אותיות בין המחשב לארדואינו — בלי כבל.Carry letters between the computer and the Arduino — without a cable.
2
מה נכנס ומה יוצא?What goes in, what comes out?
נכנס: פקודות מהמחשב. יוצא: תשובות ונתונים מהמכונית.In: commands from the computer. Out: answers and data from the car.
3
אילו רגליים? מתח, אדמה, אותWhich pins? Power, ground, signal
מתח: VCC, אדמה: GND, אות: TXD ו-RXD (מוצלבים!).Power: VCC, ground: GND, signal: TXD and RXD (crossed!).
4
בודקים אותו לבד — בלי מנועים, בלי חיישניםTest it alone — no motors, no sensors
← שלב 1 (החזרת טקסט) ושלב 2 (LED)→ Level 1 (echo) and Level 2 (LED)
5
מחברים לשאר, צעד אחד בכל פעםCombine with the rest, one step at a time
← שלב 3 (מנועים), ואז שלב 4 (חיישן + דיווח)→ Level 3 (motors), then Level 4 (sensor + reports)
כשמשהו לא עובד — חוזרים שלב אחורה. אם שלב 1 לא עובד, אין טעם לחבר מנועים.When something doesn't work — go back one step. If Level 1 doesn't work, there's no point wiring motors.

6הכירו את ה-HC-05Meet the HC-05

רגלPinמה היא עושהWhat it doesהיום?Today?
VCCמתח 5V5V power✓
GNDאדמהGround✓
TXDהמודול שולח ← לארדואינוModule sends → to Arduino✓
RXDהמודול מקבל ← מהארדואינו (3.3V!)Module receives ← from Arduino (3.3V!)✓
STATEHIGH כשיש חיבורHIGH while connected—
EN / KEYכניסה למצב הגדרות (AT)Enter settings (AT) modeבונוסbonus

הנורה מספרת מה קורהThe LED tells you what's going on

שימו לב: "מחובר" קורה רק כשפותחים את הפורט (למשל ב-Serial Monitor) — לא ברגע הצימוד בהגדרות המחשב.Note: "connected" only happens when you open the port (e.g. in the Serial Monitor) — not at the moment you pair in the computer's settings.

7החיווט — ומפל מתח קטןWiring — and a small voltage divider

Arduino 5V GND D0 (RX) D1 (TX) HC-05 VCC GND TXD RXD TXD → RX 1kΩ 2kΩ GND ~3.3V
  • מצליבים: מי ששולח מתחבר למי שמקבל. TXD של המודול ← RX (D0) של הארדואינו, ו-TX (D1) ← RXDCross them: whoever talks connects to whoever listens. Module TXD → Arduino RX (D0), and TX (D1) → RXD
  • מפל מתח: הרגל RXD של המודול עובדת ב-3.3V, והארדואינו שולח 5V. שני נגדים (1k ו-2k) מורידים את המתח לכ-3.3VVoltage divider: the module's RXD works at 3.3V and the Arduino sends 5V. Two resistors (1k and 2k) bring it down to about 3.3V
  • בלי נגד 2k? שני נגדים של 1k בטור עושים אותו דברNo 2k resistor? Two 1k resistors in series do the same job
⚠️ D0/D1 הם גם פיני ההעלאה מה-USB. לפני כל Upload — מנתקים את שני חוטי הנתונים של המודול. אחרי ההעלאה — מחברים בחזרה. (שכחתם? תקבלו שגיאת not in sync.)⚠️ D0/D1 are also the USB upload pins. Before every Upload — unplug the module's two data wires. After the upload — plug them back. (Forgot? You'll get a not in sync error.)

8שלב 1: "שלום" — קודם בכבל, אחר כך באווירLevel 1: "hello" — first on the cable, then over the air

הקוד מחזיר כל תו שהוא מקבל, יחד עם המספר שלו. אין בו שום דבר של Bluetooth — רק Serial.The code sends back every character it gets, with its number. There's nothing Bluetooth in it — just Serial.

  1. מעלים את הקוד (חוטי המודול מנותקים)Upload the code (module data wires unplugged)
  2. בדיקה 1 — בכבל: Serial Monitor על 9600, מקלידים F ו-EnterTest 1 — cable: Serial Monitor at 9600, type F and Enter
  3. רואים Got: F (code 70) — ואחריו גם \n הנסתרYou see Got: F (code 70) — and then the hidden \n too
  4. מחברים את חוטי המודול. בדיקה 2 — באוויר: מתחברים דרך Bluetooth (השקף הבא) ומקלידים שובPlug the module wires back in. Test 2 — over the air: connect via Bluetooth (next slide) and type again
void loop() {
  if (Serial.available() > 0) {    // is a character waiting?
    char c = Serial.read();         // take ONE out
    Serial.print("Got: ");
    Serial.print(c);
    Serial.print("   (code ");
    Serial.print((int)c);           // its number
    Serial.println(")");
  }
}

📄 level1_bt_hello.ino📄 level1_bt_hello.ino

אם בדיקה 1 עובדת ובדיקה 2 לא — הבעיה בחיבור, לא בקוד.If Test 1 works and Test 2 doesn't — the problem is in the connection, not the code.

9מתחברים: צימוד ופתיחת הפורטConnecting: pairing and opening the port

Windows

  1. הגדרות ← Bluetooth ומכשירים ← הוספת מכשיר ← BluetoothSettings → Bluetooth & devices → Add device → Bluetooth
  2. בוחרים HC-05 (או השם שעל המדבקה). קוד: 1234 (לפעמים 0000)Pick HC-05 (or the name on the sticker). PIN: 1234 (sometimes 0000)
  3. "הגדרות Bluetooth נוספות" ← לשונית COM Ports ← הפורט שכתוב לידו Outgoing"More Bluetooth settings" → COM Ports tab → the port marked Outgoing
  4. ב-Arduino IDE בוחרים את הפורט הזה ופותחים Serial MonitorIn the Arduino IDE pick that port and open the Serial Monitor

Mac

  1. הגדרות מערכת ← Bluetooth ← מתחברים ל-HC-05 (קוד 1234)System Settings → Bluetooth → connect to HC-05 (PIN 1234)
  2. ב-Arduino IDE מופיע פורט בשם /dev/cu.HC-05The Arduino IDE shows a port called /dev/cu.HC-05
  3. בוחרים אותו ופותחים Serial MonitorPick it and open the Serial Monitor

בחלק מגרסאות macOS החיבור לא יציב — אם זה קורה, עוברים למחשב Windows או לאנדרואיד.On some macOS versions the connection is flaky — if so, switch to a Windows laptop or Android.

Android

  1. מצמדים את HC-05 בהגדרות Bluetooth של הטלפון (קוד 1234)Pair HC-05 in the phone's Bluetooth settings (PIN 1234)
  2. מתקינים אפליקציית טרמינל, למשל Serial Bluetooth TerminalInstall a terminal app, e.g. Serial Bluetooth Terminal
  3. Devices ← בוחרים את המודול ← Connect ← מקלידיםDevices → pick the module → Connect → type
כשהפורט נפתח, נורית המודול עוברת להבהוב כפול כל 2 שניות = מחובר. מודול מתחבר רק למחשב אחד בכל פעם — אם מישהו אחר כבר מחובר אליו, לא תראו אותו.When the port opens, the module LED switches to a double blink every 2 seconds = connected. A module connects to only one computer at a time — if someone else is connected to it, you won't get in.

10איך הארדואינו קורא פקודותHow the Arduino reads commands

תווים שמגיעים נכנסים לתור (כמו תור בדואר) ומחכים שם עד שנקרא אותם:Arriving characters go into a queue (like a line at the post office) and wait there until we read them:

  • Serial.available() — כמה תווים מחכים בתור?how many characters are waiting?
  • Serial.read() — מוציא תו אחד מתחילת התורtakes one character from the front of the queue

"השפה" שלנו: אות אחת = פקודה אחתOur "language": one letter = one command

זה פרוטוקול — הסכם בין שני הצדדים. הכי פשוט שיש: קל להקליד, קל לבדוק ב-if.That's a protocol — an agreement between both sides. The simplest there is: easy to type, easy to check with if.

if (Serial.available() > 0) {
  char cmd = Serial.read();

  // ignore the hidden Enter characters
  if (cmd == '\n' || cmd == '\r') return;

  if (cmd == '1') {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("OK: LED on");     // always answer!
  } else if (cmd == '0') {
    digitalWrite(LED_PIN, LOW);
    Serial.println("OK: LED off");
  } else {
    Serial.println("Unknown command");
  }
}
למה לענות? כי ככה רואים שהפקודה הגיעה. בלי תשובה אי אפשר לדעת אם הבעיה בחיבור או בקוד.Why answer? So you can see the command arrived. Without an answer you can't tell whether the problem is the connection or the code.

11שלב 2: מדליקים LED מהמחשבLevel 2: turn on an LED from the computer

שולחיםSendהארדואינו עושהThe Arduino doesועונהand answers
1מדליק את ה-LEDturns the LED onOK: LED on
0מכבהturns it offOK: LED off
?בודק מצבchecks stateLED is on
xלא מכירdoesn't know itUnknown command: x

ה-LED הוא נורית ה-L הקטנה שעל הלוח (פין 13). אפשר לחבר גם LED משלכם עם נגד ל-D13.The LED is the small L LED on the board (pin 13). You can also connect your own LED + resistor to D13.

📄 level2_bt_led.ino📄 level2_bt_led.ino

משימותTasks

  • הפעילו את שלוש הפקודות — קודם בכבל, אחר כך ב-BluetoothRun all three commands — first on the cable, then over Bluetooth
  • מחקו את השורה שמתעלמת מ-\n. מה קורה עכשיו? למה?Delete the line that ignores \n. What happens now? Why?
  • הוסיפו פקודה b שמהבהבת 3 פעמיםAdd a b command that blinks 3 times
  • הוסיפו LED שני עם פקודות משלוAdd a second LED with its own commands

12שלב 3: נוהגים במכונית מהמחשבLevel 3: drive the car from the computer

אותן חמש פונקציות תנועה מכל השיעורים. רק הקלט השתנה: עכשיו הוא מגיע כאות.The same five motion functions from every lesson. Only the input changed: now it arrives as a letter.

מרחק מהחיישן:Sensor distance: 60 cm

פקודהCommandIN1IN2IN3IN4
S0000
STOP ■ ■ LEFT RIGHT

הפקודה "נשארת" עד הפקודה הבאה: שולחים F פעם אחת והמכונית נוסעת עד S.A command "stays on" until the next one: send F once and the car drives until S.

13הקוד: קלט ← בטיחות ← פלטThe code: input → safety → output

void loop() {
  // 1) INPUT: did a command arrive?
  if (Serial.available() > 0) {
    char c = toupper(Serial.read());   // 'f' = 'F'
    if (c == 'F' || c == 'B' || c == 'L' || c == 'R' || c == 'S') {
      move = c;
      Serial.print("OK ");
      Serial.println(move);
    }
  }
  // 2) SAFETY: never drive into a wall
  if (move == 'F' && getDistanceCm() <= STOP_CM) move = 'S';

  // 3) OUTPUT: do the current move
  switch (move) {
    case 'F': forward();   break;
    case 'B': backward();  break;
    case 'L': turnLeft();  break;
    case 'R': turnRight(); break;
    default:  stopCar();   break;
  }
}

switch — חדש!new!

דרך מסודרת לכתוב הרבה if / else if על אותו משתנה: "אם move הוא F — קדימה; אם B — אחורה...". break אומר "סיימנו, צאו מה-switch". default = כל מקרה אחר.A tidy way to write many if / else if checks on the same variable: "if move is F — forward; if B — back...". break means "done, leave the switch". default = any other case.

שכבת הבטיחותThe safety layer

החיישן משיעור 2 עדיין על המכונית. אתם מחליטים לאן לנסוע — אבל אם יש קיר קרוב מ-15 ס"מ, המכונית מסרבת לנסוע קדימה.The sensor from Lesson 2 is still on the car. You decide where to go — but if a wall is closer than 15 cm, the car refuses to drive forward.

📄 level3_bt_car.ino · חיווט המכונית כמו בשיעור 2 (IN1 על D2), והמודול על D0/D1.📄 level3_bt_car.ino · car wiring as in Lesson 2 (IN1 on D2), module on D0/D1.

14אופציה: נוהגים עם Dabble (אנדרואיד)Option: drive with Dabble (Android)

במקום להקליד אותיות — ג'ויסטיק על מסך הטלפון. מחזיקים חץ = נוסעים, עוזבים = עוצרים. אותן פונקציות תנועה, אותה שכבת בטיחות.Instead of typing letters — a gamepad on the phone screen. Hold an arrow = drive, let go = stop. Same motion functions, same safety layer.

⚠️ חיווט אחר! ספריית Dabble ב-Uno לא משתמשת ב-D0/D1, אלא ב-SoftwareSerial — וברירת המחדל שלה היא D2/D3, בדיוק פיני המנוע שלנו. לכן מעבירים את המודול ל-D11/D12: TXD → D11, RXD ← D12 (דרך מפל המתח).⚠️ Different wiring! On the Uno the Dabble library doesn't use D0/D1 but SoftwareSerial — and its default is D2/D3, exactly our motor pins. So the module moves to D11/D12: TXD → D11, RXD ← D12 (through the divider).

הבונוס: D0/D1 נשארים פנויים — לא צריך לנתק כלום לפני Upload, וה-Serial Monitor בכבל ממשיך לעבוד.The bonus: D0/D1 stay free — nothing to unplug before Upload, and the Serial Monitor on the cable keeps working.

  1. מתקינים את Dabble מ-Play Store, ואת ספריית Dabble ב-Arduino IDEInstall Dabble from the Play Store, and the Dabble library in the Arduino IDE
  2. באפליקציה: אייקון החיבור ← בוחרים את המודול (קוד 1234 אם מבקשים) ← GamePadIn the app: the connect icon → pick your module (PIN 1234 if asked) → GamePad

אייפון: Dabble עובד שם רק עם מודולי BLE (כמו HM-10), לא עם HC-05.iPhone: Dabble there only works with BLE modules (like HM-10), not the HC-05.

#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <Dabble.h>

void setup() {
  Dabble.begin(9600, 11, 12);   // module on RX=D11, TX=D12
}

void loop() {
  Dabble.processInput();        // read the phone
  if (GamePad.isUpPressed()) {
    if (getDistanceCm() <= STOP_CM) stopCar();   // safety
    else                            forward();
  }
  else if (GamePad.isDownPressed())  backward();
  else if (GamePad.isLeftPressed())  turnLeft();
  else if (GamePad.isRightPressed()) turnRight();
  else                               stopCar();
}

📄 level3b_dabble_car.ino · Dabble מדבר ב"שפה" משלו (בינארית) — לכן בשלב 4 חוזרים לפקודות טקסט.📄 level3b_dabble_car.ino · Dabble speaks its own (binary) "language" — so Level 4 goes back to text commands.

15שלב 4: טלמטריה — המכונית מדווחתLevel 4: telemetry — the car reports

Bluetooth הוא דו-כיווני. עד עכשיו המכונית רק הקשיבה — עכשיו היא גם מדווחת, 5 פעמים בשנייה, שורה אחת בכל פעם:Bluetooth is two-way. So far the car only listened — now it also reports, 5 times a second, one line at a time:

D=23,M=F,S=160
  • D — מרחק בס"מ (999 = אין כלום מלפנים)distance in cm (999 = nothing in front)
  • M — התנועה הנוכחית (F/B/L/R/S)current move (F/B/L/R/S)
  • S — מהירות (0–255). פקודות 1–9 משנות אותהspeed (0–255). Commands 1–9 change it
שורה אחת = הודעה אחת. מפתח=ערך, מופרדים בפסיקים. כך כל תוכנה — גם דף אינטרנט — יכולה לקרוא את השורות ולהבין אותן.One line = one message. key=value, separated by commas. That way any program — even a web page — can read the lines and understand them.

millis() — שעון שלא עוצר את התוכניתa clock that doesn't stop the program

// every 200 ms, send one report line
if (millis() - lastReport >= REPORT_MS) {
  lastReport = millis();
  Serial.print("D=");  Serial.print(distanceCm);
  Serial.print(",M="); Serial.print(move);
  Serial.print(",S="); Serial.println(speed);
}

למה לא delay(200)? כי בזמן ה-delay הארדואינו קפוא: לא קורא פקודות ולא בודק את החיישן. עם millis() שואלים "עברו כבר 200ms?" — וממשיכים הלאה.Why not delay(200)? Because during a delay the Arduino is frozen: it doesn't read commands or check the sensor. With millis() we ask "have 200 ms passed yet?" — and move on.

📄 level4_bt_telemetry.ino📄 level4_bt_telemetry.ino

16בונוס: שם משלכם למודול (מצב AT)Bonus: your own name for the module (AT mode)

בכיתה מלאה במודולים שכולם נקראים HC-05 — קשה למצוא את שלכם. במצב AT מדברים עם המודול עצמו (לא דרכו) ומשנים לו הגדרות.In a room full of modules all called HC-05 — finding yours is hard. In AT mode you talk to the module itself (not through it) and change its settings.

  1. מחברים: TXD ← D11, RXD ← D12 (דרך מפל המתח), VCC ו-GNDWire: TXD → D11, RXD ← D12 (through the divider), VCC and GND
  2. מעלים את bonus_at_rename.inoUpload bonus_at_rename.ino
  3. מנתקים את ה-VCC של המודול, מחזיקים את הכפתור הקטן, מחברים VCC ומשחררים. הנורית מהבהבת לאט = מצב ATUnplug the module's VCC, hold the small button, plug VCC back in and release. The LED blinks slowly = AT mode
  4. Serial Monitor על 9600, סוף שורה: Both NL & CRSerial Monitor at 9600, line ending: Both NL & CR
מקלידיםTypeהמודול עונהModule answers
ATOK
AT+NAME=CAR-07OK
AT+NAME?+NAME:CAR-07
  • מכבים ומדליקים את המודול כדי לצאת ממצב ATPower the module off and on to leave AT mode
  • במחשב: מסירים את ה-HC-05 הישן ומצמדים שוב — עכשיו עם השם החדשOn the computer: remove the old HC-05 and pair again — now with the new name
HC-06? אין לו כפתור. בקוד משנים את BT_BAUD ל-9600, סוף שורה "No line ending", ומקלידים AT+NAMECAR-07 (בלי =).HC-06? It has no button. In the code set BT_BAUD to 9600, line ending "No line ending", and type AT+NAMECAR-07 (no =).

17משהו לא עובד? בודקים לפי הסדרSomething's not working? Check in order

מה רואיםWhat you seeמה בודקיםWhat to check
ההעלאה נכשלת: not in syncUpload fails: not in syncחוטי המודול עדיין על D0/D1 — מנתקים ומעלים שובThe module wires are still on D0/D1 — unplug and upload again
המודול לא מופיע ברשימהThe module doesn't appear in the listהנורית מהבהבת מהר? אם לא — בדקו VCC/GND. אולי מישהו אחר כבר מחובר אליוIs the LED blinking fast? If not — check VCC/GND. Maybe someone else is already connected to it
מחובר, אבל לא מגיע כלוםConnected, but nothing arrivesTXD↔RX מוצלבים? בחרתם את פורט ה-Outgoing ולא את ה-Incoming? מהירות 9600 בשני הצדדים?TXD↔RX crossed? Did you pick the Outgoing port, not Incoming? 9600 on both sides?
מגיעות אותיות משובשותGarbled characters arriveמהירות לא תואמת — ה-Serial Monitor וה-Serial.begin() חייבים להיות אותו מספרSpeed mismatch — the Serial Monitor and Serial.begin() must use the same number
כל פקודה מקבלת גם "Unknown"Every command also gets "Unknown"תווי ה-Enter הנסתרים (\n, \r) — מתעלמים מהם בקוד, או בוחרים "No line ending"The hidden Enter characters (\n, \r) — ignore them in code, or choose "No line ending"
Dabble מתחבר אבל המכונית לא זזהDabble connects but the car doesn't moveהמודול חייב להיות על D11/D12 (לא D0/D1), ובקוד Dabble.begin(9600, 11, 12). באפליקציה פתחתם את GamePad?The module must be on D11/D12 (not D0/D1), with Dabble.begin(9600, 11, 12) in the code. Did you open GamePad in the app?
הארדואינו מתאפס כשהמנועים מתחיליםThe Arduino resets when the motors startסוללות חלשות, או חסר גראונד משותף בין הסוללה לארדואינוWeak batteries, or no common ground between the battery and the Arduino
החיבור נפל והמכונית ממשיכה לנסועThe connection dropped and the car keeps drivingהפקודות "נשארות" עד הפקודה הבאה — מרימים את המכונית. (אתגר: לעצור לבד אם לא הגיעה פקודה שנייה שלמה)Commands "stay on" until the next one — pick the car up. (Challenge: stop by itself if no command arrived for a full second)

18סיכום ואתגריםSummary & challenges

הרעיון האחד להיוםThe one idea for today

Bluetooth לא שינה את הקוד — Serial הוא Serial, בכבל או באוויר. מה שכן חדש: המצאנו פרוטוקול — הסכם על מה כל אות אומרת, ועל איך נראית שורת דיווח.Bluetooth didn't change the code — Serial is Serial, on a cable or over the air. What is new: we invented a protocol — an agreement on what each letter means, and on what a report line looks like.

מילים חדשותNew words

  • TX / RX · צימוד (pairing)pairing · פורט COMCOM port
  • Serial.available() · Serial.read() · switch · millis()
  • פרוטוקול · טלמטריה · מפל מתחprotocol · telemetry · voltage divider

אתגרים לביתChallenges for home

  • הוסיפו לשלב 3 פקודה ? שעונה במרחק הנוכחיAdd a ? command to Level 3 that answers with the current distance
  • הוסיפו פקודות מהירות + ו--Add speed commands + and -
  • עצירת חירום: אם לא הגיעה אף פקודה שנייה שלמה — המכונית עוצרת לבד (רמז: millis())Failsafe: if no command arrived for a whole second — the car stops by itself (hint: millis())

💻 כל קבצי הקוד של השיעור — הורדה והסברAll of this lesson's code — download & walkthrough

תודה — נתראה בפעם הבאה! 👋Thanks — see you next time! 👋