Difference between revisions of "SHARP 2Y0D21"
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
Code arduino http://arduino103.blogspot.fr/2011/06/detecteur-de-proximite-infrarouge-sharp.html |
Code arduino http://arduino103.blogspot.fr/2011/06/detecteur-de-proximite-infrarouge-sharp.html |
||
+ | |||
+ | |||
+ | D'après http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/ |
||
+ | <pre> |
||
+ | // Sharp GP2Y0A02 |
||
+ | 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. |
||
+ | } |
||
+ | |||
+ | </pre> |
Revision as of 21:31, 6 May 2013
GP2Y0D21YK0F is a distance measuring sensor unit, composed of an integrated combination of PSD (position sensitive detector) , IRED (infrared emitting diode) and signal processing circuit.
http://sharp-world.com/products/device/lineup/data/pdf/datasheet/gp2y0d21yk_e.pdf
Code arduino http://arduino103.blogspot.fr/2011/06/detecteur-de-proximite-infrarouge-sharp.html
D'après http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/
// Sharp GP2Y0A02 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. }