Introduction: IR PROXIMITY SENSOR

Hello guys! In this Instructable I'll teach you how to make a very simple proximity sensor using infrared LEDs and Arduino.After several times trying to optimize it, I finally came up with something that is quite simple e precise. Just like my first Instructable, this project is perfect for beginners in the arduino's world, with a few components anyone can make it. I hope you all enjoy it.

Step 1: WHAT IS a PROXIMITY SENSOR :-

A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact. A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for instance), and looks for changes in the field or return signal.

So now we will be able to build this sensor using arduino. let's get started.

Step 2: ELECTRONICS REQUIRED :-

    Step 3: ELECTRONICS REQUIRED :-

    • Piezo buzzer
    • Jumper wires
    • Arduio uno
    • IR emitters
    • IR reciever

    Be careful to don't mix up the LED receiver with the normal LED, they all look the same.

    Step 4: BUILDING ELECTRONICS:-

    Connect the resistor from the 5V pin to the anode pin of the IR LED receiver. All the anodes pins of the IR LEDs emitters to the digital pin 2. A wire goes from the analog pin 0 to the anode pin of IR LED receiver. Don't forget to connect all the cathode pins of the LEDs to the ground pin.The buzzer is optional, but if you are using it connect to the digital pin 11 and the ground.Infrared light isn't visible to naked eye, but you can see it thru a digital camera, it helps to see if the LED is working or not.Take a look at the pics.

    Step 5: CODING :-

    int IRpin = A0; // IR photodiode on analog pin A0

    int IRemitter = 2; // IR emitter LED on digital pin 2 int ambientIR; // variable to store the IR coming from the ambient int obstacleIR; // variable to store the IR coming from the object int value[10]; // variable to store the IR values int distance; // variable that will tell if there is an obstacle or not

    void setup(){

    Serial.begin(9600); // initializing Serial monitor

    pinMode(IRemitter,OUTPUT); // IR emitter LED on digital pin 2

    digitalWrite(IRemitter,LOW);// setup IR LED as off

    pinMode(11,OUTPUT); // buzzer in digital pin 11 }

    void loop(){

    distance = readIR(5); // calling the function that will read the distance and passing the "accuracy" to it Serial.println(distance); // writing the read value on Serial monitor // buzzer(); // uncomment to activate the buzzer function }

    int readIR(int times){

    for(int x=0;x

    //-- Function to sound a buzzer for audible measurements --// void buzzer(){

    if (distance>1){

    if(distance>100){ // continuous sound if the obstacle is too close

    digitalWrite(11,HIGH); }

    else{ // bips faster when an obstacle approaches

    digitalWrite(11,HIGH);

    delay(150-distance); // adjust this value for your convenience

    digitalWrite(11,LOW);

    delay(150-distance); // adjust this value for your convenience } }

    else{ // off if there is no obstacle

    digitalWrite(11,LOW); }

    }