Shop OBEX P1 Docs P2 Docs Learn Events
IR rangefinder (GP2D12) question — Parallax Forums

IR rangefinder (GP2D12) question

WhelzornWhelzorn Posts: 256
edited 2006-12-31 02:17 in General Discussion
Ok, so I have a GP2D12 here and it works just like it should, outputting a higher voltage the closer the distance.

What I've done is have the BS2 convert that voltage to a frequency (via the ADC) and then output the frequency to a digital potentiometer to control the brightness of an LED.
Seems redundant, right? well sort of, and thats what my question is about. The reason I have to do it this way is:
1) because the voltage needs to be lower the closer the distance is (not higher like normal)
2) because the voltage needs to be 0 when the distance is closer than 20cm, and it needs to stay where it is when the distance is greater than 70cm.
In other words, if someone put there hand 30cm away, the voltage should be low (like 0.25v or so) as they move it closer, it will get dimmer, until it reaches <20cm, when the voltage goes to 0.
Also, if someone put there hand at 50cm, the voltage should be somewhere around 1.5v. slowly moving it up would increase the voltage, but if they took their hand away at 50cm, the voltage would remain 1.5v until someone put their hand back within range of the sensor (between 20 and 70 cm).
The BS2 is handling this just fine, but the problem I have is that it seem quite complex for such a simple task, and I'd rather not go from analog to digital then back to analog again. It would be nice if there was a way to stay analog the entire time.
Does anyone know how I could do this without a micro controller at all?

Thanks!

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-12-29 03:49
    If all you want is for the sensor to control the brightness of an LED (close = dim, far = bright/est) then have the sensor sinking current instead of sourcing.· So, connect the LED anode·to +V (VCC) and then·connect the limiting resistor·between the LED cathode and the sensor output.
  • WhelzornWhelzorn Posts: 256
    edited 2006-12-29 23:12
    hmmm... alright the sensor seems to output a constant 'high' if I do that... The LED does not light at all.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-12-30 00:09
    Drat.· Apparently it doesn't sink current.· ???· (There wasn't any representation of the output circuit in the datasheet.)· Seems like it should.·

    Please verify that you connected it as in the attached drawing.
    229 x 191 - 4K
  • WhelzornWhelzorn Posts: 256
    edited 2006-12-30 06:50
    Yeah, that's exactly how I've wired it. It does work (backwards from what I want) if I plug the LED Anode to Vout and cathode to ground. but it seems that the sensor refuses to vary its output voltage if I have it sink the current (the reading from the ADC on the microcontroller shows no variation when I print the value to the serial terminal).
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-12-30 15:01
    OK, I was under the impression that you only wanted to use the sensor to vary the brightness of an/the LED.· With your last post, you indicate/d that you need to have the voltage, too.

    Given that, I have attached a schematic that will result in varying brightness of the LED as you want (0V, bright; +5V dim) and you should still be able to have the output voltage available for whatever.· I have verified the·operation of the circuit.·
    • The circuit uses a PNP transistor (2N3906 or similar is OK.)·
    • Resistor values aren't critical.· The base transistor could be 1K to 4K7 and the LED resistor could be a 1K.
    850 x 429 - 22K
  • WhelzornWhelzorn Posts: 256
    edited 2006-12-30 18:22
    aah, thank you! this seems to work just fine. I'm going to have to play with the values a bit to get the voltage range to be what I want, but it's what I was looking for.
    Unfortunately, without some very complicated circuit, the second requirement probably won't be possible unless I use a microcontroller and a digital potentiometer. I was thinking of using a 1381 voltage trigger or something, but I can't think of a way to keep the voltage where it was when the distance jumps to >70cm.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-12-30 18:36
    Second requirement: that at a distance of 70cm it should hold that voltage.· Is that it?· Till when?· So, when the voltage crosses a certain threshold then that voltage locks?

    I'm thinking op-amp/s:
    • a "sample and hold"
    • a·comparator
  • WhelzornWhelzorn Posts: 256
    edited 2006-12-31 01:49
    hmmm... doesn't a "sample and hold" only hold the value for a few seconds at most? I need it to hold the value indefinitely (until the value is changed, or power is disconnected)

    Post Edited (Whelzorn) : 12/31/2006 1:55:02 AM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-12-31 02:17
    With an op-amp and its high input impedance, it would hold for a very long time (indeed), but not exactly indefinitely.· Once the input cap is charged, the only current drawn off it would be from the op-amp input (next to nothing.)

    Just brain-storming.
    ·
Sign In or Register to comment.