IR Sensor Interfacing With PIC16F877A

In this tutorial we are going to see IR Sensor Interfacing with PIC16F877A.

Prerequisites

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

Components Required

  • PIC16F877A 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

Infrared Obstacle Sensor Module has builtin IR transmitter and IR receiver that sends out IR energy and looks for reflected IR energy to detect presence of any obstacle in front of the sensor module. The module has on board potentiometer that lets user adjust detection range. The sensor has 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 obstacle is detected
  • On board 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 builtin IR transmitter and IR receiver. Infrared Transmitter is a light emitting diode (LED) which emits infrared radiations. Hence, they are called IR LED’s. Even though an IR LED looks like a normal LED, the radiation emitted by it is invisible to the human eye.

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 photo diodes 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 PIC16F877A

Connection

IR Sensor

  • Vcc – 5v
  • Gnd – Ground
  • Out – RD0 (PORTD.0)

LCD

  • RS – RC0
  • RW – RC1
  • EN –RC2
  • Data Lines – PORTB

IR Sensor Interfacing with PIC16F877A

Source Code

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

#include<htc.h>
 
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);
 
#define IR RD0                  //IR Output is connected at PORTD.0
 
#define rs RC0
#define rw RC1
#define en RC2
#define delay for(i=0;i<1000;i++)
 
int i;
 
void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
 
 
void main()
{
    TRISB=TRISC0=TRISC1=TRISC2=0;
    TRISD=0xff;                         //Port D act as Input
    lcd_init();
    cmd(0x80);
    show("   EmbeTronicX  ");
    while(1) {
        if(IR == 0) {
            cmd(0xc0);
            show("Obstacle Detcted");
            delay;delay;
        } else {
            cmd(0xc0);
            show("                ");
        }
    }
}
 
void lcd_init()
{
    cmd(0x38);
    cmd(0x0c);
    cmd(0x06);
    cmd(0x80);
}
 
void cmd(unsigned char a)
{
    PORTB=a;
    rs=0;
    rw=0;
    en=1;
    delay;
    en=0;
}
 
void dat(unsigned char b)
{
    PORTB=b;
    rs=1;
    rw=0;
    en=1;
    delay;
    en=0;
}
 
void show(unsigned char *s)
{
    while(*s)
    {
        dat(*s++);
    }
}

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
Ads Blocker Image Powered by Code Help Pro
Ad Blocker Detected!!!

Dear User,

Thanks for visiting the site. Unfortunately, we have noticed that you are using an Ad Blocker extension in your browser.

We charge advertisers instead of the audience. We depend on Ad revenue to keep creating quality content for you. We guarantee clean ads. 

HERE IS HOW YOU CAN KEEP READING!

Click the AdBlock icon on your browser and click Enabled on this site to Disable AdBlock in embetronicx.com or whitelist our website.

If you still want to hide the ads, please become a Premium member. If you are a premium member already, then please log in.

Thank you for understanding.

If you are seeing this even after disabling all the ad blockers, Please report us the False Positive to [email protected]

Refresh