Space In HIndi

 


Pages

Popular

Light sensor (LDR) interfacing

 Light sensor (LDR) interfacing

Components Required: 

1. Arduino UNO

 2. LDR 

3. 10KΩ resistor 

4. Connecting wires 

LDR Basics:



LDR stands for Light Dependent Resistor. It is a variable resistor depending on intensity of light. When this sensor exposed to light, it’s resistance starts decreasing and it could reduce less than 1KΩ. On the other hand in extreme darkness, resistance could reach in the range of MΩ. We need to change this resistance in equivalent change in voltage. This could be done using voltage divider rule. For this we need to connect LDR in series with 10KΩ resistor and obtain output from the point of contact where LDR and resistor are connected with each other.

Interfacing LDR with Arduino UNO:

As we have seen in LDR basics, we need to create a voltage divider rule. For that we will be connecting LDR in series with 10KΩ resistor. One end of LDR is connected to 5V of Arduino and other to resistor. One end of resistor is connected to LDR and remaining leg to GND. Output is taken from connection point of LDR and resistor.



 Programming:

 In this example we just need to observe changes in LDR output when there is light and when there is darkness. We will note the value when there is darkness and also note value when there is light. These values will be used in next experiment to turn LED on and off. So first we need to initialize variable to store value of output. After that in void setup() we need to initialize serial port to be able to monitor the output value. In void loop() we will simply read the analog output values and display on serial terminal. To make changes in sensor output value, hold a torch in front of LDR and you will observe increase in reading. To create darkness, simply put your hand over sensor and you will observe decrease in output values.

int output; 

void setup() 

{

     Serial.begin(9600);

 }

 void loop()

 { 

output = analogRead(A0);

 Serial.println(output); 

 delay(1000);


 }

Controlling LED with LDR

Components Required: 

1. Arduino UNO 

2. LDR

 3. 10KΩ resistor

 4. LED 

5. 220Ω resistor 

6. Connecting wires 

Interfacing LED and LDR with Ardiuno UNO

Interfacing is quite easier because now we already have completed LED interfacing and LDR interfacing. In this practical we just need to combine them together. Here LED is connected to digital pin 10 and LDR output is connected to pin A5. Ground for LDR and LED is commonly connected to ground of Arduino.

Programming: 

Here we need to turn LED on whenever there is darkness and turn off the LED in sufficient light. To make this possible we will consider darkness value as threshold. Whenever value would be below the darkness value calculated in earlier practical LED should turn on and vice versa.

int output; 

void setup() 

{

 pinMode(10, OUTPUT); // LED Pin 

Serial.begin(9600); 

}

 void loop()
{

 output = analogRead(A0); //Read sensor data 

Serial.println(output); //Print on serial terminal 

if(output<50) //Compare output with threshold 

{

 digitalWrite(10, HIGH); //Turn LED on 

}

 else 

{

 digitalWrite(10, LOW); //Turn LED off 

}

}

No comments: