# LDR sensor – How to use a Light Dependent Resistor

Learn how to use an LDR (Light Dependent Resistor), also known as a photoresistor. In this post we’ll go over the basics of the Light Dependent Resistor and an example on how to use an LDR to turn on a light when it’s dark.

An LDR or photoresistor is simply a resistor whose resistance varies depending on the amount of light that the LDR itself is exposed to. So in essence, the LDR is a light sensor capable of detecting the amount of light it’s subject to. This can be useful in applications in which we want to take a specific action under a specific lighting condition (turning on a light when it’s dark for example).

## LDR Configurations

Light Dependent Resistors can be purchased in its stand-alone form, or as a module. For the stand-alone you will need a resistor to mimic the module, which comes with a built in resistor, allowing you to simply connect to the three pins (GND, Vp, VCC). Either way, both configurations will take care of the same function. In this post, I will be using the module configuration.

## LDR Module Pins

If you are using the LDR module, then it’s important you know the pins.

VCC – Connected to main positive voltage on the circuit.

GND – Connected to ground on the circuit.

Signal (Vp) – Provides the signal associated with the amount of light (or darkness) to which the LDR sensor is exposed. Vp is simply a term I am choosing to use as I show on the circuit shown in the next section.

## LDR Circuit Basics

Applications of LDRs is mainly based on the concept of voltage division.

Voltage division: The main idea in voltage division is to generate different voltage values along a series of resistors. The simplest case is that of two resistances in series, which is actually the case for the LDR module circuit.

In the case of the LDR circuit voltage division, the input voltage is VCC (we will use 5V as the input), and the output will be measured at the location called out as “Voltage Probe” in the image.

We know the voltage drop across a resistor is equal to the resistance multiplied by the current flowing through it. We can use this to determine the equation used to calculate the voltage at Vp.

## LDR Resistance Range

Light Dependent Resistors have a resistance that can go as high as 1 Megaohm (1,000,000Ω) when they are in complete darkness. When the LDR is under light, the resistance will drop considerably (more light, less resistance). I used a multimeter to take resistance measurements of the LDR under different set of lighting conditions.

I also when ahead and turned off most of the lights, which resulted in a substantial increase in the resistance of the LDR (it when all the way to 703 komhs).

## LDR Resistance Range Analysis

Using the range for the LDR resistance of 0 kohms to 1,000 kohms, along with the previous equation, we can determine the expected range for Vp.

The graph above assumes VCC = 5V.

## Example – Darkness Sensor

In this example we’ll go over how to make a darkness sensor. The idea is to turn on a light automatically when the lights go off.

Components used:
LDR Module
LED Flash (if you use a standard LED light, make sure to also add a resistor in front of it).
2N2222 transistor
220kohm resistor
3.3Volt source
12Volt source

### What is each component needed for?

#### LDR module:

As previously mentioned, this component will change its resistance based on the amount of light it receives.

#### LED Flash:

Simply used to turn on and off based on the lighting conditions (detected by the LDR).

#### 2N2222 Transistor:

In a previous post, I went over how to use the 2N2222 transistor to turn on a bright LED Flash on and off. In that post we turned on the LED through the transistor using a switch (push button) and using an Arduino UNO. Now, we will use the LDR to control the turning on/off of the LED. In this case the transistor is acting as a switch, with the LDR controlling whether or not current should flow through the transistor.

#### 220kohm resistor:

The main reason for adding this component is to improve the conditions under which the LED will turn on and off. To be more specific:

• The 2N2222 transistor has a VBE saturation voltage of 0.6V. When VBE > 0.6 (along with other conditions) current can flow from the transistor collector to the emitter (from C to E), which allows the LED to turn on.
• Adding a large resistance means a larger voltage is needed to drive the required current through the transistor base, which results in the base current to be amplified at the transistor collector.

Net, we want to make sure that relatively small changes in brightness do not result in turning on the LED Flash. Take a look at the image showing the relation between Vp and the LDR resistance for the original scenario and the scenario after adding the 220kohm resistor.

The original curve shows the voltage Vp vs. RLDR with a step curve at the beginning, this meant that small changes in resistances (which means small changes in brightness) would have resulted in large changes in Vp voltage. The curve after adding the 220kohm transistor is not as steep, meaning voltage (and a result current too) will increase less abruptly relative to LDR changes.

#### 3.3Volt source:

3.3V was chosen over 5V to help keep the voltages going to the transistor base lower at lower LDR resistance values.

#### 12Volt source:

Needed to power up the specific LED Flash that I am using for this example (which required an input voltage between 9V and 14.8V.

*Note that the LED flash used in this example is a ready-to-use component with a built-in resistor, which is why a separate resistor is not needed.

## Components used in this example

*As an Amazon & Ebay Associate I earn from qualifying purchases.