Light Dependent Resistor With Arduino


LDR - Light Dependent Resistor
In this article, I'll show you how to work with LDR to sense the light levels, measure those levels with the Arduino Uno, and print the value to the serial port.
Required Components:
  • Arduino Uno
  • LDR
  • Bread Board 
  • led 
  • Led Anode pin to Arduino digital pin.
  • Led Cathode pin to Gnd.
  1. int LDR=A0;  
  2. int led=13;    
  3. int ldr reading=0;    
  4. void setup()    
  5. {    
  6.   pinMode(led,OUTPUT);  
  7.   Serial.begin(9600);    
  8. }    
  9. void loop()    
  10. {    
  11. ldr reading=analogRead(LDR);  
  12.   if(value < 800)  
  13. {  
  14.   digitalWrite(led,HIGH);   
  15. }  
  16. else  
  17. {  
  18.   digitalWrite(led,LOW);  
  19. }  
  20.   Serial.println(ldr reading);    
  21.   delay(200);    
  22. }   
Initialize the value to the LDR to the Analog Pin and set value "0." In setup() function we want to set the Baud Rate as 9600 and in the loop() function we want to make the condition to the LDR; such as, first we want to read the Analog Pin value from the Arduino board. If the value is less than 800, the led will be ON, else the led will be in the OFF condition, and then print the value in the serial monitor.

Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles