loading

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

    }

    <p>How would I do this if I don't have a buzzer but want to use an LED?</p>
    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 <br>Right??
    hi I have an IR with three legs what is the different <br>
    IR sensors have 3 pins but receivers not.
    <p>may i know which arduino is to be used??</p>
    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.
    <p>Bonjour, </p><p>Est il possible de faire plusieurs groupes de d&eacute;tection qui fonctionneraient ind&eacute;pendamment sur la m&ecirc;me unoarte? u</p>
    <p>I am sorry..</p>
    <p>can i use UNO R3 without DIP??</p>
    what is coding ?please tell it fast
    <p>Nice 'ible, but what Boogity said.<br><br>The two &quot;paragraphs&quot; above should read:</p><p>int IRemitter = 2; // IR emitter LED on digital pin 2 </p><p>int <br>ambientIR; // variable to store the IR coming from the <br>ambient </p><p>int obstacleIR; // variable to store the IR coming <br> from the object </p><p>int value[10]; // variable to store the <br>IR values </p><p>int distance; // variable that will tell if <br>there is an obstacle or not</p><p>and:</p><p> distance = readIR(5); // calling the function that will read <br>the distance and passing the &quot;accuracy&quot; to it </p><p>Serial.println(distance); // writing the read value on Serial monitor </p><p>// buzzer(); // uncomment to activate the buzzer <br>function }</p><p>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.</p>
    <p>Hi appytechie and thank you for the 'ible. I may be wrong but it seems that you forgot several &quot;ENTERS&quot; (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.</p>

    About This Instructable

    13,662views

    192favorites

    License:

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