Lesson-3: Arduino Photo Resistance (LDR)

Arduino Photo Resistance (LDR)

Arduino photo resistance (LDR) usage: the element whose resistance value decreases in light and increases in darkness is called Photo resistance (LDR).In a full dark environment, that is, little or no light falls on it, while the resistance value shows quite high resistance values such as 200 MΩ. In other words, as the light falling on it increases, the resistance value decreases in a nonlinear way. For this reason, increasing the light intensity leads to a decrease in the resistance value, and decreasing the light intensity leads to an increase in the resistance value.

Bu görsel boş bir alt niteliğe sahip; dosya adı ldr-e1605638739633.jpg
Photo resistance (LDR)

It can be used in all electronic circuits where the light intensity difference needs to be controlled. LDR is a circuit element whose resistance value changes inversely with light.As the intensity of light increases, the resistance value decreases, as the intensity of light decreases, the resistance value decreases.

Circuit Diagram:

LDR Foto Direnç
LDR photo resistance circuit

One leg of LDR photo resistance is connected to +5 V. The other leg is connected to the A0 entry of Arduino Uno Cartin. It also connects to GND pin with 10K ohm resistor.

LEDs are attached to Arduino Cartin 4,5,6,7 pins in order to the anode ends. The cathode ends of the LEDs are connected to the GND pin with resistors of 330 ohm.

Below are the codes of the Arduino circuit:

Codes Of The Circuit

int spin=0;
int lpin1=7;
int lpin2=6;
int lpin3=5;
int lpin4=4;

void setup() {
Serial.begin(9600);
pinMode(lpin1,OUTPUT);
pinMode(lpin2,OUTPUT);
pinMode(lpin3,OUTPUT);
pinMode(lpin4,OUTPUT);
}

void loop() {
int sensorValue=analogRead(spin);
Serial.println(sensorValue);

if (sensorValue>0 && sensorValue<=15){
digitalWrite(lpin1,LOW);
digitalWrite(lpin2,LOW);
digitalWrite(lpin3,LOW);
digitalWrite(lpin4,LOW);

}
if (sensorValue>15 && sensorValue<=30){
digitalWrite(lpin1,HIGH);
digitalWrite(lpin2,LOW);
digitalWrite(lpin3,LOW);
digitalWrite(lpin4,LOW);
}
if (sensorValue>31 && sensorValue<=45){
digitalWrite(lpin1,HIGH);
digitalWrite(lpin2,HIGH);
digitalWrite(lpin3,LOW);
digitalWrite(lpin4,LOW);
}
if (sensorValue>46 && sensorValue<60){
digitalWrite(lpin1,HIGH);
digitalWrite(lpin2,HIGH);
digitalWrite(lpin3,HIGH);
digitalWrite(lpin4,LOW);
}
if (sensorValue>61 && sensorValue<80){
digitalWrite(lpin1,HIGH);
digitalWrite(lpin2,HIGH);
digitalWrite(lpin3,HIGH);
digitalWrite(lpin4,HIGH);
}
delay (100);
}

Priorities are generated by the variables spin, lpin1, lpin2, lpin3 and lpin4. the spin variable is the LDR input, while the others are the LEDs input. Outputs of LEDs should be specified in Void setup.

int sensorValue=analogRead(spin);
Analog reading on the spin leg is performed with the command and the value from 0-255 is transferred to the sensorValue variable. Since this is the loop part of the program, this value can constantly change depending on the intensity of light. Then, in if structures, +5V is sent to the legs of LEDs according to the values that the sensorValue variable will receive.

Bu görsel boş bir alt niteliğe sahip; dosya adı LDR_0.jpgBu görsel boş bir alt niteliğe sahip; dosya adı LDR_1.jpg
Bu görsel boş bir alt niteliğe sahip; dosya adı LDR_2.jpg
Use of Arduino photo resistance (LDR)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *