How to detect objects with IR proximity sensor and Arduino Uno?

IR proximity sensors are the most commonly used sensors in wireless technology and are often used for remote control and detection of surrounding objects/obstacles. When there is an obstacle in the surrounding, the sensor will output "0" or "1" level in digital form. This project demonstrates the use of IR sensor, the BOM table is as follows:
IR sensor module x1
RED LED x1
220 ohm resistor x1
Arduino development board x1
USB cable x1
jumper several


Get to know IR sensors

 

IR sensors also sense heat and motion by emitting and detecting IR radiation to find certain objects/obstacles within their range. IR sensors use infrared radiation with wavelengths between 0.75-1000 μm, which is between the visible and microwave regions of the electromagnetic spectrum, and the IR region is invisible to the human eye.

Since any object whose temperature is not equal to absolute zero (0 Kelvin) will emit radiation, and the total energy emitted by a black body at all wavelengths is related to absolute temperature, an IR sensor contains both an IR transmitter, an IR receiver, and a signal processing circuit to detect surrounding objects. test. Typical characteristics of IR proximity sensors are as follows:
IR receiver with ambient light protection 
3 pin interface connector
LED & Power LED indicator
2-30cm away from
"low" level when objects appear,
working voltage 3.3-5V

Circuit diagram and code

 

The connection between the IR sensor sensor and the Arduino development board is simple. The VCC and GND pins of the sensor module are connected to the 5v and GND pins of the Arduino development board, and the output pin pin OUT of the sensor is connected to the digital pin PIN 8 of the Arduino UNO.

In order to conveniently check the detection status, the project connects an LED to the PIN pin of the Arduino development board.

int IRSensor = 8; // connect ir sensor to arduino pin 2
int LED = 13; // conect Led to arduino pin 13
void setup()
{
 pinMode (IRSensor, INPUT); // sensor pin INPUT
 pinMode (LED, OUTPUT); // Led pin OUTPUT
 Serial.begin(9600);
 delay(500);
 Serial.println("Welcome to Microdigisoftn");
}
void loop()
{
 delay(1000);
 Serial.print("IR Sensor value=  ");
 Serial.println(digitalRead(IRSensor));
 int statusSensor = digitalRead (IRSensor);
 if (statusSensor == 1)
   digitalWrite(LED, LOW); // LED LOW
 else
 {
   digitalWrite(LED, HIGH); // LED High

 }
}

 

The sensor digitally outputs a logic 0 (0V) when an object appears in front of the IR sensor and a logic 1 (+5V) if there is no object in front.

At the same time, when an object appears in front of the IR sensor, the LED will light up. If an object is removed from the front of the sensor, the LED will automatically turn off.

Top