IR Proxity Sensor Using Arduino

In this article, I will explain about the IR Proximity Sensor using Arduino.

Introduction

IR Proximity Sensor:

  • The IR Proximity sensor is to perceiver occurrence of any object without begin in contact with-it.
  • It senses the accurate distance of a particular object.
  • It will emit electromagnetic radiation.

     IR sensor
    Figure1: IR sensor

IR LED Emitter:

  • It will also emit the light.
  • When the object occur it will produce light

    IR Emitter
    Figure 2: IR Emitter

Parts Of List:

  • Arduino uno
  • IR Led Receiver
  • IR Emitter
  • Bread Board
  • Hookup Wires
  • Buzzer

Connection

Step 1: Fix the IR Receiver in the bread board.
Step 2: Fix the IR Emitter 4 in the bread board.

Connection Of Bread Board To Arduino:

Step 1: 
Take the IR Receiver Gnd pin to the Analog pin A0, then Vcc to the Digital pin 02.
Step 2: Take the IR Emitter connect the Gnd pins commonly then Vcc pins commonly.
Step 3: Connect to the Arduino uno board.
Step 4: Fix the buzzer in Arduino board.

Program:

  1. int IRpin = A0; // IR photodiode on analog pin A0  
  2. int IRemitter = 2; // IR emitter LED on digital pin 2  
  3. int ambientIR; // variable to store the IR coming from the ambient  
  4. int obstacleIR; // variable to store the IR coming from the object  
  5. int value[10]; // variable to store the IR values  
  6. int distance; // variable that will tell if there is an obstacle or not  
  7. void setup()  
  8. {  
  9.     Serial.begin(9600); // initializing Serial monitor  
  10.     pinMode(IRemitter, OUTPUT); // IR emitter LED on digital pin 2  
  11.     digitalWrite(IRemitter, LOW); // setup IR LED as off  
  12.     pinMode(11, OUTPUT); // buzzer in digital pin 11  
  13. }  
  14. void loop()  
  15. {  
  16.     distance = readIR(5); // calling the function that will read the distance and passing the "accuracy" to it  
  17.     Serial.println(distance); // writing the read value on Serial monitor  
  18.     // buzzer(); // uncomment to activate the buzzer function  
  19. }  
  20. int readIR(int times)  
  21. {  
  22.     for (int x = 0; x < times; x++)  
  23.     {  
  24.         digitalWrite(IRemitter, LOW); //turning the IR LEDs off to read the IR coming from the ambient  
  25.         delay(1); // minimum delay necessary to read values  
  26.         ambientIR = analogRead(IRpin); // storing IR coming from the ambient  
  27.         digitalWrite(IRemitter, HIGH); //turning the IR LEDs on to read the IR coming from the obstacle  
  28.         delay(1); // minimum delay necessary to read values  
  29.         obstacleIR = analogRead(IRpin); // storing IR coming from the obstacle  
  30.         value[x] = ambientIR - obstacleIR; // calculating changes in IR values and storing it for future average  
  31.     }  
  32.     for (int x = 0; x < times; x++) { // calculating the average based on the "accuracy"  
  33.         distance += value[x];  
  34.     }  
  35.     return (distance / times); // return the final value  
  36. }  
  37. void buzzer()  
  38. {  
  39.     if (distance > 1)  
  40.     {  
  41.         if (distance > 100)  
  42.         {  
  43.             digitalWrite(11, HIGH);  
  44.         } else  
  45.         {  
  46.             digitalWrite(11, HIGH);  
  47.             delay(150 - distance); // adjust this value for your convenience  
  48.             digitalWrite(11, LOW);  
  49.             delay(150 - distance); // adjust this value for your convenience  
  50.         }  
  51.     } else  
  52.     {  
  53.         digitalWrite(11, LOW);  
  54.     }  
  55. }
Explanation:
  • In this article it can be used to detect the object at a particular distance.
  • It can display the distance of an object in the Serial Monitor accurately.
  • If they have the signal of the object it will produce the sound when it reaches the signal.

    Output
                Figure 3: Output
Read more articles on Arduino: