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

INPUT เทียบกับ INPUT_PULLUP

เหตุใดพินที่ลอยจึงให้ค่าผิด และตัวดึงขึ้นช่วยแก้ปัญหาได้อย่างไร

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

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

Pins Can Listen Too

So far your pins pushed signals out. Now you'll make a pin listen instead, so your board can sense a button and react to it.

Set a Pin as INPUT

To read a button, you first tell a pin it should receive a signal. You do that by setting its mode to INPUT inside setup().

void setup() {
  pinMode(2, INPUT);
}

A Floating Pin Lies

An INPUT pin with nothing pulling it is called floating. It picks up stray noise and flickers between HIGH and LOW all on its own.

Why Floating Hurts

A floating pin gives you random, false button readings. Your code thinks the button is pressed when nobody touched it. ⚡

Pull Resistors Fix It

A pull resistor gently ties the pin to a known voltage. That gives it a steady default reading until the button changes it.

Pull-Up vs Pull-Down

A pull-up holds the pin HIGH by default; a pull-down holds it LOW. The Arduino has handy pull-ups built right into the chip.

Use INPUT_PULLUP

Skip the extra resistor: set the mode to INPUT_PULLUP and the board enables its internal pull-up for you automatically.

void setup() {
  pinMode(2, INPUT_PULLUP);
}

The Logic Flips

With INPUT_PULLUP the pin reads HIGH when the button is released, and LOW when it is pressed. The logic is inverted on purpose.

Wire to Ground

Because the internal pull-up holds the pin HIGH, you wire the button between the pin and GND. Pressing it pulls the pin down to LOW.

Less Wiring, Fewer Bugs

INPUT_PULLUP means one less resistor on your breadboard and no floating pin. For most beginner buttons it is simply the easiest choice.

Pick the Right Mode

Reach for plain INPUT only when your circuit already supplies its own pull resistor. Otherwise INPUT_PULLUP keeps things safe and simple.

Quick Check

Think about how INPUT_PULLUP behaves on an idle button.

Recap

You learned that an INPUT pin can float and lie, and that INPUT_PULLUP fixes it: HIGH when released, LOW when pressed. Next you'll actually read that value. 👍

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

บทเรียน “INPUT เทียบกับ INPUT_PULLUP” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “INPUT เทียบกับ INPUT_PULLUP”

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

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

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

บทเรียน “INPUT เทียบกับ INPUT_PULLUP” ใช้เวลานานแค่ไหน

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

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

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

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

  1. INPUT เทียบกับ INPUT_PULLUP
  2. อ่านสถานะปุ่ม
  3. if/else: LED ทำตามปุ่ม
  4. ต่อปุ่มบนเบรดบอร์ด
← กลับไปที่ Arduino & IoT Academy