Site icon DIY Usthad

LDR With Arduino

arduino with ldr by diyusthad.com

In this tutorial, we are going to learn about how to use Light Dependent Resistor with Arduino and we are going to do a small project based on the LDR sensor.

What is LDR?

Light Dependent Resistor or Photoresistor, which is a passive electronic component, is basically a resistor that has a resistance that varies depending on the light intensity.

In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.

Video

What we are going to do!

We are going to connect an LED and a Photoresistor(Light Dependent Resistor or LDR) with an Arduino and program it to respond according to the light in the room.

If the room is dark then the LED will turn ON and if the room is bright then the LED will turn OFF.

Hardware Required

ComponentsAmazon.comBanggood.comAliExpressUtsource
Arduino UNO
Photoresistor/LDR
LED
Resistor(10k,220ohm)

Circuit

Code



//https://diyustahd.com
//https://youtube.com/diyusthad

const int ledPin = 13; //pin at which LED is connected

const int ldrPin = A0; //pin at which LDR is connected

int threshold = 600;

void setup() {

  Serial.begin(9600);

  pinMode(ledPin, OUTPUT); //Make LED pin as output

  pinMode(ldrPin, INPUT); //Make LDR pin as input

}

void loop()
{

  int ldrStatus = analogRead(ldrPin); //saving the analog values received from LDR

  if (ldrStatus <= threshold) //set the threshold value below at which the LED will turn on
  { //you can check in the serial monior to get approprite value for your LDR

    digitalWrite(ledPin, HIGH);  //Turing LED ON

    Serial.print("Its DARK, Turn on the LED : ");

    Serial.println(ldrStatus);

  }

  else

  {

    digitalWrite(ledPin, LOW); //Turing OFF the LED

    Serial.print("Its BRIGHT, Turn off the LED : ");

    Serial.println(ldrStatus);

  }

}
 



To buy electronic components order from UTSOURCE

Exit mobile version