1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Help with sharp IR distance sensor

Discussion in 'Modding' started by mirciu, 5 Nov 2009.

  1. mirciu

    mirciu What's a Dremel?

    Joined:
    7 Jan 2007
    Posts:
    39
    Likes Received:
    0
    Hi guys, long time no talk, but i have a serious issue at hand.
    For our 2nd year project we're supposed to build a robot that can go up the stairs grab an object, climb down and place the object in a designated box. We have done all the easy part, constructing the little bugger, but now we're at sea....obviously we have to create a firmware for the pic at hand. Our dear university made some PIC programmers(very buggy and dodgy etching skills) witch is supposed to be connected to a board IO analog and digital.

    I'm having difficulties with the aforementioned sensor, as it is passed through an A2D. I have been reading posts and data-sheets (and i clearly don't get the full picture of) and I found out that it has an exponential output.

    The thing is 0V-0, 5V-1023. If it were to be a linear output i would guess, 0v means it is miles away from an object, and 5v when it's close to an object, bearing in mind it has a certain accuracy range.

    I found a formula giving the distance at which the object is placed but it contains the voltage of the sensor, and we don't have access to it, we only get a integer for the supposed distance between 0 and 1023.

    The formula is R = (2914 / (V + 5)) - 1
    Can someone shed a bit of light on this subject? pretty please with a cherry on top :D

    The code is supposed to be in C, applying this formula seems straight forward, but that V is bugging me.
    Thankx:wallbash:
     
  2. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    Wouldn't it be easier to get some empirical data? Set up the sensor at the end of a meter rules and move a bit of card along it.

    Hook your scope up to the ADC and measure the duty cycle of the PWM output. Or am I missing something?

    Btw if it really is an exponential scale, I don't think that formula will work. Or the output will not be linear.
     
  3. mirciu

    mirciu What's a Dremel?

    Joined:
    7 Jan 2007
    Posts:
    39
    Likes Received:
    0
    We don't have access to scopes and things of a sort for this project. The graph is something like this

    [​IMG]
    Basically we're only allowed to code it, and leave the electronics alone ( messing with electronics is for next year's project)
     
  4. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    You have access to the voltage of the sensor, the integer is a directed representation of it:

    Your ADC is giving numbers 0 to 1023, this means its a 10-bit ADC that has 1024 possible values.

    Your ADC range is 0-5v, so thats a 5V range.

    5/1024 = 0.0048828125 Volts per Step.

    If my read value is 512, then 0.0048828125 * 512 = 2.5 V.

    Then (2914 / (2.5 + 5)) - 1 = 387, which I would guess to be 387mm. (If the equation is mapping distance to voltage)
     
  5. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    The graph given doesn't really correspond to the equation...
     
  6. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    Also- which university do you go to? (I've noticed a worrying trend that alot of people I meet from other universities studying electronics are not encouraged to design whole systems in the 2nd year, only being rescricted to a simple subset of design)
     
  7. mirciu

    mirciu What's a Dremel?

    Joined:
    7 Jan 2007
    Posts:
    39
    Likes Received:
    0
    I'm at ULB, engineering department of the Brussels University. This is a multidisciplinary project, we're starting our major next year.

    The graph that i posted was from Sharp's site. It's the response of the sensor to distance.

    We are kept in the dark about the actual components that go into this board, it has some functionality, status leds digital inputs, analog inputs, and some connectors for some motors (lego mindstorms).

    I have already started gathering experimental data for this sensor using some simple code, and using the leds as a reference. I have been aiming it at a wall and measured the distance. The output the value thanks to the leds (i'm not very familiar with mplab to follow a certain variable and record it's values. Basically the first 3 leds are used for the main part of the number and the second part of the led array the decimals.
     

Share This Page