Sharp紅外線測距模組-GP2Y0A02YK0F


Sharp紅外線測距模組-GP2Y0A02YK0F



紅外線測距模組一般有長中短距,這是Sharp公司出的模組,包括較短距離(2 – 15厘米)GP2Y0A51SK0F,中距(10 – 80厘米)GP2Y0A21YK0F和遠距離(20 – 150厘米)GP2Y0A02YK0F。我們還搭載了新款夏普GP2Y0A60SZ模擬距離傳感器(10 – 150厘米),提供最低的最小探測距離,最大探測距離,3 V寬輸出電壓差,高60 Hz採樣速率,低至2.7 V的操作電壓和可選的使能控制,全部採用更小的封裝,可以拿來做為廁所自動沖手感應。


接線方式


程式碼

下載函式庫

https://gist.github.com/reefwing/6bb74409774d5152f904

依照模組型號在下方程式裡的model寫入規定的值,否則執行測出的距離會不準

#include <SharpIR.h>

#include <Wire.h>

#define IR A2 // define signal pin

#define model 20150 // used 1080 because model GP2Y0A21YK0F is used

// Sharp IR code for Robojax.com

// ir: the pin where your sensor is attached

// model: an int that determines your sensor:  1080 for GP2Y0A21Y

//                                            20150 for GP2Y0A02Y

//                                            430 for GP2Y0A41SK   

/*

2 to 15 cm GP2Y0A51SK0F  use 1080

4 to 30 cm GP2Y0A41SK0F / GP2Y0AF30 series  use 430

10 to 80 cm GP2Y0A21YK0F  use 1080

10 to 150 cm GP2Y0A60SZLF use 10150

20 to 150 cm GP2Y0A02YK0F use 20150

100 to 550 cm GP2Y0A710K0F  use 100550
 */
 
SharpIR SharpIR(IR, model);

void setup() {

 Serial.begin(9600);

 Serial.println("Robojax Sharp IR  ");

}


void loop() {

  delay(500);   

  int dis=SharpIR.distance();  // this returns the distance to the object you're measuring

  Serial.print("Mean distance: ");  // returns it to the serial monitor

  Serial.println(dis);

}

文章作者: blairan
版權聲明: 本博客所有文章除特別聲明外,均採用 CC BY 4.0 許可協議。轉載請註明來源 blairan !
评论
  目錄