Serial.begin และอัตราบอด
เปิดช่องสัญญาณ USB ด้วยความเร็วที่ตรงกัน
Serial.begin และอัตราบอด เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
A Two-Way Channel
Your board can talk to your computer over the same USB cable that powers it. That conversation is called Serial communication. 🔌
Why Serial Matters
A microcontroller has no screen, so Serial is how you peek inside it. You print messages and watch them live on your computer.
Open the Channel
Before any printing, you must open the connection with Serial.begin(). You do this once, inside setup().
void setup() {
Serial.begin(9600);
}What Is Baud Rate?
The number you pass to begin is the baud rate: how many signal changes per second travel down the wire. It sets the speed of the chat.
9600 Is the Classic
A baud rate of 9600 is the friendly default. It is slow but rock solid, so most beginner sketches start there.
Serial.begin(9600);Faster When You Need It
You can go faster, like 115200, to stream lots of data without lag. Higher speed means more bytes per second.
Serial.begin(115200);Both Sides Must Agree
Here is the golden rule: the baud rate in your code must match the one set in the Serial Monitor, or you get garbage characters.
Garbage Means Mismatch
If your monitor shows weird symbols like ⸮⸮⸮, do not panic. It almost always means the baud rate on the two sides is different.
It Belongs in setup
Put Serial.begin() in setup(), not loop(). You only open the channel once, then it stays open for the whole program.
void setup() {
Serial.begin(9600);
}
void loop() {
}Wait for the Port
On some boards you add while (!Serial) to pause until the USB port is truly ready before you start printing.
Serial.begin(9600);
while (!Serial) { }Pick One Speed
Choose a baud rate and stick with it across your whole project. Mixing speeds between sketches is the most common Serial headache.
Quick Check
You set Serial.begin(9600) but the Monitor shows random symbols. What is most likely wrong?
Recap
You opened a USB chat with Serial.begin() in setup, learned that baud rate sets the speed, and that both sides must agree on it. 🎉
คำถามที่พบบ่อย
บทเรียน “Serial.begin และอัตราบอด” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “Serial.begin และอัตราบอด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “Serial.begin และอัตราบอด”
เปิดช่องสัญญาณ USB ด้วยความเร็วที่ตรงกัน คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “Serial.begin และอัตราบอด” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม
ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- Serial.begin และอัตราบอด
- Serial.print เทียบกับ println
- ดูค่าจากเซนเซอร์แบบสด
- อ่านคำสั่งที่คุณพิมพ์