Infrared Sensor Tutorial

Infrared Proximity Detection

Objective

This experiment demonstrates the use of an infrared sensor to detect objects in proximity, useful in robotics and automation systems.

Required Components

Working Principle

The infrared sensor detects objects by emitting infrared light and measuring the reflection. If the light is reflected, the sensor detects the object’s proximity.

Circuit Diagram

Infrared Sensor Circuit Diagram

Connect the sensor as follows:

Arduino Code


/*
 * Infrared Proximity Detection
 * This code detects an object within the range of the infrared proximity sensor.
 */

const int irSensorPin = 2;  // Infrared sensor connected to digital pin 2
int sensorState = 0;

void setup() {
    Serial.begin(9600);  // Initialize serial communication
    pinMode(irSensorPin, INPUT);  // Set the IR sensor pin as input
}

void loop() {
    // Read the infrared sensor
    sensorState = digitalRead(irSensorPin);

    // If an object is detected
    if (sensorState == HIGH) {
        Serial.println("Object Detected!");
    } else {
        Serial.println("No Object.");
    }

    delay(500);  // Wait for 0.5 seconds
}
            

Results

The serial monitor will display "Object Detected!" when the infrared sensor detects an object and "No Object" when no object is in range.

Applications

Conclusion

The infrared proximity sensor is a practical component for detecting objects, with applications in robotics, automation, and security systems.