≡
Difference between revisions of "SNS-GP2Y0A21YK0F"
(→GP2Y0A21YK0F) |
(→GP2Y0A21YK0F) |
||
Line 4: | Line 4: | ||
The output / distance relations is like this: | The output / distance relations is like this: | ||
− | [[File:Example. | + | [[File:Example.png]] |
[http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/ have nice article about measuring distance with Arduino] | [http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/ have nice article about measuring distance with Arduino] | ||
Line 13: | Line 13: | ||
void setup() { | void setup() { | ||
− | Serial.begin(9600); | + | Serial.begin(9600); // start the serial port |
} | } | ||
void loop() { | void loop() { | ||
− | float volts = analogRead(IRpin)*0.0048828125; | + | float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) |
− | float distance = 65*pow(volts, -1.10); | + | float distance = 65*pow(volts, -1.10); // worked out from graph 65 |
− | Serial.println(distance); | + | Serial.println(distance); // print the distance |
− | delay(100); | + | delay(100); // arbitary wait time. |
} | } |
Revision as of 03:36, 23 July 2014
GP2Y0A21YK0F
GP2Y0A21YK0F is IR distance sensor 10-80cm with analog output. The output / distance relations is like this:
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) float distance = 65*pow(volts, -1.10); // worked out from graph 65 Serial.println(distance); // print the distance delay(100); // arbitary wait time. }