-
Notifications
You must be signed in to change notification settings - Fork 0
Sensor de distancia SHARP
javierre edited this page May 15, 2019
·
11 revisions

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

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.

/*
* getDistance
*
* Example of using SharpIR library to calculate the distance beetween the sensor and an obstacle
*
* Created by Giuseppe Masino, 15 June 2016
*
* -----------------------------------------------------------------------------------
*
* Things that you need:
* - Arduino
* - A Sharp IR Sensor
*
*
* The circuit:
* - Arduino 5V -> Sensor's pin 1 (Vcc)
* - Arduino GND -> Sensor's pin 2 (GND)
* - Arduino pin A0 -> Sensor's pin 3 (Output)
*
*
* See the Sharp sensor datasheet for the pin reference, the pin configuration is the same for all models.
* There is the datasheet for the model GP2Y0A41SK0F:
*
* http://www.robotstore.it/open2b/var/product-files/78.pdf
*
*/
//import the library in the sketch
#include <SharpIR.h>
//MODELS
//GP2YA41SK0F
//GP2Y0A21YK0F
//GP2Y0A02YK0F
//Create a new instance of the library
//Call the sensor "sensor"
//The model of the sensor is "GP2Y0A21YK0F"
//The sensor output pin is attached to the pin A0
SharpIR sensor( SharpIR::GP2Y0A21YK0F, A0 );
void setup()
{
Serial.begin( 9600 ); //Enable the serial comunication
}
void loop()
{
int distance = sensor.getDistance(); //Calculate the distance in centimeters and store the value in a variable
Serial.println( distance ); //Print the value to the serial monitor
}
Este sensor requiere de la instalación de la siguiente librería:
- SharpIR

-
- Acelerómetro-GY-61
- Brújula GY-273
- Buzzer o zumbador
- ESP8266 Deauther
- GPS NEO-6M
- Heltec LoRa
- IMU (Accel, Gyro, Magn)
- Joystick analógico
- Láser lidar 2D
- LDR Keyes K-018
- Leds RGB WS2811
- Led Superlumínico Keyestudio
- Motor DC
- Motor Lego NXT
- NodeMCU
- OLED
- Botón-pulsador
- RFID522
- Sensor barométrico BMP180
- Sensor de distancia HCSR04
- Sensor de distancia SHARP
- Sensor de temperatura DHT11
- Sensor infrarrojo de obstáculos (YL63)
- Servo de rotación continua FS90R
- Servo SG90
- Tacómetro
- TTGO Camera
- Wemos D1 Mini