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

pinMode และ OUTPUT

กำหนดให้พินจ่ายกระแสไฟไปยัง LED

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

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

Pins Have a Job

Every Arduino pin can either listen or speak. Before you use one, you must tell it which job to do. That setup is the role of pinMode. 🔌

Why OUTPUT Mode

To light an LED, the pin must send current out into the world. You declare that intent by setting the pin to OUTPUT mode.

The pinMode Call

You configure a pin once, inside setup(). The pinMode function takes a pin number and a mode, and it remembers your choice.

pinMode(13, OUTPUT);

Naming Your Pin

Hard-coded numbers get confusing fast. Give the pin a clear name with a constant so your sketch reads like plain language.

const int ledPin = 13;

Set It Up Once

You only need to declare a pin's mode a single time. Put pinMode in setup(), which runs once when the board powers on.

void setup() {
  pinMode(ledPin, OUTPUT);
}

The Onboard LED

Pin 13 is special: most Arduino boards wire it to a tiny onboard LED. That means you can test output with no extra parts. 💡

A Friendlier Alias

You do not have to memorize the number. Arduino gives you the built-in name LED_BUILTIN, which points to that onboard LED for you.

pinMode(LED_BUILTIN, OUTPUT);

OUTPUT vs INPUT

Each pin defaults to listening. Setting OUTPUT flips it so the pin actively drives a voltage instead of just sensing one.

What 'Drive' Means

An OUTPUT pin can push out about 5 volts or pull down to 0. That controlled push is how a pin drives an LED on or off.

Forgetting pinMode

Skip pinMode and your LED may stay dim or dead. The pin never enters OUTPUT mode, so it cannot push enough current to shine.

Setup Is the Stage

Think of setup() as preparing the stage before the show. Declaring your pin's mode here gets everything ready for the loop that follows.

Quick Check

You want a pin to light an LED. What do you call first?

Recap

You learned to claim a pin with pinMode and OUTPUT inside setup(). With the pin ready to drive current, you can now make it blink. 🎉

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

บทเรียน “pinMode และ OUTPUT” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “pinMode และ OUTPUT”

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

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

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

บทเรียน “pinMode และ OUTPUT” ใช้เวลานานแค่ไหน

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

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

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

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

  1. pinMode และ OUTPUT
  2. digitalWrite HIGH และ LOW
  3. delay() และจังหวะการกะพริบ
  4. ต่อ LED ภายนอกอย่างปลอดภัย
← กลับไปที่ Arduino & IoT Academy