top of page

Interfacing the LDR Sensor to the Arduino and its usage

In this tutorial, I'm going to show you how to Interface the LDR sensor to the Arduino uno.


ITEM REQUIRED


1 x Light Dependent Resistor (LDR)

1 x Potentiometer

1 x Arduino board (I am using An Arduino Uno).

1 x USB cable

1 x Computer with Arduino software installed

1 x Breadboard





Circuit Theory:

An LDR is a type of variable resistor that changes its resistance according to intensity of the light incident on it. Generally, when the intensity of light is less i.e. in dark conditions, the resistance of LDR will be in the order of Mega Ohms (MΩ).


As the intensity of the light increases, it resistance decreases and falls down to few Ohms at maximum intensity of light.


Photo Resistors are semiconductor devices with photo sensitive cells. Photo cells are made with different compounds depending on the frequency of the light and application they are used.


In this circuit diagram the potentiometer is connected to the Ldr in series, as the voltage across the Ldr sensor increases above a particular threshold set by the Arduino a trigger is given to the buzzer/led. We can also connect a led to test the circuit if a buzzer is not available.


Step 1

Connect the circuit as per Circuit diagram


Arduino interfaced to ldr sensor
Circuit Diagram-1

Pictorial representation Of Arduino Interfaced to Ldr
Circuit Diagram-2

Step 2:

Open a new window in the arduino terminal and type the following code.


//Declaring the Pins

int sensorPin = A0; // select the input pin for the potentiometer

int sensorValue = 0; // variable to store the value coming from the sensor

float voltage;


void setup() {

// declare the ledPin as an OUTPUT:

Serial.begin(9600);

pinMode(11,OUTPUT); //You can either connect an led or a buzzer.

}

void loop()

{

sensorValue=analogRead(sensorPin);

voltage = sensorValue*(5.0/1023);

Serial.println(voltage);

if(voltage >= 2.5) //Set the threshold as per your preferred value

digitalWrite(11,HIGH);

else

digitalWrite(11,LOW);

delay(2);

}


Connect the Arduino to your pc and upload the code to the Arduino board. Open the serial monitor to see the voltage. Place your hand in front of the sensor to see the change in values in the serial monitor. As you place your hand over the ldr sensor the voltage across the sensor increases and the light turns on.



The Ldr resistor can be used in burglar alarms, automatic light switches, night Lamps, etc. It is also used in generation of efficient solar energy i.e. they are used in solar tracking systems.

Stayed tuned for more fun tutorial


72 views

Comments


bottom of page