0Pricing
Arduino & IoT Academy · درس

قراءة الأوامر التي تكتبها

استخدم Serial لتشغيل الإجراءات من لوحة المفاتيح.

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

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

Talk Back to Your Board

Serial works both ways. You can type into the Monitor and your board will read it, letting you send commands from your keyboard. ⌨️

Is Anything Waiting?

First check if data has arrived with Serial.available(). It returns how many bytes are sitting in the buffer, ready to read.

if (Serial.available() > 0) {
}

Why Check First

Reading when nothing is there gives junk. So you guard your read with available() and only act when real data exists.

Read One Character

Grab a single incoming character with Serial.read(). It pulls one byte from the buffer and hands it to you.

char c = Serial.read();

React to a Command

Now branch on what you got. Compare the character and run different actions, like turning an LED on or off.

if (c == '1') digitalWrite(13, HIGH);
if (c == '0') digitalWrite(13, LOW);

Mind the Quotes

Notice the single quotes around '1'. That is a character, not the number one, and matching it correctly matters.

Reading Whole Words

For full commands like on or off, read a whole line with readStringUntil(), stopping at the newline you send.

String cmd = Serial.readStringUntil('\n');

Compare the Text

Then test the whole word. If the String equals on, do one thing; if it equals off, do another.

if (cmd == "on") digitalWrite(13, HIGH);

Set the Line Ending

In the Monitor, pick a line ending like Newline. It tells readStringUntil where each typed command stops.

Confirm Back

Good feedback feels great. After acting on a command, println a confirmation so you know the board heard you.

Serial.println("LED is on");

Now It Is Interactive

You just built a tiny command interface. Type, the board reads, acts, and replies. That is real two-way control. 🚀

Quick Check

Which function tells you whether typed data has arrived and is waiting to be read?

Recap

You made the board listen: checking available(), reading characters or full lines, acting on commands, and confirming back. Two-way Serial done! 🎉

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

هل درس «قراءة الأوامر التي تكتبها» مجاني؟

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

ماذا ستتعلم في «قراءة الأوامر التي تكتبها»؟

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

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

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

كم من الوقت يستغرق درس «قراءة الأوامر التي تكتبها»؟

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

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

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

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

  1. ‏Serial.begin ومعدل البود
  2. ‏Serial.print مقابل println
  3. مراقبة قيم المستشعرات مباشرة
  4. قراءة الأوامر التي تكتبها
← العودة إلى Arduino & IoT Academy