Sharp Sensor GPY0A21YK

26 Jan 2012

hello I am new and Iqm bad on programming.

http://mbed.org/users/Tomas/programs/SHARPIR/5ydc9

I have found this code and when I run thecode occur errors . Can you tell me the process how to run it?

02 Feb 2012

Hi.

Could you show me the code you've written?

Anyway, here's a quick example which should work for the GP2Y0A02YK0F sensor (and also other non-linear sharp IR sensors, but then it needs to be calibrated).

If you create a main.cpp and put this code in it, it should work. I haven't been able to test it right now but tell me if you recieve any errors.

#include "mbed.h"
#include "SHARP.h"

SHARPIR Sensor(p10); //the output of the sharpIR sensor is connected to the MBEDs pin 10.
int main() {
  float DistanceCM;
  while(1){ //creates an eternal loop
    DistanceCM=Sensor.cm();
    wait_ms(20); //wait 20 ms between each readout
  }
}

edit: here's the program for you that you can import to the compiler

http://mbed.org/users/Tomas/programs/SharpIR_test/m4s4ry

13 Feb 2012

If I execute the program it is:

"cannot open source input file "SHARP.h": No such file or directory" in file "/main.cpp", Line: 2, Col: 18

13 Feb 2012

Did you try to compile the program I posted above? It compiles fine for me. Look at it and adjust your code according to it.

Basically I think you've included the sharp-library incorrectly.

22 Mar 2016

Where did you find the sharp-library?

28 Mar 2016
29 Mar 2016

FWIW this is a very old thread but the link to the library is still valid.

It looks as if the include ought to have read #include "SHARPIR.h" as that is the name of the header file.

26 Feb 2018

Hi....i am a new user here. Even i faced the same issue and i fixed it by following the method suggested above "If you create a main.cpp and put this code in it, it should work. I haven't been able to test it right now but tell me if you recieve any errors." It will be good if you can share full code here.