ศิลปะ
ความงามและสุขภาพ
งานฝีมือ
วัฒนธรรมและประวัติศาสตร์
ความบันเทิง
สิ่งแวดล้อม
อาหารและเครื่องดื่ม
วิศวกรรมย้อนรอย
วิทยาศาสตร์
กีฬา
เทคโนโลยี
อุปกรณ์สวมใส่
Push Buttons — SIK Circuit 5
Ed

สร้างโดย

Ed

17. มีนาคม 2026FI
99
0
0
0
0

Push Buttons — SIK Circuit 5

Use two push buttons for digital input. Learn about digitalRead(), pull-up resistors, and boolean logic (AND, OR, NOT) to control an LED.

คำแนะนำ

1

Parts & Introduction

Push buttons are the simplest digital input. This experiment uses two buttons with an XOR logic gate: the LED turns on if you press either button, but turns off if you press both. You'll learn about digitalRead(), pull-up resistors, and boolean logic.

Parts Needed

  • 1x Arduino Uno + USB cable
  • 1x Breadboard
  • 2x Push Buttons
  • 1x LED (any color)
  • 1x 330Ω Resistor
  • 2x 10KΩ Resistors (pull-ups)
  • 7x Jumper Wires

วัสดุสำหรับขั้นตอนนี้:

SparkFun Inventor's Kit - V3.2SparkFun Inventor's Kit - V3.21 ชุด

เครื่องมือที่ต้องใช้:

Computer with Arduino IDEComputer with Arduino IDE
2

Hardware Hookup

Wiring Instructions

  1. Place both push buttons across the center canyon of the breadboard.
  2. Button 1: Connect one pin to GND. Connect the opposite diagonal pin to Arduino Digital Pin 2. Add a 10K resistor between Pin 2 and 5V (pull-up).
  3. Button 2: Connect one pin to GND. Connect the opposite diagonal pin to Arduino Digital Pin 3. Add a 10K resistor between Pin 3 and 5V (pull-up).
  4. Connect LED positive leg to Digital Pin 13, negative leg through 330Ω resistor to GND.

Note: The pull-up resistors hold the input HIGH when the button is not pressed. Pressing the button connects the pin to GND (LOW).

วัสดุสำหรับขั้นตอนนี้:

Push ButtonPush Button2 ชิ้น
BreadboardBreadboard1 ชิ้น
Jumper WiresJumper Wires7 ชิ้น
3

Arduino Code

Open the Arduino IDE and upload the following sketch to your Arduino board.

push_buttons.inoarduino
/*
SparkFun Inventor's Kit
Example sketch 05 — PUSH BUTTONS

Use pushbuttons for digital input.
LED on if pressing button 1 OR button 2, but not both (XOR).

Hardware connections:
  Button 1: one pin to GND, diagonal pin to digital pin 2
            10K pullup resistor between pin 2 and 5V
  Button 2: one pin to GND, diagonal pin to digital pin 3
            10K pullup resistor between pin 3 and 5V
  LED: positive to pin 13, negative through 330 ohm to GND

This code is completely free for any use.
*/

const int button1Pin = 2;
const int button2Pin = 3;
const int ledPin = 13;

void setup()
{
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  int button1State, button2State;

  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  // XOR logic: on if either pressed, off if both pressed
  if (((button1State == LOW) || (button2State == LOW))
      && !
      ((button1State == LOW) && (button2State == LOW)))
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

วัสดุสำหรับขั้นตอนนี้:

Arduino Uno R3Arduino Uno R31 ชิ้น

เครื่องมือที่ต้องใช้:

Computer with Arduino IDEComputer with Arduino IDE
4

Test & Experiment

What You Should See

The LED turns on when you press either button individually. It turns off when you press both buttons simultaneously (XOR logic).

Troubleshooting

  • Not responding: Push buttons are square — it's easy to put them in the wrong orientation. Try rotating 90°.
  • LED always on or always off: Check the pull-up resistor connections. Without them, the input pin floats and reads random values.

Experiments to Try

  • Change the logic to AND (both buttons required) or simple OR.
  • Use the buttons to control an RGB LED — one button for color, one for brightness.
  • Try using INPUT_PULLUP mode to eliminate the external resistors.

วัสดุ

8
  • SparkFun Inventor's Kit - V3.2ค่าคอมมิชชัน 10%
    1 ชุด
    $105.94
  • Push Buttonค่าคอมมิชชัน 10%
    2 ชิ้น
    Magento Legacy Storeships internationally
    เริ่มที่$1.19
  • Breadboardค่าคอมมิชชัน 10%
    1 ชิ้น
    Magento Legacy Storeships internationally
    เริ่มที่$9.50
  • Jumper Wiresค่าคอมมิชชัน 10%
    7 ชิ้น
    Magento Legacy Storeships internationally
    เริ่มที่$4.16
  • Arduino Uno R3ค่าคอมมิชชัน 10%
    1 ชิ้น
    Magento Legacy Storeships internationally
    เริ่มที่$27.06
  • 5mm LEDค่าคอมมิชชัน 10%
    1 ชิ้น
    Magento Legacy Storeships internationally
    เริ่มที่$3.57
  • 1 ชิ้น
    ตัวยึดตำแหน่ง
  • 10K Ohm Resistorค่าคอมมิชชัน 10%
    2 ชิ้น
    Magento Legacy Storeships internationally
    เริ่มที่$1.19

เครื่องมือที่จำเป็น

1
  • ตัวยึดตำแหน่ง
ยอดรวมประมาณ
สิ่งที่ผู้ทำซื้อมา วัสดุที่ไม่แสดงราคาให้หาซื้อจากที่ที่คุณซื้อได้
$105.94

CC0 สาธารณสมบัติ

พิมพ์เขียวนี้เผยแพร่ภายใต้ CC0 คุณสามารถคัดลอก แก้ไข แจกจ่าย และใช้งานผลงานนี้เพื่อวัตถุประสงค์ใดก็ได้ โดยไม่ต้องขออนุญาต

สนับสนุนเมกเกอร์โดยซื้อสินค้าผ่านพิมพ์เขียวของพวกเขา ซึ่งพวกเขาจะได้รับ ค่าคอมมิชชันเมกเกอร์ ที่ผู้ขายกำหนด หรือสร้างเวอร์ชันใหม่ของพิมพ์เขียวนี้และรวมเป็นการเชื่อมต่อในพิมพ์เขียวของคุณเพื่อแบ่งรายได้

การสนทนา

(0)

เข้าสู่ระบบ เพื่อร่วมการสนทนา

กำลังโหลดความคิดเห็น...