0Pricing
Arduino & IoT Academy · บทเรียน

Serial.print เทียบกับ println

ส่งค่าพร้อมป้ายกำกับไปยัง Serial Monitor

Serial.print เทียบกับ println เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Sending Words Out

Once the channel is open, you send text with Serial.print(). Whatever you pass shows up in the Serial Monitor on your computer.

Serial.print("Hello");

Print Stays on One Line

The key thing about Serial.print() is that it does not move to a new line. The next print appears right after it.

Serial.print("Hi");
Serial.print("There");

That Prints HiThere

Those two prints produce HiThere, jammed together with no gap. Print never adds spacing for you.

Meet println

Use Serial.println() when you want each message on its own line. The ln means it adds a line break at the end.

Serial.println("Line one");
Serial.println("Line two");

Clean, Readable Output

That gives you two tidy rows in the Monitor. println is your go-to for status messages you read top to bottom.

Printing Numbers

You are not limited to text. Pass a number and Serial.print() converts it to readable digits automatically.

int score = 42;
Serial.println(score);

Build a Label

Mix text and values for clarity. Print the label first, then print the number, so output reads like a sentence.

Serial.print("Score: ");
Serial.println(score);

Why Labels Help

A bare number like 42 means nothing later. A label like Score: 42 tells you exactly what you are looking at.

Print Inside loop

Calls to print and println usually live in loop(), so values keep streaming out as your program runs.

void loop() {
  Serial.println("running");
}

A Common Pattern

A neat habit: print the label, then println the value. The label glues to the number, then the line wraps cleanly.

Serial.print("Temp: ");
Serial.println(24);

Pick the Right One

Reach for print when more output follows on the same line, and println when this is the end of the line. 🙂

Quick Check

Which call ends the current line and moves output to the next row?

Recap

You learned that print keeps output on one line while println adds a break, and that labeling values makes your Monitor easy to read. 🎉

คำถามที่พบบ่อย

บทเรียน “Serial.print เทียบกับ println” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “Serial.print เทียบกับ println” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “Serial.print เทียบกับ println”

ส่งค่าพร้อมป้ายกำกับไปยัง Serial Monitor คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “Serial.print เทียบกับ println” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม

ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. Serial.begin และอัตราบอด
  2. Serial.print เทียบกับ println
  3. ดูค่าจากเซนเซอร์แบบสด
  4. อ่านคำสั่งที่คุณพิมพ์
← กลับไปที่ Arduino & IoT Academy