Interfacing IR sensor with Arduino !!..

Haii,

 

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

Features

  • 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

CONNECTION

  • 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

pinMode(IR_Sensor,INPUT);

}

void loop() {

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

{

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

}

else

{

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

}

delay(1000);              // wait for a second

}

TESTING

STEP 1:

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.

STEP 2:

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

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


STEP 3:

  • Port: Tools > Port in Arduino.

STEP 4:

  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.

NOTE:

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

Advertisements

4 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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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