LDR Using Arduino Mega 2560

Introduction

In this article I will explain about the LDR (Light Dependent Resistor). It will measure the light level using the Arduino Mega 2560.

Parts
  • Arduino Mega 2560
  • LDR
  • LED
  • BreadBoard
  • Resistor
  • Hookup wires
LDR


   Figure 1: LRD
  • Light Dependent Resistor (LDR): t will measure the light level.
  • It will sense the light level.
Connection

Step 1:
Connection From The LDR To Arduinomega2560.
  • Take the positive pin connected to the Analog pin of A1 and also connect to the resistor with the positive pin connected with the Gnd.
  • The negative pin can be connected to the 5v of the Arduino Mega 2560.
Step 2: Connection From The LED To Arduino Mega 2560
  • Postive pin = 11
  • Negative pin = Gnd.
Programming
  1. int LDR=A1;    
  2. int led=11;      
  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. }  
Explanation

In this article I have explained about the light measuring level when the light has a low level, or at the high level it will display in the serial monitor.

Output
                                                      Figure 2: Output
 
Read more articles on Internet of Things:

Up Next
    Ebook Download
    View all
    Learn
    View all