Arduino deneyi 14
Potentiometer LED Dimmer
Beginner · 40 min · Analog-to-PWM mapping
Turn a potentiometer to control LED brightness.
Malzemeler
- Arduino Uno
- 10 kΩ potentiometer
- LED
- 220 Ω resistor
- Breadboard and jumper wires
Bağlantı
- Connect the potentiometer outer pins to 5V and GND; connect its centre pin to A0.
- Connect PWM pin 9 through 220 Ω to the LED anode and the cathode to GND.
Kod
const int potPin = A0, ledPin = 9;
void setup() { pinMode(ledPin, OUTPUT); }
void loop() {
int reading = analogRead(potPin);
int brightness = map(reading, 0, 1023, 0, 255);
analogWrite(ledPin, brightness);
}
Ne olmalı?
LED brightness changes smoothly as the knob turns.
Meydan okuma
Reverse the response so clockwise movement makes the LED dimmer.
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.
