IR Sensor Interfacing with LPC2148

This article is a continuation of the series of tutorials on the LPC2148 Microcontroller (ARM7). The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the RF 434 Transceiver with LPC2148 (ARM7).  In this tutorial, we are going to see IR Sensor Interfacing with LPC2148.

Prerequisites

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

Components Required

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

 lpc2148 ir sensor

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.

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 LPC2148

Connection

IR Sensor

  • Vcc – 5v
  • GND – Ground
  • Out – P1.24

LCD

  • RS – P0.8
  • RW – P0.9
  • EN – P0.10
  • Data Lines – P0.0 – P0.7

IR Sensor Interfacing with LPC2148

Source Code

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

#include<lpc214x.h>
#define bit(x) (1<<x)
#define delay for(i=0;i<7000;i++);
 
#define IR (IO1PIN & (1<<24))
 
unsigned int i;
 
void lcd_int();
void dat(unsigned char);
void cmd(unsigned char);
void string(unsigned char *);
 
void main()
{
    IO0DIR =0XFFF;
    IO1DIR = 0x0;
    lcd_int();
    cmd(0x80);
    string("EMBETRONICX.COM ");
    while(1) {
            if(IR == 0) {
                    string("Obstacle Detcted");
            }
            delay;delay;
            cmd(0x01);
        }
}
 
void lcd_int()
{
    cmd(0x38);
    cmd(0x0c);
    cmd(0x06);
    cmd(0x01);
    cmd(0x80);
}
 
void cmd(unsigned char a)
{
    IO0PIN&=0x00;
    IO0PIN|=(a<<0);
    IO0CLR|=bit(8);                //rs=0
    IO0CLR|=bit(9);                //rw=0
    IO0SET|=bit(10);               //en=1
    delay;
    IO0CLR|=bit(10);               //en=0
}
 
void dat(unsigned char b)
{
    IO0PIN&=0x00;
    IO0PIN|=(b<<0);
    IO0SET|=bit(8);                //rs=1
    IO0CLR|=bit(9);                //rw=0
    IO0SET|=bit(10);               //en=1
    delay;
    IO0CLR|=bit(10);               //en=0
}
 
void string(unsigned char *p)
{
    while(*p!='\0') {
        dat(*p++);
    }
}

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 Bluetooth with LPC2148 (ARM7). If you want to use FreeRTOS on LPC2148, then please refer FreeRTOS series.

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
Bootloader TutorialsRaspberry PI Pico Tutorials
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