Home > Arduino, electronics, library > Arduino Library for the Sharp GP2Y0A21YK IR Distance sensor

Arduino Library for the Sharp GP2Y0A21YK IR Distance sensor

I started a Google code project to share an Arduino library for the Sharp GP2Y0A21YK IR Distance sensor

This project is a free initiative to create an Arduino library for the Sharp GP2Y0A21YK IR distance sensor. The main goal is to provide a library that simplifies the usage of this particular sensor in Arduino projects.

How the sensor works:

  1. A pulse of IR light is emitted by the emitter.
  2. This light travels out in the field of view and hits an object.
  3. The reflected light returns to the detector and creates a triangle between the point of reflection, the emitter, and the detector.
  4. The angles in this triangle vary based on the distance to the object.
  5. The receiver uses a precision lens to transmits the reflected light onto various portions of the enclosed linear CCD array based on the angle of the triangle described above.
  6. The CCD array can then determine what angle the reflected light came back at and therefore, it can calculate the distance to the object.

Library usage:

  1. Download the source
  2. Place the DistanceGP2Y0A21YK folder in your Arduino1.0+ “libraries” folder
  3. Open example sketch: “file”, “Examples”, “DistanceGP2Y0A21YK”, “Centimeter” (or “Voltage” or “Raw”)
  4. Connect the analog sensor to port A0 (and connect Vcc and GND)
  5. Compile & upload code
  6. Sensor data should be arriving over the serial port

More info & download: http://code.google.com/p/gp2y0a21yk-library/

  1. Luigi
    1 April 2013 at 1:20 pm

    Hey, great work. Can I use this library with Arduino due ?

  2. Dominique Tindall
    31 March 2018 at 5:48 pm

    This website is completely awesome. I’ve researched these details a great deal and
    I realised that is good written, fast to comprehend.
    I congratulate you because of this research that I’ll tell to people
    friends. I request you to recommend the gpa-calculator.co site
    where each university student or learner can find ratings grade point average rating.
    Thank you!

  1. 22 August 2014 at 2:45 pm
  2. 22 August 2014 at 3:24 pm
  3. 24 August 2014 at 3:44 am
  4. 5 September 2014 at 9:53 am
  5. 6 September 2014 at 1:56 am
  6. 6 September 2014 at 9:04 am
  7. 6 September 2014 at 2:33 pm
  8. 7 September 2014 at 12:43 am
  9. 8 September 2014 at 12:11 am
  10. 21 September 2014 at 2:40 am
  11. 22 September 2014 at 5:33 pm
  12. 22 September 2014 at 9:49 pm
  13. 24 September 2014 at 6:21 pm
  14. 24 September 2014 at 6:44 pm
  15. 24 September 2014 at 8:55 pm
  16. 24 September 2014 at 11:05 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: