Sensor – LDR
Posted by cognoscis on May 1st, 2008
Sensors help the robots become autonomous. Sensors, are just like eyes, ears and skin of the robot. They give your robot the necessary tools to sense its environment and decide on its own what to do next. Depending on your applications, there are different sensors available. Some of the common ones used by hobbyists are LDRs, IR detecting diodes, modulated IR receivers, Ultrasound sensors and the LASER sensors.
LDRs and the IR detecting diodes are the ones that have short range and are usually used in robots like a line follower which does not require a longer range. The are relatively cheap and easy to work with. So, as the topic name goes, I will be describing about using LDRs today.
Light Dependant Resistors or photoresistors or photocells are devices that change their resistance when light falls on them. When there is no light, it will have very high resistance. As the light intensity increases, its resistance decreases. Hence, we can use a LED and focus the light on to and surface that you want to detect. Place a LDR in the path of reflection. Thus, depending on the intensity of the reflected light, we will have different resistance and hence, the robot will be ale to sense its surroundings. Lets see how to use the LED and LDR to detect a white line.
I will be using a white LED(meaning it will emit white light) in this post. White LED will give good sensing ability for the fact that white light is reflected fully by a white line. So, we will be able to sense the white line distinctly using a white LED. Now, the one thing you must be aware before going into building the circuit is that the output of the sensor you get will be analog in nature. So, if you are using this output to drive any IC, you will need to convert this to a digital signal first. That can be done in two ways, using comparators or using ADCs(Analog-to-Digital Converters). I will be using the comparator as its very easy to handle and also cheap. After the comparator, you will get a signal that can be fed to any IC, be it a micro-controller or logic gates.

LDR sensors
The above circuit shows a simple design of sensor circuit. Towards the left is the emitter part. The 120? resistance is to limit current through the diode. You can make the LED grow brighter of dimmer by changing the value of resistance.
Now, lets see what happens in the LDR circuit part. The comparator used here is the ever popular LM339D. its a quad comparator IC package. It has four comparators and here only one of them is shown. The potentiometer R1 acts as the reference voltage for the comparator. You can use a potentiometer of 10k?/10 turns so that you can set a suitable reference value. The output from the LDR is given to the other input of the comparator as shown. Now, after you set up the circuit( preferably on your bread board) check the various voltage levels once.
See the voltage at the center pin of the pot(potentiometer) that is given to the pin 7 of LM339D. Now, by turning the pot you will be able to vary this voltage. Set it to 2.5V initially. Now, you check the voltage at pin 6 that is due to the LDR. First, when the LDR is covered, you will see that the voltage is less. Depending on the lighting conditions, it must be well within 1V. Now, allow the light to fall on the LDR and see the rise in the voltage. It will around 4 – 4.5 V. Now, that you have tested your inputs, its time to see if you are getting the proper output.
The resistance R3 at the output is called the pull up resistor. The chip provides an output of only ground. hence, you pull up the output line to high using this resistor unless the IC pulls it down. Now, when the light falls on the LDR, the input at in 6 will be less than the reference voltage which we have set at 2.5V. Now, the output will be low. If you take the light off the LDR, the voltage at pin 6 rises above the reference. Hence, the output will be high. Thus, we get a digital output from the circuit. Now, one more good thing about this circuit is that you can set your reference voltage level by varying the pot. This will help to operate the sensor in any environment. All you need to do is heck the minimum and maximum voltage from the LDR as described before and set the reference voltage value somewhere in between the two values obtained. Thats how you calibrate your sensors to a given environment.
Any problems or additions, please post as comments



June 13th, 2008 at 11:39 am
[...] Cognoscis’s Weblog Just another WordPress.com weblog « Sensor - LDR [...]
August 24th, 2008 at 4:00 am
Absolutely love your technique! Surprised I didn’t come across your blog earlier! Thanks for sharing and keep writing!
January 7th, 2009 at 8:11 am
Hey,I’m after a LDR that can work with 3V only. Is there anything on the market? thanks guys.
January 7th, 2009 at 10:42 am
HI,
LDR is just a resistor, so whatever voltage you apply, it will work well… You can try the normal one you have and if it doesnt work, you can get back to me
May 2nd, 2009 at 9:44 pm
Hey,
I need ur help as early as possible…In order to convert the LDR output to digital we r using an analog to digital convertor…bt den on connecting it to d adc d ic is getting burnt..can u tell d reason for it…
May 2nd, 2009 at 10:37 pm
Sanjana,
The reason for that happening is obviously over current. As I have mentioned before, LDR is just a resistor. When light falls on it, its resistance will become almost zero and hence a lot of current will flow into the ADC. But, this problem might also be due to incorrect biasing. place a 10k? potentiometer in series to that LDR input that goes into your ADC. Initially keep it at maximum and see if your IC heats up. If it does, then probably you must cross check your circuit for any places where there might be short circuit. Else, slowly reduce its resistance till you get proper output from the ADC.
If you are using ADC because you want EXACT value of the current coming into the circuit then its OK. If you are using ADC only to convert your AC to DC, then I suggest you switch to the simple comparator that I have shown in this post. All the same, if you can provide your circuit diagram and the part number of the ADC then I can try to pin point the bug in your circuit
May 3rd, 2009 at 12:02 pm
Hey,
Actually we got d circuit made from sum1….now dat person is saying that drs no problem in d ADC..its d OP07 which is getting burnt on connecting to ADC….what mite be d reason here?We have our project submission 2mrw…n sumthing or d odr gets spoilt every now n then..plz sort this out…..if possible you can send me ur email id..will directly contact u via messenger
July 4th, 2009 at 11:39 am
[...] IR signal for modulated IR sensor explained in my previous post. The second picture is a part of LDR sensors I made for my line follower robot. The picture has a comparator circuit and a motor driver circuit [...]
August 5th, 2009 at 3:32 pm
[...] Sensors – LDR [...]
November 7th, 2009 at 1:33 pm
[...] a black background). For this, LDR or IR sensors can be used. For construction of LDR sensor click here and for IR click here. Now, we have two sensors which are like two eyes of our bot. Using these [...]