Arduino deneyi 04
LDR Light Sensor
Beginner · 45 min · Analog input
Measure light with a photoresistor and switch on an LED when the room gets dark.
Malzemeler
- Arduino Uno
- LDR/photoresistor
- 10 kΩ resistor
- LED
- 220 Ω resistor
- Breadboard and jumper wires
Bağlantı
- Make a voltage divider: 5V → LDR → A0 → 10 kΩ → GND.
- Connect pin 13 through 220 Ω to the LED anode and its cathode to GND.
Kod
const int ldrPin = A0;
const int ledPin = 13;
const int threshold = 400;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int light = analogRead(ldrPin);
Serial.println(light);
digitalWrite(ledPin, light < threshold ? HIGH : LOW);
delay(100);
}
Ne olmalı?
The Serial Monitor shows light readings and the LED switches on below the threshold.
Meydan okuma
Observe your room’s values and calibrate the threshold.
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.
