How to use a LDR (Light dependent resistor), photo transistor
PDF Print E-mail
                                                      Light dependent resistors - LDR

LDR's are the resistors whose resistance varies with the intensity of light incident upon it. The resistance is typically very high when no light in incident and it begins to reduce as light is incident upon it. LDR or a photo sensor finds its application in many robotics/embedded system applications such as line following robot, Light seeking robot, garage door opener when cars light is incident upon it, solar tracker etc.

What questions this document addresses?

  • Detailed explanation of how LDR works and how to use them.
  • Concept of developing your own customized LDR module for varying applications.
  • End to end working circuit diagram for using a typical LDR module.
  • Challenges in implementation.
  • Troubleshooting a LDR sensor module.


Operation:
It is known by many names such as LDR, photo resistor, photo conductor etc. The resistor has a component which is sensitive to light. One of the semiconductor materials used in constructing a LDR is cadmium sulphide (CdS).
Since an electrical current would involve movement of electrons which drifts as per the potential difference applied at two ends, a LDR or photo resistor is made up of a semi conductor material which has a high resistance and less free electrons available for conduction and hence offers a higher resistance. As light (of sufficient frequency) is incident upon this semiconductor material, photons are absorbed by the lattice of the semiconductor and a part of this energy gets transferred to the electrons in the lattice which would then have sufficient energy to break free from the lattice and participate in conduction. Hence, the resistance of the photo resistor reduces with varying intensity of incident light.

                                 ldr
                                                                                        LDR of varying sizes.


From robotics perspective, it is mainly used in making a basic line following robot.
The LDR is a typical receiver (Rx) and any led emiting visible light can form the transmitter (Tx). while selecting the Tx led, be careful to first check and ensure if the light emitted by it brings about an appreciable change in the resistance on the LDR.

When the Tx is forward biased, it begins emitting visible light which upon reflection would be received by the LDR (assuming the Tx and Rx are suitably oriented). The circuitry involved is quite similar to the one involved while making an infrared sensor.



                                                                                               tx
                                                                                                      A typical transmitter circuit.

The resistance R1 in the above circuit can vary. It should not be a very high value (~ 1Kohm) as then the current flowing through the diode would be very less and hence the intensity of emitted light would be lesser. By increasing the current flowing in the circuit, you can increase the effective distance of your LDR sensor. However, there are drawbacks of reducing the resistance. Firstly, it would increase the current consumption of your circuit and hence drain the battery (one of the few ‘precious’ resources for any embedded system) faster. Secondly, increasing the current might destroy the Tx. So, the final choice should be a calculated trade off between these various factors.

You can also modulate the Tx  to achieve better distance and immunity.The receiver has a very high resistance, typically of the order of mega Ohms when light is not incident upon it. However, when visible light is incident upon it, the resistance decreases sharply to the order of a few kilo Ohms or even lesser. This feature forms the basis of using LDR as a sensor. You will need to connect a resistance of the order of a few mega Ohm in series with the Rx. Then tap the output voltage at the point of connectivity of these two resistors. A complete Tx-Rx circuit is given below.

                                                                                           tx-rx
                                                                                                     Complete Tx-Rx cirtcuit.

Remember, the value of R2 can vary depending upon the Rx diode you are working with. You are advised to first check the resistance of Rx diode with no light being incident upon it and then select the value of R2 for decent performance.

Case1: when no light is incident upon the Rx

Rx would be of the order of mega ohms and hence the output voltage would be around 2.6v – 3v depending upon your choice of R2 and the Rx.

Case2: when light is incident upon the Rx

The resistance of Rx will sharply fall and hence the output voltage would be around 1.8v - 1.5v depending upon your choice of Rx and R2.

Once you obtain a neat difference between the output voltages in case1 and case2, your sensor is ready.

How to use this LDR sensor?

So far, we had just prepared the sensor. Now, we will see 2 different methods of using this in your machine.

Method1:

The output voltage is in the form of analog voltage. You would need to convert it into digital format so that whenever light is incident upon the Rx, the final conditioned output voltage is a logic high (binary 1) and whenever light is not incident upon the Rx, the conditioned output voltage should be a logic low (binary 0).
You can use a comparator IC to serve this purpose. A comparator IC compares 2 input voltages using an op-amp and gives a logic high or a logic low as the final output. LM324 is one such comparator. Lets see how it can be used here:
                                           lm324

                                                                                           Pin diagram for LM324 comparator.

It has 4 separate channels meaning it can compare 4 pairs of voltages. For a single LDR sensor, only one channel is enough. Here we would be using pin 1,2 and 3 for our sensor.

Input voltage at pin2 > input voltage at pin3 ; Output1=> logic 0

Input voltage at pin2 logic 1

Connect the output of our sensor circuit to pin2 of this IC. Generate 2v from a potential divider circuit of multiple resistance and feed that 2v to pin3 of the IC. Therefore, Vin at pin3 = 2v (constant).

 

Case1: when light is not incident upon the Rx.

When the Tx is above a black line, the black line will absorb all the incident light and will not reflect an appreciable amount of light for the Rx to receive. If you are making an obstacle avoiding robot, then when there is no obstacle in front of the Tx, Rx will not receive back the transmitted light. However, when an obstacle comes in front of the Tx, it will reflect the light incident upon it and hence Rx will receive the the light.
                                                             black_line
                                                                                 
In this case, the output voltage of the sensor = 2.5v. Hence the input voltage at pin2 =2.5v.
Input voltage at pin2 > input voltage at pin3 ; Output1=> logic 0

Case2: when IR is incident upon the Rx, the output voltage of the sensor = 1.8v. Hence the input voltage at pin2 =1.8v.
Input voltage at pin2 logic 1

                                                     white_line
Now you can easily use the digital logic level outputs to drive any logic circuit as well as couple it with a microcontroller to decide the future course of action.

Method2:

Using ADC to convert the analog output voltage from sensor into a digital format. This is a little tedious way of implementing the similar logic but can give you great granular control over the distance/range of your LDR sensor. You can use the built in ADC channels of a microcontroller also.

The program section in the tutorial of robosense covers the program required to use the adc channels of a microcontroller as well as program for implementing a simple line follower or obstacle avoiding robot.

Implementation challenges:

One might be tempted to infer that LDR are good substitues for Infrared sensors and vice versa due to very similar technique of implementation for both of them. However, there are some inherent hurdles to be overcomed if you try to substitute either of these sensors. The challenges faced would be specific to a particular case and would largely be environment biased. For example, if you are using LDR/photo sensors in a line following robot, please ensure that you cover the entire array of the sensors within a case so as to minimize the interference due to ambient light. Calibrating your circuit time and again for varying ambient lighting would not be a preferable option. Hence, we would strongly recommend to make an ingenuous case like the one shown below:

                                                                            virtuoso2

                                                                                                          LDR based line following robot.     

 

                                                                           virtuoso3

                                                                                                     Taking a closer look at the sensor array

Other minor issues can be to get a decent variation in resistance when light is incident upon the LDR and when it is not. Be careful about not wasting too much of battery by using a bright Tx which consumes high power.

Troubleshooting:

Troubleshooting LDR circuits is not very complex.

Step1: First verify if the Tx led is working fine. Since you would be using visible light here, a quick look with naked eyes should serve the purpose.

Step2: Once you have verified that the TX are working fine, check if the output at the receiver side is showing correct expected voltages when light is incident upon it and when it is absent.

Step3: if the Tx and Rx are behaving correctly, please check the LM324 comparator and check if it is giving correct outputs in different scenarios.

 

For any suggestions or questions, please write to This e-mail address is being protected from spambots. You need JavaScript enabled to view it or scribble in our forum.

Useful resources:
http://www.robosense.in/index.php/tutorials/electronics/70-infra-red-ir-sensor-designing-basic.html