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
- int LDR=A1;
- int led=11;
- int ldr reading=0;
- void setup()
- {
- pinMode(led,OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- ldr reading=analogRead(LDR);
- if(value < 800)
- {
- digitalWrite(led,HIGH);
- }
- else
- {
- digitalWrite(led,LOW);
- }
- Serial.println(ldr reading);
- delay(200);
- }
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: