Está en la página 1de 7

Infrared Proximity Sensors

Application Note

By Vashishtha Kadchhud
Design Team 08
ECE 480, Spring 2007

Abstract:
This paper discusses the implementation of a Sharp infrared proximity sensor to
measure the distance of an object from the sensor. The Infrared sensors are used along
with a microprocessor with Analog to Digital Voltage conversion capability and clock to
create a simple circuitry to measure distance. This paper will elaborate on how the
infrared proximity sensor is connected and communicates with the microprocessor and
the software implemented based on the data provided for the sensors.

Introduction:
Infrared sensors are available in various forms, it can be an emitter and detector
by itself operating at the same wavelength, a emitter and detector housed in the same unit
or a like a photoelectric sensor which works with reflective surfaces. The major
categories of infrared sensor are retro-reflective sensors, diffuse reflection sensor and
Through Beam Sensors. Each of these sensors has its own advantage based on the
application it is being used for. A through beam works great in assembly lines and in
close ranges. A Retro-reflective is really durable and works well where there are harsh
environment. A diffuse reflective is useful where only partial light is reflected back.
In this application note, we will be using the Sharp GP2D120 which is an Analog
infrared sensor working on the diffuse principle. The Sharp GP2D120 measures analog
voltage which when the transmitted beam is reflected back from the object. This analog
voltage can be translated into distance.

1 2 3

GP2D120

The picture above shows a Sharp GP2D120. The LED on the left is an emitter, while the
bigger lens on the right is a detector. The pin layout for the sensor is essential while
wiring it up.

Pin Layout for GP2D120:


Pin Number

Symbol

V0

GND

Vcc

Hardware Requirement:
1. Sharp GP2D120 Sensor
2. Microprocessor (PIC 18F4520)
3. Microchip MPLAB ICD 2
4. Microchip MPLAB IDE
5. 40 MHz Clock Crystal
6. Winford R11 Header
7. 5V Power Supply
8. 10K resistor
9. 1uF Capacitor
10. 1pF Capacitor
11. Protoboard

Rating
Analog Output
-0.3 to Vcc 0.3

-0.3 to +7 V.
But operated at 5V

Implementation:
Wiring the Protoboard:
The PIC18F4520 is used to do an analog to digital conversion of the voltage
obtained from the infrared sensor. The PIC provides us with 13 analog to digital
conversion pins and in total 40 pins. In this setup we will only be using one A to D
conversion pin.

Wiring Diagram for Sharp GP2D120 IR Sensor

The output coming out of pin 3 of the Sharp GP2D120 sensor is wired to pin 2 on
the PIC. Pin 2 is an AN0 port which performs an A to D conversion at the users request.
One of the important things to do is to wire the 1uF and 1 pF capacitors at the power bus
and Vdd of the PIC. This is done to prevent the sensor from absorbing all the current and
the PIC seeing a big voltage drop, preventing it from performing the functions.

Software/Algorithm Implementation:
The infrared sensors analog output voltage to distance from the object can be
graphed. A typical graph for the analog output voltage vs. distance from the object
GP2D120 looks like

This is very valuable information in our setup. The graph is almost linear for the
first 4cms and then is exponentially decaying; we will try and operate in the
exponentially decaying curve of the graph. This is done so we dont get any errors in the
reading. Say if we got our voltage as 0.8 V we would have two distances that correspond
to 0.8 V. By operating on one side of the graph we can eliminate the other reading. When
we implement our code this will be taken into consideration.

Code:

#include <p18cxxx.h>
#include <ADC.h>
#pragma config WDT=OFF
long int count,j;
double distance,height,R,conv;
int adc_result1;
void main()
{
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,ADC_CH0 & ADC_INT_OFF,
0); //open adc port for reading
ADCON1 =0x00; //set VREF+ to VDD and VREF- to GND (VSS)
for(;;)
{

SetChanADC(ADC_CH0); //Set ADC to Pin 2


ConvertADC(); //perform ADC conversion
while(BusyADC()); //wait for result
adc_result1 = ReadADC(); //get ADC result
conv=adc_result1*(5/1024);
distance=adc_result/2.87;

}
}

Calibration:
In order to determine the distance of the object a reference table is created for the
sensor based on the graph. The voltage converted by the PIC is checked against this
reference table to determine the distance. A separate reference table needs to be created
for each sensor since they have a small difference.

Conclusion:
The application note covers the principle, implementation and application of the
analog infrared sensor Sharp GP2D120. It shows the basics of how to wire the sensor,
how to program the PIC and implement a code to work with the sensor.

Recommendation:
Calibrating every individual sensor is a time consuming and challenging task. A
better way of determining the distance could be by using the line of best fit for the graph
provided in the data sheet as compared to creating a reference table for each sensor. This
can be done in the coding.

References:
a. http://www.hobbyengineering.com/H1060.html
Data sheet for Sharp GP2D120 and information.
b. http://www.acroname.com/robotics/parts/R146-GP2D120.html
Information in regards to application of GP2D120
c. http://ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf
Data sheet for PIC1854520
d. http://www.egr.msu.edu/classes/ece480/goodman/ForMiniprojects/
MPLAB and A to D conversion help

También podría gustarte