Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

IR Sensor Infrared Obstacle Sensor Module Has Builtin IR Transmitter and IR Receiver That Sends Out IR Energy and Looks For

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

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 LPC2148

Connection

IR Sensor

● Vcc – 5v
● Gnd – Ground
● Out – P1.24
● Buzzer
● Buzzer is an electrical device, which is similar to a bell that makes a buzzing noise and is used for signaling.
Typical uses of buzzers and beepers include alarm devices, timers and confirmation of user input such as a mouse
click or keystroke.
● Interfacing Buzzer
● Fig. 1 shows how to interface the Buzzer to microcontroller. A piezoelectric element may be driven by an
oscillating electronic circuit or other audio signal source, driven with a piezoelectric audio amplifier. Sounds
commonly used to indicate that a button has been pressed are a click, a ring or a beep. When the input port pin
from microcontroller is changed, the sound wave is changed in Buzzer.

● Fig. 1 Interfacing Buzzer to Microcontroller 
● Interfacing Buzzer with LPC2148
● A small piezoelectric buzzer on the ARM7 LPC2148 Development Kit, by pulling pin P0.7 low, current will
flow through the buzzer and a relatively sharp, single-tone frequency will be heard.
● The alternative PWM feature of pin P0.7 (the PWM2 signal) can be used to modulate the buzzer to oscillate
around different frequencies. Then the volume of the sound will be changed by alternating the pulse width. The
buzzer can be disconnected by removing jumper JP1, and this is also the default position for this jumper since the
buzzer sound can be quite annoying if always left on.
● Pin Assignment with LPC2148

Buzzer Buzzer LPC2148 Buzzer Selection

 
I/P P0.7
LS1

● Circuit Diagram to Interface Buzzer with LPC2148


● Source Code
● The Interfacing Buzzer with LPC2148 program is very simple and straight forward. We now want to generate a
sound in LPC2148 Development Board by using a buzzer. The C programs are developed in Keil software.
● C Program to generate sound in LPC2148 using Buzzer
● #include

● #include

● #define BUZZ 7 void Delay(void);

● void Wait(void); void main()

● {

● PINSEL0 = 0x00;

● //Configure Port0.7 as GPIO IODIR0 = 3 << BUZZ;

● //Configure Port0.7 as O/P pin while(1)

● {

● IOSET0 = 1 << BUZZ;

● Delay();

● IOCLR0 = 1 << BUZZ; Delay();

● }

● }

● void Delay()

● {

● unsigned int i,j;

● for(i=0;i<1000;i++)

● for(j=0;j<700;j++);

● }

Ultrasonic Sensor

Components Required

● LPC2148 Development Board


● Ultrasonic Sensor [HC-SR04]
● LCD Module (To print the Distance)

Operation

1. Connect the Trigger pin of the HC-SR04 module to any I/O pins of LPC2148 controller and assign that Pin as a
output using IODIR.
2. Connect the Echo pin of the module to any I/O pins of LPC2148 controller and assign that Pin as a input using
IODIR.
3. Send a pulse of minimal timer period 10us, this will make the Ultrasonic module to send burst of data.
4. Now wait until that Echo pin goes high. Then Start the timer.
5. The reflected waves will be sensed by the module and it exhibits the output in Echo pin logic low or 0.
6. When the pulse from echo pin alters its state to logic 0 or low, then stop the timer.
7. The length of pulse from echo pin is proportional to the distance at which the object is located.
8. The value in the Timer gives the distance of course with some simple calculations.
CALCULATION

According to the data sheet the distance can be given by the formula :

Distance in cm = Timer /59

Distance in inch = Timer /148

Ultrasonic Sensor Interfacing with LPC2148

Connection

LCD:

● RS – P1.16
● RW – P1.17
● EN – P1.18
● Data Lines – P1.24 – P1.31

Ultrasonic Sensor:

● Trigger – P0.8
● Echo – P0.9
Code

Sending Trigger Pulse

void send_pulse()
{
T0TC=T0PC=0;
IO0SET=trig;

void send_pulse()
1 {
2     T0TC=T0PC=0;
3     IO0SET=trig;                            //trig=1
4     timer1delay(10);                        //10us
5
6 delay
7     IO0CLR=trig;                            //trig=0
}

Here I’m making timer value to zero. Then we are giving high to trigger pin (1). We have to wait for 10u Seconds. So
i’m using generating 10us delay using timer 1. Then make trigger pin to low (0).

Distance Calculating

unsigned int get_range()


{
unsigned int get=0;
send_pulse();

1 unsigned int
2 get_range()
3
4
5
6
{
7
    unsigned int get=0;
8
    send_pulse();
9
    while(!echo);
1
    T0TCR=0x01;
0
    while(echo);
1
    T0TCR=0;
1
    get=T0TC;
1
 
2
    if(get<38000)
1
        get=get/59;
3
    else
1
        get=0;
4
 
1
    return get;
5
}
1
6
1
7

This is the full function to calculate the distance.

1. First i’m sending trigger pulse.


2. Then waiting until that echo pin goes high (1). Then we have to start the Timer 0.
3. Again i’m waiting until that echo goes low (0). If it goes to zero, we have to stop the Timer 0.
4. Then I’m taking value from timer register.
5. Then using above formula i can calculate the Distance.

Full Code

Here I’m using Two timers. Timer 0 will be used for find the distance. And timer 1 will be used for Generating 10us
Delay. Then I’m Printing the distance in LCD Module. Here PCLK will be 60MHz. You can download the full project
here.

Main.c

#include<lpc214x.h>
#include"TIMER.H"
#include"ULTRASONIC.H"
#include"LCD.H"

1 #include<lpc214x.h>
2 #include"TIMER.H"
3 #include"ULTRASONIC.H"
4 #include"LCD.H"
5  
6 #define delay for(i=0;i<65000;i++);
7  
8 unsigned int range=0,i;
9  
1 int main()
0 {
1
1
1
2
1
3
1
4
1
5     VPBDIV=0x01;                 // PCLK =
1 60MHz
6     IO1DIR=0xffffffff;
1     ultrasonic_init();
7     lcd_init();
1     show("Distance : ");
8  
1     while(1) {
9         cmd(0x8b);
2         range=get_range();
0         dat((range/100)+48);
2         dat(((range/10)%10)+48);
1         dat((range%10)+48);
2         show("cm");
2         delay;
2         delay;
3     }
2 }
4
2
5
2
6
2
7
2
8

ULTRASONIC.H

#define trig (1<<8) //P0.8


#define echo (IO0PIN&(1<<9))

void ultrasonic_init();

1 #define trig (1<<8)             //P0.8


2 #define echo (IO0PIN&(1<<9))         //P0.9 as
3 EINT3
4  
5 void ultrasonic_init();
6 void send_pulse();
7 unsigned int get_range();
8  
9 void ultrasonic_init()
1 {
0     IO0DIR|=(1<<8);
1     T0CTCR=0;
1     T0PR=59;
1 }
2  
1 void send_pulse()
3 {
1     T0TC=T0PC=0;
4     IO0SET=trig;                            //trig=1
1     timer1delay(10);                        //10us delay
5     IO0CLR=trig;                            //trig=0
1 }
6  
1 unsigned int get_range()
7 {
1     unsigned int get=0;
8     send_pulse();
1     while(!echo);
9     T0TCR=0x01;
2     while(echo);
0     T0TCR=0;
2     get=T0TC;
1  
2     if(get<38000)
2         get=get/59;
2     else
3         get=0;
2  
4     return get;
2 }
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9

LCD.H

#define bit(x) (1<<x)

void lcd_init();
void cmd(unsigned char a);

1 #define bit(x) (1<<x)


2  
3 void lcd_init();
4 void cmd(unsigned char a);
5 void dat(unsigned char b);
6 void show(unsigned char *s);
7 void lcd_delay();
8  
9 void lcd_init()
1 {
0     cmd(0x38);
1     cmd(0x0e);
1     cmd(0x06);
1     cmd(0x0c);
2     cmd(0x80);
1 }
3  
1 void cmd(unsigned char a)
4 {
1     IO1PIN&=0x00;
5     IO1PIN|=(a<<24);
1     IO1CLR|=bit(16);                  
6 //rs=0
1     IO1CLR|=bit(17);                  
7 //rw=0
1     IO1SET|=bit(18);                    //en=
8 1
1     lcd_delay();
9     IO1CLR|=bit(18);                    //en
2 =0
0 }
2  
1 void dat(unsigned char b)
2 {
2     IO1PIN&=0x00;
2     IO1PIN|=(b<<24);
3     IO1SET|=bit(16);                   //rs=1
2     IO1CLR|=bit(17);                  
4 //rw=0
2     IO1SET|=bit(18);               //en=1
5     lcd_delay();
2     IO1CLR|=bit(18);               //en=0
6 }
2  
7 void show(unsigned char *s)
2 {
8     while(*s) {
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
        dat(*s++);
8
    }
3
}
9
 
4
void lcd_delay()
0
    {
4
    unsigned int i;
1
    for(i=0;i<=1000;i++);
4
}
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1

TIMER.H

void timer0delay(unsigned int a)


void timer1delay(unsigned int b)

void timer0delay(unsigned int a)

1 void timer0delay(unsigned int a);


2 void timer1delay(unsigned int b);
3
4
5
6
7
8
9
1
 
0
void timer0delay(unsigned int
1
a)    //1ms
1
{
1
    T0CTCR=0X0000;
2
    T0PR=59999;
1
    T0MR0=a;
3
    T0MCR=0x00000004;
1
    T0TCR=0X02;
4
    T0TCR=0X01;
1
    while(T0TC!=T0MR0);
5
    T0TC=0;
1
}
6
 
1
void timer1delay(unsigned int b)   //1u
7
s
1
{
8
    T1CTCR=0X0000;
1
    T1PR=59;
9
    T1MR0=b;
2
    T1MCR=0x00000004;
0
    T1TCR=0X02;
2
    T1TCR=0X01;
1
    while(T1TC!=T1MR0);
2
    T1TC=0;
2
}
2
3
2
4
2
5
2
6

You might also like