Interfacing IR sensor with Arduino !!..



This post is intended to help beginners to interface IR Sensor with Arduino. IR sensor can be bought from our online store by clicking here


  • ATmega328P microcontroller
  • Input voltage – 7-12V
  • 14 Digital I/O Pins (6 PWM outputs)
  • 6 Analog Inputs
  • 32k Flash Memory
  • 16Mhz Clock Speed

Below shows the picture used to interface the IR sensor with Arduino


  • IR Sensor has three pins(GND,V,OUT).
  • It works under 5v. Connect V pin of sensor with Arduino 5v
  • GND pin of IR connected to GND of Arduino
  • Interface OUT pin of sensor with 2 nd pin of Arduino

//Sample Code to check the working of IR sensor

const int IR_Sensor=2;

void setup() {

// initialize the digital pin as an output.

// Pin 13 has an LED  on  Arduino boards:

pinMode(13, OUTPUT);

//Pin 2 is connected to the output of IR_Sensor



void loop() {

if(digitalRead(IR_Sensor)==HIGH)      //Check the sensor output


digitalWrite(13, HIGH);   // set the LED on




digitalWrite(13, LOW);    // set the LED off


delay(1000);              // wait for a second




Connect the A to B  cable to the USB port of a computer and make sure that the port has been detected by checking the Device Manager option.


Open two Arduino IDE window and Select Arduino UNO as Board and select the appropriate COM port.

  • Board: Tools > Board > Arduino/Geniuno UNO.


  • Port: Tools > Port in Arduino.


  1. Compile and upload this program to your Arduino Uno board via Arduino IDE
  2. Place the object in front of IR proximity sensor and observe the change in LED connected to Pin 13 (on board LED)
  3. When you remove object you will see it gets turned off.


If you wish to change pin numbers then you can do so by varying the pin number in the program line const int IR_sensor=2

5 thoughts on “Interfacing IR sensor with Arduino !!..

  1. Pingback: Ir Sensor Arduino – AKAPHP

  2. hello sir,
    in this demonstration when obstacles are in front of ir then the output is high.
    but the the things is i want to do that output remain for only 2 sec when obstacle is put continuously in front of IR sensor

  3. Hii i interfaced atmega 8051 microcontroller to IR control the automatic lights on & off through Relay boards, distance was getting in LCD display correctly but relay was operating in reverse condition how it was happen ???

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