“(SKU:RB-02S042)夏普GP2Y0A02YK0F 紅外測距傳感器”的版本間的差異
來自ALSROBOT WiKi
第8行: | 第8行: | ||
# 功耗: 標稱值33 mA | # 功耗: 標稱值33 mA | ||
# 供電電壓:4.5 to 5.5 V | # 供電電壓:4.5 to 5.5 V | ||
? | == | + | ==數(shù)據(jù)分析圖示== |
+ | [[文件: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> | ||
==產(chǎn)品相關推薦== | ==產(chǎn)品相關推薦== | ||
購買地址:[http://gharee.com/goods-183.html 夏普GP2Y0A02YK0F 紅外測距傳感器] | 購買地址:[http://gharee.com/goods-183.html 夏普GP2Y0A02YK0F 紅外測距傳感器] |
2015年7月1日 (三) 20:34的版本
目錄 |
產(chǎn)品概述
GP2Y0A02YK0F是夏普的一款距離測量傳感器模塊。它由PSD(position sensitive detector) 和IRED (infrared emitting diode) 以及信號處理電路三部分組成。由于采用了三角測量方法,被測物體的材質(zhì)、環(huán)境溫度以及測量時間都不會影響傳感器的測量精度。傳感器輸出電壓值對應探測的距離。通過測量電壓值就可以得出所探測物體的距離,所以這款傳感器可以用于距離測量、避障等場合。
規(guī)格參數(shù)
- 距離測量范圍:20 to 150 cm
- 信號輸出類型:電壓模擬信號
- 包裝尺寸:29.5×13×21.6 mm
- 功耗: 標稱值33 mA
- 供電電壓:4.5 to 5.5 V
數(shù)據(jù)分析圖示
文件:RB-02S042109.jpg
737px
文件:RB-02S042110.jpg
616px
引腳圖
應用例程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 ********/