Arduino deneyi 03
Button-Controlled LED
Beginner · 40 min · Digital input
Read a push button and use it to control an LED.
Malzemeler
- Arduino Uno
- Push button
- LED
- 220 Ω resistor
- 10 kΩ resistor
- Breadboard and jumper wires
Bağlantı
- Connect one side of the button to 5V and the other to pin 2.
- Connect a 10 kΩ pull-down resistor between pin 2 and GND.
- Connect pin 13 through 220 Ω to the LED anode; connect the cathode to GND.
Kod
const int buttonPin = 2;
const int ledPin = 13;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, digitalRead(buttonPin));
}
Ne olmalı?
The LED lights while the button is pressed.
Meydan okuma
Change the circuit and code to use INPUT_PULLUP.
Güvenlik ve sorun giderme
- Bağlantıyı değiştirmeden önce gücü kes.
- Her LED ile direnç kullan.
- Kart ve port seçimini Arduino IDE'de kontrol et.
- Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.
Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.
