IR sensors
Posted by cognoscis on June 13th, 2008
After the LDRs, I now come to the next level of sensors, the Infra red sensors. I am going to describe the use of IR LED and IR photodiodes today. Now, if you have my post about LRD sensors(http://cognoscis.wordpress.com/2008/05/01/sensor-ldr/), you will notice that the working of the IR sensors in exactly the same. Then whats the advantage of using these sensors one might wonder. The main advantage of IR sensors in that it will not be affected by noise as much as the LRDs would be. Since LRD use white light, there can be many sources of noise for it.
IR LED(left) and IR detector(right)
The picture shows an IR LED and a photodiode that can detect IR radiations. We use the same principle as that of the LDR when we use these IR sensors to follow a white line. Once you have seen its working, you can apply it for different purposes. Similar to LDR, the photodiode will conduct only when IR light falls on it. That is, its resistance is very high when IR light DOES NOT fall on it; and its resistance is very low when IR light falls on it. Here again the output will be analog in nature as in the LDR circuit. 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(similar to the LDR circuit) 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.
IR Sensor circuit (Click to view)
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. But the problem with IR is that we cannot see it. But, the cameras can. If you have digital camera, mobile camera or a web camera, just see the image being formed on the screen, you will find that the LED glows with a green or blue colour. See, how easy it is
Now, lets see what happens in the detector part. This is the same as the LDR circuit. 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 R2 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 IR detector is placed between VCC and ground. Now this acts as a switch. When OFF, the input to the comparator is VCC. When ON, input to the comparator is zero. 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 detector. First, when the IR detector is covered, you will see that the voltage is equal to VCC. Now, allow the light to fall on the IR detector and see the fall in the voltage. It will around 0.5 to 1 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 IR detector, 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 IR detector, 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 check 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 ![]()

August 11th, 2008 at 1:15 am
I agreed with you
January 26th, 2009 at 8:52 am
Sir,
According to the given circuit of LM339D, I fed the final output from pin 1 of the comparator to a port of microcontroller to drive the port.
But using multimeter I found that in both the cases i.e. when the IR sensor is obstructed or not, the final output is always low. So, finally the port of the microcontroller always remain low.
Kindly suggest me some steps to get rid of this problem.
January 26th, 2009 at 11:55 am
Pragyajit
I can think of a number of reasons for this. So, here is what I want you to do. Make sure again that you have connected the pull up resistor R3 as shown in the diagram. Since the pin floats for a HIGH output, it wont be able to drive the microcontroller.
If you have done that, now please cross check the potentiometer as described in the post and check the output across the comparator IC. If that gives the proper output then you need to consider the microcontroller.
Certain microcontrollers also have floating HIGH pins just like comparator. So, check the datacheet and see if the ports need to be pulled up using a pull up resistors. 8051 ’s PORT 0 is like that. You need external pull up resistors to drive it HIGH
Hope this solves your problem
January 26th, 2009 at 6:49 pm
Sir,
First of all, I am using the port P1.0 of microcontroller AT89C52. In this port, the is no need of using pull up resistor.
Using 10K pot, I fix the reference voltage at 3.0V.
Now when I donot connect the output of the comparator to the microcontroller, the output of the comparator shows high voltage when the IR sensor is obstructed.
As soon as I connect it to the microcontroller the final output goes down to about 0.5V.
What shoud I do now to get out from this problem?
January 26th, 2009 at 7:20 pm
Okay, there maybe some problem grounding problem. You can try something else, try to use some other port. Also, you try to run a program and take the input and see if you can make an LED glow. Also, the ports of the microcontroller must be programmed as input ports. So, cross check all of these.
January 30th, 2009 at 6:45 am
Sir,
According to your steps I have checked everything and find no problem in microcontroller. I doubt that the current drive from the output of LM339D is not enough to drive the port of microcontroller.
Is there any way to increase the current drive?
January 30th, 2009 at 12:47 pm
Well, this is actually very new problem I have seen
Anyways, you can indeed increase the current by employing a buffer between the comparator and the microcontroller. Here is the data sheet of one such buffer IC. This one has 4 buffers packaged in one IC. You also get more number of buffers in a single package. So, you can choose whichever you fell is right for your board. Here is the link to the one I mentioned
http://www.nxp.com/#/pip/pip=pip=74HC_HCT126_CNV_2|pp=[t=pip,i=74HC_HCT126_CNV_2]
February 21st, 2009 at 3:14 pm
hello sir,
thanks for your post,it will be very use full to my project,thank you very much again..
August 5th, 2009 at 3:30 pm
[...] IR sensors [...]
August 11th, 2009 at 6:17 pm
sir,
i’m just a beginner in autonomous robotcs, i’m tryng to make a line follower.
i’ve been able to figure out the sensor part of it only…now how do i proceed…can u plz help me out….
August 12th, 2009 at 7:14 am
Raktim,
Once you have the sensors, you will want to think about a logic that will help the bot to navigate the line. I will create a new post explaining a simple line follower. I hope that will help. Keep checking this site or else subscribe to it to get the feeds directly to your mail
Regards
February 18th, 2010 at 11:02 pm
can this be used as a clock pulse?