Introduction: IR PROXIMITY SENSOR

Picture of 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:-

    Picture of 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); }

    }

    Comments

    AlyssonR2 (author)2015-08-11

    Nice 'ible, but what Boogity said.

    The two "paragraphs" above should read:

    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

    and:

    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 }

    For folks who like to tinker, modifying the circuit so that the LEDs may be indipendently switched on would allow a simple form of range measurement to be performed.

    AnserM (author)AlyssonR22017-09-27

    "readIR" was not declared in this scope!
    The software responds to it like that, what will u say about that?

    AlyssonR2 (author)AnserM2017-09-27

    You're going to have to debug the routine ReadIR yourself - it's summarised in the pseudocode in the article text.

    AnserM (author)2017-09-27

    Will you please provise the CODE in more better and authentic and 100% working form because the way that you have given tha code ia really really poor

    MusaS4 (author)2016-07-28

    How would I do this if I don't have a buzzer but want to use an LED?

    AhmedA27 (author)2016-01-18

    OK thanks but what is the different between try he sensor and the recover because both of them are doing the same job I think
    Right??

    AhmedA27 (author)2015-12-16

    hi I have an IR with three legs what is the different

    kakash1 (author)AhmedA272016-01-18

    IR sensors have 3 pins but receivers not.

    SanketH1 (author)2015-09-07

    may i know which arduino is to be used??

    Marethno (author)SanketH12016-01-13

    you can use any arduino or clone nano or micro. it depends on the atmega 328 or168 or8, arduino bootloader. don't worry. your arduino will work. you survey have the SMD atmega version on it.

    lepiou83 (author)2015-10-11

    Bonjour,

    Est il possible de faire plusieurs groupes de détection qui fonctionneraient indépendamment sur la même unoarte? u

    SanketH1 (author)2015-09-07

    I am sorry..

    SanketH1 (author)2015-09-07

    can i use UNO R3 without DIP??

    techno maker (author)2015-08-28

    what is coding ?please tell it fast

    Boogity (author)2015-08-10

    Hi appytechie and thank you for the 'ible. I may be wrong but it seems that you forgot several "ENTERS" (or carriage returns) in your text for the sketch code. Would you please make the necessary corrections so that beginners can understand the code without problems? Thanks.

    About This Instructable

    14,365views

    194favorites

    License:

    More by appytechie:Program the Linkit One Using a Raspberry PILinkit One Controlled El-wireLinkit One - Dice
    Add instructable to: