Home Code Arduino and GP2Y0A21YK Distance Sensor

Arduino and GP2Y0A21YK Distance Sensor

by shedboy71

the GP2Y0A21 is an infrared proximity sensor made by Sharp. Part # GP2Y0A21YK has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. The sensor has a Japanese Solderless Terminal (JST) Connector.

FEATURES

• Digital Output
• LED Pulse Cycle Duration: 32 ms
• Range: 10 to 80 cm
• Typical response time: 39 ms
• Typical start up delay: 44 ms
• Average Current Consumption: 30 mA
• Detection Area Diameter @ 80 cm: 12 cm

 

Schematic

Code

[codesyntax lang=”cpp”]

/*  
VCC -- VCC  
GND -- GND  
Signal -- Analog 0 
 */
 
#define pin A0

void setup () 
{
  Serial.begin (9600);
  pinMode (pin, INPUT);
}

void loop () 
{
  uint16_t value = analogRead (pin);
  uint16_t range = get_gp2d12 (value);
  Serial.println (value);
  Serial.print (range);
  Serial.println (" mm");
  Serial.println ();
  delay (1000);
}

uint16_t get_gp2d12 (uint16_t value) 
{
  if (value < 10) value = 10;
  return ((67870.0 / (value - 3.0)) - 40.0);
}

[/codesyntax]

 

Link
GP2Y0A21YK0F GP2Y0A21 Infrared Proximity Sensor IR Analog Distance Sensor VE713 P

Share

You may also like

Leave a Comment