Features
- Less influence on the color of reflective objects, reflectivity
- Line-up of distance output/distance judgement type
Distance output type (analog voltage) : GP2Y0A21YK
Detecting distance : 10 to 80cm
Distance judgement type : GP2Y0D21YK
Judgement distance : 24cm
(Adjustable within the range of 10 to 80cm [Optionally available]) - External control circuit is unnecessary
- Low cost
Applications
- TVs
- Personal computers
- Cars
- Copiers
- Robots
The output of this sensor is analog therefore it need Analog to Digital Converter (ADC) to interface the 8051. I use ads7841 as ADC (see this article).
The graph of Analog voltage output versus distance to reflective object are shown in Fig.1. When I plot Analog voltage output versus inverse number distance, I found the linear relation shown in Fig.2.
Fig. 2 Analog voltage output (V) versus inverse number distance (1/cm).
The linear equation is y = 20.99x + 0.19, where y is voltage output and x invert distance. Notice that the voltage output I can trust are about 0.4 to 2.8 V.
This is an example code how to interface the distance sensor to 8051. I use SDCC as C Compiler.
#include <8051.h>
#include "ads7841.h"void main()
{
float x,y; // Distance and Analog voltage output
y = analog(0); // Read volt out if the sensor connect to channel 0 of ADS7841
y = 0.00122*y; // Convert BCD to DEC by multiply voltage by 5/4096
if ( (y > 0.4) && (y < 2.8) ) {
x = (y-0.19)/20.99; // Solve the linear equation
x = 1/x; // Inverse back get distance in cm.
}
}
Source:
test_irsensor.c
characteristic.txt (For plot with Spreadsheet)
Related Links
GP2Y0A21YK/GP2Y0D21YK Datasheet
Analog to Digital (ADS7841) Interfacing
No comments:
Post a Comment