SNS-GP2Y0A21YK0F

Revision as of 04:35, 23 July 2014 by Olimex (talk | contribs) (GP2Y0A21YK0F)

GP2Y0A21YK0F

GP2Y0A21YK0F is IR distance sensor 10-80cm with analog output. The output / distance relations is like this:

Example.jpg

have nice article about measuring distance with Arduino

the final code is:

   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)S - luckylarry.co.uk
     Serial.println(distance);                       // print the distance
     delay(100);                                     // arbitary wait time.
   }