SHARP GP2Y0A41SK0F IR ranger sensor (4-30cm) SKU:SEN0143

From DFRobot Electronic Product Wiki and Tutorial: Arduino and Robot Wiki-DFRobot.com

Specifications

  • Output:analog output
  • Detection Range :4-30cm
  • Voltage:4.5~5.5V
  • Current:33mA
  • Size:40x20x13.5 mm

formulas

formulas


Connection Diagram

sen0143_connection

Sample Code

/******** start code ********/
/*
 *	created		2013-07-29
 *	by		lisper (leyapin@gmail.com)
 *	function	test GP2Y0A41SK0F
 *
 */

//connect gp2d120x to A1
#define pin A1

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

void loop () {
        uint16_t value = analogRead (pin);
        double distance = get_IR (value); //Convert the analog voltage to the distance
        Serial.println (value);                 //Print the data to the arduino serial monitor
        Serial.print (distance);
        Serial.println (" cm");
        Serial.println ();
        delay (500);                            //Delay 0.5s
}

//return distance (cm)
double get_IR (uint16_t value) {
        if (value < 16)  value = 16;
        return 2076.0 / (value - 11.0);
}

/******** end code ********/
Go shopping:

SHARP GP2Y0A41SKOF Infrared Distance Sensor (4-30cm)