IR PROXIMITY SENSOR

15,057

196

15

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

    }

    Share

      Recommendations

      • Big and Small Contest

        Big and Small Contest
      • Toys Contest

        Toys Contest
      • Make it Glow Contest 2018

        Make it Glow Contest 2018

      15 Discussions

      0
      None
      AlyssonR2

      3 years ago on Introduction

      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.

      2 replies
      0
      None
      AnserMAlyssonR2

      Reply 1 year ago

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

      0
      None
      AlyssonR2AnserM

      Reply 1 year ago

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

      0
      None
      AnserM

      1 year ago

      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

      0
      None
      MusaS4

      2 years ago

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

      0
      None
      AhmedA27

      2 years ago

      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??

      0
      None
      AhmedA27

      3 years ago

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

      1 reply
      0
      None
      kakash1AhmedA27

      Reply 2 years ago

      IR sensors have 3 pins but receivers not.

      temp_300226369.jpg
      0
      None
      MarethnoSanketH1

      Reply 2 years ago

      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.

      0
      None
      lepiou83

      3 years ago

      Bonjour,

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

      0
      None
      techno maker

      3 years ago

      what is coding ?please tell it fast

      0
      None
      Boogity

      3 years ago on Step 5

      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.