LDR(Light Dependent Resistor)

Interfacing a LDR

Hardware Required
  • ARDUINO UNO
  • LDR
  • Buzzer
  • Connecting Wires
About Arduino
Arduino is a popular open-source development board for engineers and makers to develop electronics projects in an easy way. It consists of both a physical programmable development board (based on AVR series of microcontrollers) and a piece of software or IDE which runs on your computer and used to write and upload the code to the microcontroller board.

About LDR
photoresistor (or light-dependent resistorLDR, or photo-conductive cell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light-activated and dark-activated switching circuits.
A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. 









A LDR Sensor- It has four pins to be connected:
  
Connections
  • Connect VCC to VCC
  • Connect GND to GND
  • Connect D0 to digital pin(if you want to direct give HIGH or Low commands)
  • Connect A0 to analog pin

             Chart to represent LDR intensity



  If the LDR detects light then the green light in the LDR module will glow








If the LDR detects dark then the green light in the LDR module will not glow






Using digital input to interface LDR
Code
void setup()
{
pinMode( 9, INPUT);//LDR
pinMode( 5, OUTPUT);//Buzzer  
Serial.begin(9600);
}
void loop()
{ 
 if (( ( digitalRead(9) ) == ( HIGH ) ))
  {    
Serial.println("Dark");
digitalWrite(5,HIGH);
}
  if (( ( digitalRead(9) ) == ( LOW ) ))  
{ 
Serial.println("Light"); 
digitalWrite(5,LOW);  
}
   }
Code Explanation
In the code for LDR there's no need for explanation but in short i'll explain you; in the code for LDR you just need to give a condition that if the LDR detects Dark(HIGH) or Light(LOW) then buzzer should beep(according to my code).

Using ANALOG Input to interface LDR
Code
int x = 0;
void setup()
{
pinMode(5,OUTPUT);
Serial.begin(9600);
}
void loop()
{ 
x = analogRead(5); 
// Serial.println(x);
if (( ( analogRead(5) ) > ( 300 ) ))  
{
Serial.println("Dark");
digitalWrite(5,HIGH);
}
if (( (analogRead(5) ) < ( 300 ) )) 
 { 
   Serial.println("Light");
   digitalWrite(5,LOW);  
}
  }
Code Explanation
There is only one change in the connections that is you have to disconnect the wire from D0 to A0 because we are using analog input.


No comments:

Post a Comment