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.
Figure1: IR sensor
IR LED Emitter:
- It will also emit the light.
- When the object occur it will produce light
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:
- int IRpin = A0;
- int IRemitter = 2;
- int ambientIR;
- int obstacleIR;
- int value[10];
- int distance;
- void setup()
- {
- Serial.begin(9600);
- pinMode(IRemitter, OUTPUT);
- digitalWrite(IRemitter, LOW);
- pinMode(11, OUTPUT);
- }
- void loop()
- {
- distance = readIR(5);
- Serial.println(distance);
-
- }
- int readIR(int times)
- {
- for (int x = 0; x < times; x++)
- {
- digitalWrite(IRemitter, LOW);
- delay(1);
- ambientIR = analogRead(IRpin);
- digitalWrite(IRemitter, HIGH);
- delay(1);
- obstacleIR = analogRead(IRpin);
- value[x] = ambientIR - obstacleIR;
- }
- for (int x = 0; x < times; x++) {
- distance += value[x];
- }
- return (distance / times);
- }
- void buzzer()
- {
- if (distance > 1)
- {
- if (distance > 100)
- {
- digitalWrite(11, HIGH);
- } else
- {
- digitalWrite(11, HIGH);
- delay(150 - distance);
- digitalWrite(11, LOW);
- delay(150 - distance);
- }
- } else
- {
- digitalWrite(11, LOW);
- }
- }
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.
Figure 3: Output
Read more articles on Arduino: