Skip to content

Sensor de distancia SHARP

javierre edited this page May 7, 2019 · 11 revisions

Sensor de distancia SHARP 2y0a21

SHARP

Este sensor óptico tiene un rango de 10-80cm (aunque modelos similares tienen otros rangos).

SHARP Pinout

Es importante saber que SHARP devuelve la distancia en valores analógicos, por tanto es importante que el pin de datos esté conectado a un pin analógico. En el caso de NodeMCU sólo existe un pin analógico: A0.

SHARP Fritzing

/*SHARP GP2Y0A21YK0F IR sensor with Arduino and SharpIR library example code. More info: https://www.makerguides.com */

//Include the library
#include <SharpIR.h>
//Define model and input pin
#define IRPin A0
#define model 1080
/*Model :
GP2Y0A02YK0F --> 20150
GP2Y0A21YK0F --> 1080
GP2Y0A710K0F --> 100500
GP2YA41SK0F --> 430
*/
//Setup the sensor object
SharpIR IR_Sensor_1(IRPin, model);
void setup()
{
  //Begin serial communication at a baud rate of 9600
  Serial.begin(9600);
}

void loop()
{
  delay(1000);   
  int distance_cm = IR_Sensor_1.distance();  // this returns the distance to the object you're measuring
  Serial.print("Mean distance: ");  // returns it to the serial monitor
  Serial.print(distance_cm);
  Serial.println(" cm");
}

Ver código

Este sensor requiere de la instalación de la siguiente librería:

  • SharpIR

    Instalar librería


Más información

Clone this wiki locally