“(SKU:RB-02S042)夏普GP2Y0A02YK0F 红外测距传感器”的版本间的差异
来自ALSROBOT WiKi
第8行: | 第8行: | ||
# 功耗: 标称值33 mA | # 功耗: 标称值33 mA | ||
# 供电电压:4.5 to 5.5 V | # 供电电压:4.5 to 5.5 V | ||
− | == | + | ==数据分析图示== |
+ | [[文件:RB-02S042109.jpg|737px|缩略图|居中]] | ||
+ | [[文件:RB-02S042110.jpg|616px|缩略图|居中]] | ||
===引脚图=== | ===引脚图=== | ||
[[文件:RB-02S0421.jpg|500px|缩略图|居中]] | [[文件:RB-02S0421.jpg|500px|缩略图|居中]] | ||
− | == | + | ==应用例程1== |
+ | <pre style="color:blue"> | ||
+ | /* description: | ||
+ | The sample code is used to measure distance by GP2Y0A02YK IR ranger sensor. | ||
+ | VCC -- VCC | ||
+ | GND -- GND | ||
+ | Signal -- Analog 1 | ||
+ | */ | ||
+ | int IRpin = 1; // analog pin for reading the IR sensor | ||
+ | void setup() { | ||
+ | Serial.begin(9600); // start the serial port | ||
+ | } | ||
+ | void loop() { | ||
+ | float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3 | ||
+ | float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts) | ||
+ | Serial.println(distance); // print the distance | ||
+ | delay(100); // arbitary wait time. | ||
+ | } | ||
+ | |||
+ | </pre> | ||
+ | ==应用例程2== | ||
+ | <pre style="color:blue"> | ||
+ | /******** start code ********/ | ||
+ | /* | ||
+ | * created 2013-07-26 | ||
+ | * by lisper (leyapin@gmail.com) | ||
+ | * function test gp2y0a02yk, read value from A1 | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | //connect gp2y0a02 to A1 | ||
+ | #define pin A1 | ||
+ | |||
+ | void setup () { | ||
+ | Serial.begin (9600); | ||
+ | pinMode (pin, INPUT); | ||
+ | } | ||
+ | |||
+ | void loop () { | ||
+ | uint16_t value = analogRead (pin); | ||
+ | uint16_t range = get_gp2y0a02 (value); | ||
+ | Serial.println (value); | ||
+ | Serial.print (range); | ||
+ | Serial.println (" cm"); | ||
+ | Serial.println (); | ||
+ | delay (500); | ||
+ | } | ||
+ | |||
+ | //return distance (cm) | ||
+ | uint16_t get_gp2y0a02 (uint16_t value) { | ||
+ | if (value < 70) value = 70; | ||
+ | return 12777.3/value-1.1; //(cm) | ||
+ | //return (62.5/(value/1023.0*5)-1.1); //(cm) | ||
+ | //return ((67870.0 / (value - 3.0)) - 40.0); //gp2d12 (mm) | ||
+ | } | ||
+ | |||
+ | /******** end code ********/ | ||
+ | </pre> | ||
+ | <br><br><br> | ||
==产品相关推荐== | ==产品相关推荐== | ||
购买地址:[http://www.alsrobot.cn/goods-183.html 夏普GP2Y0A02YK0F 红外测距传感器] | 购买地址:[http://www.alsrobot.cn/goods-183.html 夏普GP2Y0A02YK0F 红外测距传感器] |
2015年7月1日 (三) 20:34的版本
目录 |
产品概述
GP2Y0A02YK0F是夏普的一款距离测量传感器模块。它由PSD(position sensitive detector) 和IRED (infrared emitting diode) 以及信号处理电路三部分组成。由于采用了三角测量方法,被测物体的材质、环境温度以及测量时间都不会影响传感器的测量精度。传感器输出电压值对应探测的距离。通过测量电压值就可以得出所探测物体的距离,所以这款传感器可以用于距离测量、避障等场合。
规格参数
- 距离测量范围:20 to 150 cm
- 信号输出类型:电压模拟信号
- 包装尺寸:29.5×13×21.6 mm
- 功耗: 标称值33 mA
- 供电电压:4.5 to 5.5 V
数据分析图示
引脚图
应用例程1
/* description: The sample code is used to measure distance by GP2Y0A02YK IR ranger sensor. VCC -- VCC GND -- GND Signal -- Analog 1 */ int IRpin = 1; // analog pin for reading the IR sensor void setup() { Serial.begin(9600); // start the serial port } void loop() { float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3 float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts) Serial.println(distance); // print the distance delay(100); // arbitary wait time. }
应用例程2
/******** start code ********/ /* * created 2013-07-26 * by lisper (leyapin@gmail.com) * function test gp2y0a02yk, read value from A1 * */ //connect gp2y0a02 to A1 #define pin A1 void setup () { Serial.begin (9600); pinMode (pin, INPUT); } void loop () { uint16_t value = analogRead (pin); uint16_t range = get_gp2y0a02 (value); Serial.println (value); Serial.print (range); Serial.println (" cm"); Serial.println (); delay (500); } //return distance (cm) uint16_t get_gp2y0a02 (uint16_t value) { if (value < 70) value = 70; return 12777.3/value-1.1; //(cm) //return (62.5/(value/1023.0*5)-1.1); //(cm) //return ((67870.0 / (value - 3.0)) - 40.0); //gp2d12 (mm) } /******** end code ********/