Introduction
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
Connections:
- Led Anode pin to Arduino digital pin.
- Led Cathode pin to Gnd.
Programming
- int LDR=A0;
- int led=13;
- 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
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.
Output:
Read more articles on Arduino: