Introduction: How to Use IR Sensor Using Op Amp and Arduino

Picture of How to Use IR Sensor Using Op Amp and Arduino

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.

Step 1: Infra-red Sensor

Picture of Infra-red Sensor

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 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.

Step 2: How to "see" IR

Picture of How to "see" IR

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.

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.

Step 3: Using Op Amp Comparator With IR

Picture of Using Op Amp Comparator With IR

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.

Step 4: Schematic and Theory of Operation

Picture of Schematic and Theory of Operation

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.

Step 5: Images

Picture of Images

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.

Step 6: Video



Video demo using IR sensor with comparator.

Step 7: Using Arduino With IR

Picture of Using Arduino With IR

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.

Step 8: Code for Arduino

Picture of Code for Arduino

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.begin(20,4);
pinMode(photodiode,INPUT);

lcd.setCursor(0,0);
lcd.print(" Infrared Sensor");

lcd.setCursor(5,1);
lcd.print("Experiment");

lcd.setCursor(6,3);
lcd.print("By Zxlee");

lcd.setCursor(2,2);
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
lcd.setCursor(17,2);
lcd.print((value%10));
value/=10;
lcd.setCursor(16,2);
lcd.print((value%10));
value/=10;
lcd.setCursor(15,2);
lcd.print((value%10));
value/=10;
lcd.setCursor(14,2);
lcd.print(value);
}

Step 9: Images

Picture of Images

Step 10: Video



Video demo on using IR sensor with Arduino

Step 11:

Hope this instructables cann give a brief introduction on using IR sensor. If you have any questions, feel free to drop me a comment below.

Visit my blog on IR sensor, http://iamzxlee.wordpress.com/2014/01/22/infra-red-sensor-ir/

Comments

avinashd9 (author)2016-02-17

i want a code for the digital values of levels that the i r sensors placed examole 25%,50%,75%,100% code for those levels in a web page for a container that fills any type of material

sauravd3 (author)2015-09-13

I actually wanted to know do IR Sensors and IR Receivers mean the same thing, or is an IR sensor a component of IR receiver or IR transmitter system?

ottoj (author)sauravd32015-10-10

An IR Receiver has an IR Detector as one of its components. An IR Sensor may be simply an IR Detector, or it may have other components to adjust the detector's signal to fit design expectations. Generally, an IR Receiver would be a device used with digital signals, while an IR Sensor might be used with analog signals.

sauravd3 (author)ottoj2015-10-11

The problem I am facing is that some manufacturers consider IR Receiver and IR Sensors as one and same, whereas some manufacturers consider IR Receiver as a component of IR Sensor.

ottoj (author)sauravd32015-11-04

The difficulty you are having is not uncommon for many components--stuff is marketed with keywords to attract attention, and you have to look closely at the specifications to know exactly what is being offered. One assumption we might be able to make is that something sold at an IR Receiver probably does not need much extra circuitry to make it work. If it is sold as a Sensor, it may require additional circuitry to condition the output signal to accomplish what you want to do. This conditioning could be something like amplification to make the signal large enough to connect to the input pin on your microcontroller, or to extend the range of the corresponding IR Transmitter.

One thing I've noticed is that the stuff you find on eBay and other online vendors (especially from China) comes without much (if any at all) guidance. You just get the device(s) without instructions, spec sheets, or warranty. That makes sense since the price is usually quite low, so you need to do a bit more research to find out exactly what arrived.

If you bought something and want to figure out what you ended up with, I'll assume you know what to do to get an output from your device. Connect a voltmeter to the output, set to read a 0-5 Volt signal, and set up an IR source nearby that your Sensor/Receiver can "see". Turn the IR signal ON, and check the output voltage. Then turn it off and check the output voltage again. If the output voltage changes, you've got a functioning sensor. If it swings 5 Volts (or whatever your sensor power source dictates), you may have a Receiver. Double the distance between the IR source and your sensor, and make the measurements again. Repeat this step until the sensor change drops below half of the first difference. A sensor obeys the inverse square law while a receiver is generally operated in saturation. All that really means is that a receiver is a sensor with very high gain so that this inverse square law doesn't matter until the IR source gets so far away that it can't be separated from other IR sources we don't control.

IR LEDs are great sources (i.e. transmitters) of IR signals. They are also OK as IR sensors, but generally need amplification to get a large enough signal to use. There are also IR Photodiodes, IR Phototransistors, and IR Photodarlingtons that can be used as IR Sensors. Depending on how sensitive you need your sensor or receiver to be, any of those devices could be suitable, or can be made suitable by connecting them to a transistor amplifier or even a driver IC.

ottoj (author)sauravd32015-10-10

An example of an IR Receiver is the part in the TV or Disc Player that gets instructions from the wireless remote. The signal from the remote is detected and decoded into serial (digital) data indication which button is being pressed.

An example of an IR Sensor is one of those non-contact thermometers that you can aim at something (most have an integrated laser pointer to show what point it is aimed at) and it will tell you what the temperature is at that point. The temperature is an analog infrared (IR) measurement that is converted into data for the display in the thermometer.

Sumanta.Bee (author)2014-08-27

u need to connect a higher resistance value to the led. it is glowing as yellow

About This Instructable

56,519views

52favorites

License:

Bio: Enjoys learning and playing with electronics and programming.
More by zx lee:How to use IR Sensor using Op amp and ArduinoDigital Clock Using 7 Segment Display controlled using TV RemoteDigital Alarm Clock Using 7 Segment Display
Add instructable to: