Infra-red Sensor (IR)

What is infra-red (IR)? Infra-red is an electromagnetic wave who wavelength is between 0.75 microns to 1000 microns (1 micron = 1µm). Since infra-red is out of visible light range, we can’t really see IR with naked eye. However, there is a method to “see” IR which will be shown later on. Some of the infra-red applications includes night vision, hyperspectral imaging, and communications. We also use IR daily in our TV remote or any device remote.

IR range in electromagnetic spectrum

IR transmitter and receiver can be obtained at low price. Their shape is looks exactly the same as LED. To distinguish between transmitter and receiver, the transmitter always come in clear LED while receiver is black in colour. Other than that, there is also receiver that is used to pick up specific frequency IR, 38kHz. For your information, 38kHz frequency IR is commonly used in remote control.

IR LED pair
Left: IR Receiver
Right: IR Transmitter
TSOP 4838 IR Receiver, 38kHz

IR transmitter will emit infra-red when powered. You can connect the IR transmitter like a LED together with a current limiting resistor. The current limiting resistor is used to prevent too much of current passing through the transmitter and burnt it. I am using 330 ohms resistor for the IR transmitter.

As mentioned before, there are ways to “see” the infra-red from the transmitter. All you need is a camera, be it from the phone camera or digital camera. Camera has sensor which can pick up infra-red, so you can use this technique to check whether your IR transmitter is working or not.

IR from TV remote

The IR receiver that I am going to discuss is the normal IR receiver instead of 38kHz IR receiver. IR receiver detects the amount of infrared received and varies the resistance across the receiver. Therefore, we can measure the voltage across the receiver to detect the amount of IR received.

I am going to show two methods of using IR receiver. The first method is using comparator which able to convert it to either HIGH or LOW. Comparator is a device that compares two signal and outputs a digital signal indicating which is larger. More info on comparator available here.

I am using LM 324 Low Power Quad Op Amp. LM 324 has four op amps, so I just use only one of them for this test.

LM 324 Connection Diagram

I will briefly explain the operation of this comparator.

(1) IR transmitter will directly shine to IR receiver. IR receiver is connected in reverse biased with a 1M ohm series resistor. This will create a potential divider to the op amp non inverting input, V+.

(2) A 100k ohm variable resistor is connected to the op amp inverting input. By adjusting the variable resistor, we can adjust the reference voltage of comparator.

(3) When IR receiver is blocked from IR transmitter, the resistance across IR receiver will increase. Thus the voltage at non inverting input will increase.

(4) Since the V+ > V-, the output of op amp will be 5V. In this case, it will turn off the LED. Only when V+ < V-, the output of op amp is 0V, thus LED lights up.

Schematic for comparator
When V+ > V-, Vout = +Vcc;
when V+ < V-. Vout = 0

You can actually implement IR receiver with comparator when you only need to compare to a fixed reference voltage. You can use this as a simple sensor for line following robot to detect the lines.

IR transmitter
IR transmitter and receiver
Comparator set up on breadboard

Video demo for IR sensor using op amp comparator.

However, there are times we need to obtain the raw values on IR receiver instead 2 discrete levels, HIGH and LOW. Now I am going to show the second method, which utilize the Arduino. I connect the IR receiver to Arduino’s Analog Input and use the Analog-to-Digital Converter to get the values. I am going to show how to obtain the values from IR receiver using Arduino and display it on LCD.

The connection is pretty simple for IR receiver. All you need is connect from IR receiver to any of the 6 analog inputs of Arduino. In this case, I am using analog input A0.

The code for Infrared sensor:

//Infrared Sensor Experiment
//By Zxlee

#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

#define photodiode A0

void setup()

 lcd.print(" Infrared Sensor");


 lcd.print("By Zxlee");

 lcd.print("Analog Val= ");

void loop()
 int value = analogRead(photodiode); //Read analog value from IR receiver

 //Convert each digit in decimal and display on LCD

Some images on how to use infra-red sensor with Arduino.

Same configuration for IR transmitter and receiver
The IR receiver is blocked
IR receiver partially blocked
Set up on breadboard
Overall Circuit

Finally a video demonstration for IR sensor and Arduino.

12 thoughts on “Infra-red Sensor (IR)

  1. Wow, nice though ! It would be great if you could make some simple application out of this like simple security system ?? Just a suggestion !

    Thanks for the tutorial !


  2. If not mistaken, iPhone and iPad’s camera will not pick-up the IR ray, there is a filter on the camera lens.

    1. I do read before, some camera have filter that removes IR. So have to use camera that does not apply filter to check whether the IR is on or not.

      1. So far I know iPhone and iPad have the filter, other smartphone like Samsung and HTC do not have the filter. I’m not sure about digital camera.

    1. Hi varshith hr,

      I am not quite sure with your question. But the IR pair requires line of sight for detection, so you can design based on this concept.

      The range depends on the transmitter and receiver used. However, IR tend to get interfere easily from light source or sunlight.

  3. has anyone made this without the lcd? im not sure if i cn use this and ignore the lcd code tho i know it be better and cleaner if we use less datatypes or syntax that takes up space specially if we aren’t using that part of the code

  4. has this code been made without the lcd? im not sure if i cn use this and ignore the lcd code tho i know it be better and cleaner if we use less datatypes or syntax that takes up space specially if we aren’t using that part of the code

  5. Hi Zx Lee,
    It seems quite obvious, but just so as to clarify my understanding: the signal (waveform) at the IR receiver output is exactly inverse of the signal that is fed into IR transmitter. Is that right?

    1. Hi shant, I think you are referring to the last demo on infrared sensor with Arduino. One thing to take note is that when the photodiode (receiver) receives IR signal, it’s resistance will reduce. On the other hand, if there is no IR detected, it will be in high resistance.

      In the video, the photodiode is actually connected to the Arduino with a pull up resistor. Therefore, when there is IR received, the resistance of photodiode reduce, thus Arduino is measuring a low voltage (close to 0V). When it is blocked, the Arduino will be measuring a voltage from pull up resistor.

      Hope this clear things up for you.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s