Skip to content

Interfacing IR Proximity Sensor with P89V51RD2

Introduction

Proximity detection sensors measure reflected infrared (IR) energy to detect the presence of an object or person. Following this guide will teach you how to interface the IR proximity sensor to the P89V51RD2.

Problem Statement

The goal is to create a circuit that allows us to control an LED's state by using an IR proximity sensor. When an object is detected the LED turns off and when there is no object the LED stays high.

Requirements

  1. P89V51RD2
  2. Breadboard
  3. LED
  4. IR Proximity Sensor
  5. Resistor (220-330 ohms)
  6. Jumper wires

Circuit Diagram

Getting Started Image

Code

  • Copy and paste the following code into main.c or download it from here:
c
#include <reg51.h>

void delay(void);

sbit ir = P0 ^ 0;
sbit led = P1 ^ 1;

void main()
{
    P0 = 0xFF; //assigning as input port
    P1 = 0x00; //assigning as output port

    while (1)
    {
        if (ir == 0)  
            led = 1;
        delay();
        if (ir == 1)
            led = 0;
        delay();
    }
}

void delay()  //delay function
{
    int i, j;
    for (i = 0; i < 500; i++)
    {
        for (j = 0; j < 1000; j++)
        {
        }
    }
}

Output

After burning the code to the P89V51RD2, the IR proximity sensor will continuously monitor its surroundings. The LED will be turned on when an object is detected within its range. If no object is detected, the LED will remain off.

Conclusion

By following this guide, you have successfully interfaced an IR proximity sensor with the P89V51RD2 microcontroller. The IR sensor can now detect the presence of an object, and the LED can provide a visible indication based on the detection status. This project can be extended to various applications, such as object detection systems, security systems, or automation projects.