# 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.

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:

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.