IR Sensor Infrared Obstacle Sensor Module Has Builtin IR Transmitter and IR Receiver That Sends Out IR Energy and Looks For
IR Sensor Infrared Obstacle Sensor Module Has Builtin IR Transmitter and IR Receiver That Sends Out IR Energy and Looks For
IR Sensor Infrared Obstacle Sensor Module Has Builtin IR Transmitter and IR Receiver That Sends Out IR Energy and Looks For
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
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.
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
●
I/P P0.7
LS1
● 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
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 :
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
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
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
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
void ultrasonic_init();
LCD.H
void lcd_init();
void cmd(unsigned char a);
TIMER.H