Shop OBEX P1 Docs P2 Docs Learn Events
Need help receiving data from sharp IR distance sensor — Parallax Forums

Need help receiving data from sharp IR distance sensor

RyoshimaRyoshima Posts: 34
edited 2011-06-13 19:31 in Propeller 1
Hello everyone,

I am new to the propeller and have just started programming it and have run across my first problem. I am using the GP2Y0D810Z0F Sharp IR distance sensor. When an object is not detected by the sensor, then it outputs a logic high ( I am putting 5 volts on it and the output signal when high reads around 4.01 volts on my multimeter) and when an object is detected, then the sensor outputs a logic low, which I have found it to be 0.8 volts on my multimeter. I strongly believe the problem I am having is with my code.

Could someone help me with my problem?

Code:
PUB edgeDetect
DIRA[0] := 0
DIRA[1] := 1
if INA[0] := 0
OUTA[1] := 1

Pin 0 is suppose to be an input for the output of the sensor and Pin 1 just outputs to an LED for an indicator.

Thank you

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-10 16:20
    First of all, you're operating the Sharp sensor from a power source of around 5V. When you use this sensor with a Propeller you either have to operate it from a 3.3V supply or you have to use a 2.2K to 10K resistor between the Sharp's output and the Propeller's I/O pin or you may damage the Propeller.

    Regarding your code, edgeDetect only checks pin 0 once. If the sensor detects an object, this routine has to be called after the detection occurs or it will miss the change. Also note that nowhere in your code is the LED turned off. You should put "OUTA[ 0 ] := 0", probably just before the IF statement.

    In the future, use the [ code ] and [ /code ] tags around any posted code (without the extra spaces).

    You never mentioned what "my problem" is.
  • ercoerco Posts: 20,259
    edited 2011-06-10 16:51
    Looks like the supply voltage on that Sharp ranges from 2.7 to 6.2 V, so you might try running everything off of 3.3V. Per Mike, you'll want your code to run in a loop, checking the sensor and switching the LED as necessary.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-06-10 23:56
    Hello Ryoshima,

    welcome to the propeller-forum. You are doing quite well for your first posting as you are describing what you do and that you posted your code.
    To improve the forum-members ability to help you can improve your providing of information.

    As Mike already mentioned short pieces of code can be inserted by using the commands "code" "/code" in square-brackets but without spaces between square-brackets and characters.
    For bigger codes it is much better to use the archive-function of the propeller-tool. For code that includes objects (=other *.spin-files) the archiving-function is a must.

    The archive-function is found in the main-menu of the propeller-tool under file - archive - project.
    This creates a zip-file containing all *.spin-files that are nescessary to compile the code.

    Another thing is to describe what you want to do and the results you get.
    In your case this could look like this
    I have a small testprogram that should read the sensor-state on IO-pin 0 all the time and switch on/off a LED connected to io-pin 1 to give a feedback about reading the input.
    What I get is LED flashes once for a short time and then stays off.

    This is just an example and maybe not exactly what you want and what you get. With The this example I just want to show a pattern what kind of information
    you should provide to get help that helps.

    You can ask as many questions here as you like and as simple questions as you like. Simple questions have the advantage that almost-newbees get a chance
    to answer too. My experience with this forum is that everybody is polite and patient.
    So keep the questions coming

    best regards

    Stefan
  • RyoshimaRyoshima Posts: 34
    edited 2011-06-13 18:38
    WOW! Thank you very much for your understanding and patience with me on this. I know that this is a very simple program, which is why I'm so frustrated it won't work. This code will be part of a senior project and will drive these infrared distance sensors (which will be attached to a robotics platform) for the purpose of edge detection so that our robot won't fall down stairs and the like. I just want this code to be able to read the output of this sensor where if the output signal is logic high, then the LED won't turn on and if the output signal is logic low, then the LED turns on. When I modified the code it still will not work. More help would be appreciated.
    PUB edgeDetect
    
      DIRA[0] := 0                  'Pin 0 set to input for the IR sensor output
      DIRA[1] := 1                  'Pin 1 set to output for the LED
      repeat
        if INA[0] := 0              'If pin 0 is reading logic low, then pin 1 goes high and turns on the LED
          OUTA[1] := 1
        if INA[0] := 1              'If pin 0 is reading logic high, then pin 1 goes low and turns off the LED
          OUTA[1] := 0
    
  • Mike GMike G Posts: 2,702
    edited 2011-06-13 18:47
    Ryoshima,
    if INA[0] := 0
    

    This means If [Assign INA[0] the value 0]. You want a Boolean compare; if INA[0] == 0.
  • RyoshimaRyoshima Posts: 34
    edited 2011-06-13 19:31
    Yes, that is what was wrong with it. Thank you so much for helping! I knew it was something simple and indeed it was.
Sign In or Register to comment.