Bu dersimizde foto direncin üzerine düşen ışığın şiddetine göre 10 adet ledi yakıp söndüreceğiz. Farklı ışık şiddeti değerlerinde arduino çıkışlarındaki ledlerden sadece biri ışık vermektedir. Kullandığınız ldrnin direnç değişimine göre ldrye seri bağlı olan direncin değerini deneme yanılma ile kendiniz belirleyiniz. Ben 220 kiloohm kullandım. 123d.circuits.io simülasyonında 1k direnç değerinde simüle yapılabildi.

LDRnin üzerine düşen ışığın şiddetine göre arduinonun 1 nolu analog girişine uygulanan gerilim 0 Volt ile 5 Volt arasında değişmektedir. Arduino programı bu gerilim değişikliklerini değerlendirerek hangi dijital çıkışın aktif olacağına karar vermekte ve o çıkıştaki ledin yanmasını sağlamaktadır. Bu mantıkla her ışık şiddetine karşılık gelen bir dijital veri elde etmiş oluyoruz. Bu dijital veriyi de birçok arduino projesinde kullanabiliriz.

Arduino kodları:
scription">Kod:
/* ========================================================
    Project : Photo resistor (Light dependent resistor) and LEDs
     Author : ScottC
    Created : 23rd May 2011
Description : Use a photo resistor to create an LED animation.
============================================================
*/

//Define the analog pin the photo resistor is connected to (A0)
int photoRPin = 0;   

void setup() {
    //initialise the LED Pins as OUTPUTS
    for (int i=4; i<14; i++){
      pinMode (i, OUTPUT);
    }
}

void loop(){
    //Turn off all the LEDs before continuing
    for (int i=4; i<14; i++){
      digitalWrite(i, LOW);
    }
    
 /* Read the light level:
     Adjust the analog reading values ranging from 120 to 600
     to span a range of 4 to 13. The analog reading of 120
     is when there is maximum resistance, and the value of 600
     is when there is minimum resistance. These analog readings
     may vary from photo resistor to photo resistor, and therefor
     you may need to adjust these values to suit your particular
     LDR. */
    int photoRead = map(analogRead(photoRPin), 120, 600, 4, 13);
    
    /* Make sure the value of photoRead does not go beyond the values
      of 4 and 13 */
    int ledPin = constrain(photoRead, 4, 13);
    
    /* Turn the LED on for a fraction of a second */
    digitalWrite(ledPin, HIGH);
    delay(10);
    digitalWrite(ledPin, LOW);
}
Devre şeması:


Deney borduna montajı:



123d.circuits.io simülasyonu:



Reel videosu:



ISIS simülasyonu: