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
- TVs
- Personal computers
- Cars
- Copiers
- Robots
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. 1 Analog voltage output (V) versus distance to reflective object (cm).
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. } }