LDR Interfacing with Arduino 

What is a LDR?

An LDR is a light-sensitive resistor whose resistance decreases as the intensity of light increases, and increases as light decreases

Image of LDR:


Task 1:- print the value of the LDR on LCD.

Code:-

#include<LiquidCrystal.h>

LiquidCrystal lcd(13,12,5,4,3,2);

int LDR=A0;

int a;

void setup ()

{

  lcd.begin(16,2);

  pinMode(LDR,INPUT);

}

void loop ()

{

  a=analogRead(LDR);

  lcd.setCursor(0,0);

  lcd.print(a);

  delay(1000);

  lcd.clear();

}

Output:-



Task 2:- Turn on the led if the LDR value is greater than 500

Code:-

int led=12;

int LDR=A0;

int a;

void setup ()

{

  pinMode(led,OUTPUT);

  pinMode(LDR,INPUT);

}

void loop ()

{

  a=analogRead(LDR);

  if (a>=500)

  {

    digitalWrite(led,HIGH);

  }

  else 

  {

     digitalWrite(led,LOW);

  }

}

Output:-