Beginners Guide To IR Sensor and how to use it with Arduino

Содержание

Hey guys! Today we are going to learn about IR sensors, their working, types, and pinout. After covering the basics of IR sensors, you will learn how to use them with an Arduino board.

What is an IR Sensor?

IR sensor is a type of sensor which uses Infrared waves or light to detect the object placed ahead of it. Since this sensor uses Infrared waves to detect the object, it is called an Infrared sensor.

IR sensor

IR Sensor

Just like visible light, Infrared wave/light is part of the electromagnetic spectrum. But unlike sunlight/visible light, the human eye cannot see IR waves. Although it can be detected as heat.

You may not be aware that you encounter Infrared waves every day. For example, a TV remote uses light waves just beyond the visible spectrum of light—infrared light waves—to change channels on your TV.

And Ir sensor uses the same waves to detect the obstacle.

Board layout of an IR Sensor

Every IR Sensor or Infrared Sensor has two main parts. IR Transmitter and IR Reciever. The work of an IR transmitter or Infrared transmitter is to transmit the infrared waves.

Whereas the work of the IR receiver is to receive these transmitted infrared waves. IR receiver constantly sends digital data in the form of 0 or 1 to the Vout pin of the sensor.

The single potentiometer on most of the IR sensors is used to set the sensitivity of the sensor or the distance up to which it detects the obstacle. So by rotating the potentiometer you can set the detection distance.

There are generally two LEDs on the IR sensor, one is a power indicator and the other one is the output/obstacle indicator.

Different versions of IR sensor:

Now depending upon the number of Pins and potentiometer you may come across different versions of Ir Sensor.

IR sensor with three pins:

IR sensor

The IR sensor with three pins has the following pinout: Power pin, Ground pin, and digital output pin.

The digital output pin provides data in digital form i.e. 0(HIGH) or 1(HIGH)

IR sensor with four pins(Output type):

IR sensor with 4 pins(output type)

IR sensor with 4 pins(output type)

The IR sensor with four pins has the following pinout: Power pin, Ground pin, digital output, and analog output pin.

The analog output pin provides data in analog form i.e. between 0 volts and 5 volts(voltage at power pin)

IR sensor with four pins(Enabling/disabling):

IR Sensor with 4 pins(Enable)IR Sensor with 4 pins(Enable)

The IR sensor with four pins has the following pinout: Power pin, Ground pin, digital output pin, and Enable pin.

The enable pin is used to enable/disable the IR sensor output.

The IR sensor with Single potentiometer:

The single potentiometer on most of the IR sensors is used to set the sensitivity of the sensor or the distance up to which it detects the obstacle. So by rotating the potentiometer you can set the detection distance.

The IR sensor with Two potentiometers:

The second potentiometer is used to set the frequency of IR waves transmission.

Working of an IR Sensor

If there is an object in front of the IR sensor, the transmitted infrared waves from the IR transmitter reflect from that object and are received by the IR receiver. IR sensor gives 0 in this condition.

Similarly, if there is a white surface in front of the sensor, the IR waves are reflected back from the surface(the white surface does not absorb any light).

When there is no object in front of the IR sensor, the transmitted infrared waves from the IR transmitter are not received by the IR receiver. And IR sensor gives 1 in this condition.

Similarly, if there is a black surface in front of the sensor, the IR waves are not reflected back from the surface(the black surface absorbs the light completely).

IR sensor pinout(3 pins):

**IR receiver constantly sends digital data in the form of 0 or 1 to the Vout pin of the sensor.

IR sensor pinout(4 pins):

**IR receiver constantly sends digital data in the form of 0 or 1 to the Vout pin of the sensor.

Watch this video for a detailed explanation :

How to use Arduino with IR Sensor:

Circuit Connections:

Connect the Vout pin of the sensor to digital pin 7 of Arduino.

Connect the Vin pin of the sensor to the 5 V pin of Arduino.

Connect the Ground pin of the sensor to the GND pin of Arduino.

Connect the LED to digital pin 13.

Program: LED Control using IR Sensor input

13 thoughts on “Beginners Guide To IR Sensor and how to use it with Arduino”

Hi
I want to build circuit with 2 relays , IR sensor and manual switch.
I have a problem with code sketch. Please send me email to trucker.poland @gmail com and let me know if are you able to help me or not .
Please answer as soon as possible.
Kind regards Greg

Hello,
I want to control 5 Led’s with 5 Ir detectors. How do I change the code to do this?

Hi Gary,
Do you want to control each LED from an individual sensor? Please provide more details so that we can help you out.

Ankit,
Yes I would like to control 5 or 6 LED’s with indivdual sr 505 IR sensors. The object is
to know the location of a model train in a tunnel.
Thanks,
Gary

yes Ankit,
five or six SR501 infrad detectors controlling one Led each. I would like to use a arduino nano for this.
I am trying to tell the location of a model trains location in a tunnel.
Thank you for your quick response.

Hi Gary,
I have compiled this code for you as fast as I could. I haven’t tested it on the actual setup but this should work.

Controlling 5 different LEDs from 5 different IR Sensors:

You can use serial commands for real-time sensor data collection.
Let me know if this works or not.

Ankit,
I have had a quick test with two IR detectors (waiting for the mail to bring more) and it does
work. I am not sure what you mean by using serial commands?

I guess I would have to add the command: serial.begin (9600); but not sure were it goes.

This is my first attempt with arduino and I really appreciate the help.
Gary

Hi Gary,
Serial commands are used for serial communication between the Arduino board and Arduino software to receive data(such as from the sensor, keyboard)/send data. The data gets printed onto the Serial monitor of the Arduino software. You can also send data to the Arduino board using this serial monitor(using appropriate serial commands).
In your case, you can use the Serial monitor to print the real-time sensor readings(0 or 1) for sensor calibration and better control.
Serial.begin(9600) command initialize the communication hence goes into the void setup(). Any other serial command will not work if this is not used in void setup().
And I understand that learning Arduino can be very difficult if you are an absolute beginner.
You can learn Arduino programming from the internet/youtube as there are a ton of quality material available there. If you like, you can also go through this article on Arduino programming for beginners posted on our website:
Beginners guide to Arduino programming

Got it working with the serial. Thanks again for
the help Ankit.
Gary


Источник: www.etechnophiles.com