IR Sensor Interfacing With 8051

In our previous tutorial, we have seen how to interface the PIR sensor with 8051. In this tutorial, we are going to see IR Sensor Interfacing with 8051.

Prerequisites

Before starting this tutorial we should know the below topics. If you know already, please go further.

Components Required

  • 8051 Development Board
  • IR Sensor
  • LCD Module (To print the Sensor output)

Introduction

Infrared is light that has a wavelength longer than visible red light. The ranges of infrared include near-infrared, mid-infrared, and far-infrared, spanning wavelengths from about 710 nanometers (near-infrared) to 100 micrometers (far infrared).

All objects emit light according to their temperature–this is called “black body radiation.” The hotter the object, the shorter wavelength of light it emits. The Earth emits infrared light at a peak of about nine to 10 micrometers–and so do warm-blooded animals like humans. This light can be used to detect motion or warmth.

IR Sensor

The infrared Obstacle Sensor Module has a built-in IR transmitter and IR receiver that sends out IR energy and looks for reflected IR energy to detect the presence of any obstacle in front of the sensor module. The PCB of this electronic circuit has a potentiometer. That onboard potentiometer lets users adjust the detection range. The sensor has a very good and stable response even in ambient light or in complete darkness.

Specifications

  • Operating Voltage: 3.0V – 5.0V
  • Detection range: 2cm – 30cm (Adjustable using potentiometer)
  • Current Consumption:at 3.3V : ~23 mA,at 5.0V: ~43 mA
  • Active output level: Outputs Low logic level when an obstacle is detected
  • Onboard Obstacle Detection LED indicator

Working Principle of IR Obstacle Sensor

An IR sensor consists of an IR LED and an IR Photodiode; together they are called as Photo–Coupler or Opto–Coupler. As said before, the Infrared Obstacle Sensor has a built-in IR transmitter and IR receiver. An infrared Transmitter is a light-emitting diode (LED) that emits infrared radiations. Hence, they are called IR LED. Even though an IR LED looks like a normal LED, the radiation emitted by it is invisible to the human eye.

IR Sensor Interfacing

Infrared receivers are also called as infrared sensors as they detect the radiation from an IR transmitter. IR receivers come in the form of photodiodes and phototransistors. Infrared Photodiodes are different from normal photodiodes as they detect only infrared radiation. When the IR transmitter emits radiation, it reaches the object and some of the radiation reflects back to the IR receiver. Based on the intensity of the reception by the IR receiver, the output of the sensor is defined.

IR Sensor Interfacing with 8051

Connection

IR Sensor

  • Vcc – 5v
  • GND – Ground
  • Vout – P1.0

LCD

  • RS – P2.0
  • RW – P2.1
  • EN – P2.2
  • Data Lines – P3.0 – P3.7

IR Sensor Interfacing with 8051

Source Code

If it is detecting an object in front of this sensor, LCD will display “Obstacle Detected”.

#include<reg51.h>
#define lcd P3

sbit IR=P1^0;

sbit rs=P2^0; //register select
sbit rw=P2^1; //RW
sbit en=P2^2; //enable

void lcd_init();
void cmd(unsigned char);
void dat(unsigned char);
void delay();
void lcd_string(char *s);

void main()
{
    lcd_init();
    lcd_string("  EmbeTronicX   ");
    while(1) {
        if(IR == 0) {
            cmd(0xc0);
            lcd_string("Obstacle Detected");
            delay();
        } else {
            cmd(0xc0);
            lcd_string("                ");
        }
    }
}

void lcd_init()
{
    cmd(0x38);
    cmd(0x0e);
    cmd(0x06);
    cmd(0x01);
    cmd(0x80);
}

void cmd(unsigned char a)
{
    lcd=a;
    rs=0;
    rw=0;
    en=1;
    delay();
    en=0;
}

void dat(unsigned char b)
{
    lcd=b;
    rs=1;
    rw=0;
    en=1;
    delay();
    en=0;
}

void lcd_string(char *s)
{
    while(*s) {
       dat(*s++);
     }
}

void delay()
{
    unsigned int i;
    for(i=0;i<20000;i++);
}

If you want to sense more distance you can use below IR sensor. You can also adjust the distance using this. This is an Infrared Transmitter and receiver which together make up a photoelectric sensor. The sensor has a long detection distance and has less interference by visible light because it uses modulated Infrared light. This sensor has a screwdriver adjustment to set the detected distance, then gives a digital output when it senses something within that range. This sensor does not return a distance VALUE.

 

 

In our next tutorial, we will see how to interface the GPS with 8051.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
STM32F7 Bootloader TutorialsRaspberry PI Pico Tutorials
STM32F103 Bootloader TutorialsRT-Thread RTOS Tutorials
Zephyr RTOS Tutorials - STM32Zephyr RTOS Tutorials - ESP32
AUTOSAR TutorialsUDS Protocol Tutorials
Product ReviewsSTM32 MikroC Bootloader Tutorial
VHDL Tutorials
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Table of Contents