How to use Photoresistor (LDR) with Arduino

Introduction

In this tutorial, we will explore How to use Photoresistor (LDR) with Arduino, also known as a Light Dependent Resistor (LDR), with an Arduino Uno board. A photoresistor is a type of resistor whose resistance varies based on the intensity of light falling on it. By connecting a photoresistor to an Arduino, we can measure the light level in the surrounding environment and use it for various applications such as automatic lighting systems, light intensity monitoring, and more.

Hardware Required

You will require the following Hardware Components for How to use Photoresistor (LDR) with Arduino.

Components#Buy From Amazon
Arduino UNO1Buy Now
Photoresistor (LDR)1Buy Now
9v DC Adapter (Optional)1Buy Now
Resistor 10KΩ1Buy Now
Resistor 220KΩ1Buy Now
Jumper WiresFewBuy Now
Breadboard1Buy Now

What is LDR?

An LDR light-dependent resistor is a type of resistor that changes its resistance based on the amount of light that it receives. This type of resistor is unique in that it allows for the sensing of light levels and the control of electronic circuits based on those levels.

In its simplest form, a twilight photoresistor consists of a resistor with a light-sensitive material, such as cadmium sulfide, that changes its resistance when exposed to light. The resistance of the photoresistor decreases as the light level increases, and vice versa. By measuring the resistance of the photoresistor, an electronic circuit can determine the light level and adjust its behavior accordingly.

Circuit Diagram

How-to-use-Photoresistor-LDR-with-Arduino-circuit

Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Code

//For more Projects: www.arduinocircuit.com

const int pResistor = A0; // Photoresistor at Arduino analog pin A0
const int ledPin=9;       // Led pin at Arduino pin 9

//Variables
int value;				  // Store value from photoresistor (0-1023)

void setup(){
 pinMode(ledPin, OUTPUT);  // Set lepPin - 9 pin as an output
 pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)
}

void loop(){
  value = analogRead(pResistor);
  
  //You can change value "25"
  if (value > 25){
    digitalWrite(ledPin, LOW);  //Turn led off
  }
  else{
    digitalWrite(ledPin, HIGH); //Turn led on
  }

  delay(500); //Small delay
}

Applications

  1. Using a photoresistor with Arduino opens up various applications. Here are a few examples:
  2. Build an automatic night light that turns on when it gets dark.
  3. Create a plant monitoring system that measures the light intensity for optimal plant growth.
  4. Develop a light-controlled robot that reacts to changes in the surrounding light levels.
  5. Remember to experiment and adapt the code to suit your specific application needs.

Conclusion

In this tutorial, we learned how to use a photoresistor (LDR) with an Arduino Uno board. By measuring the varying resistance of the photoresistor in response to light, we were able to determine the light level in the environment. This opens up a wide range of possibilities for creating interactive and responsive projects. So go ahead, explore different light-based applications, and let your creativity shine!

Leave a Comment


error: