Shop OBEX P1 Docs P2 Docs Learn Events
Reading voltage of infraredsensor — Parallax Forums

Reading voltage of infraredsensor

Robot FreakRobot Freak Posts: 168
edited 2007-02-14 20:11 in General Discussion
I'm trying to read the voltage of a infrared sensor, the sensor will continualy send to pin0.
Maybe a ADC, but that requires a output pin.
CPU.readPin(CPU.pin0); will only reaturn a boolean.

Can you help me?
Thanks!

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-10 13:24
    For reading a voltage you need the ADC.
    If you only have one spare pin, then that pin must be the ADC input.
    For output, you can possibly use another pin that·is currently assigned to some
    other device. For example, if you do have an I2C bus implemented,
    you can use the SCL pin as output for the ADC. You only must start and stop
    the ADC between using the I2C bus. (the SCL pin may be toggled as long as SDA
    remains high, eg. idle state for I2C)

    Without further knowledge what you have connected to the javelin
    this is the best advice I can give.

    regards peter
  • Robot FreakRobot Freak Posts: 168
    edited 2007-02-10 13:53
    The infrared sensor I use is made by someone here in the Netherlands, but it isn't a commercial sensor, so i've got no scematic or anything.
    It has the following connections:
    - 5V
    - 0V (ground)
    - signal
    Can I connect the 5V to pin1 and use that as output?

    Thanks for your quick reply!
    (this sensor can be used with a Robocup junior infrared ball)
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-10 14:08
    No.
    Connect 5V to sensor 5V pin.
    Connect GND to sensor 0V pin.
    The sensor signal pin is input to the ADC circuit.
    The ADC output pin generates a pulsewidth signal.
    Without knowing what you have connected to the javelin, and how, I cannot help.
    Draw up a schematic and post that.

    regards peter
  • Robot FreakRobot Freak Posts: 168
    edited 2007-02-11 12:56
    public int getSensor(int sensor) {
            adc.setChannel(sensor);
            int i = adc.getSample();
            if (sensor < 2) {
                if (i == 0) i = 1023;
                else i = 0;
            }
            return i;
        }
    


    I've found the following script for the muvium processor. adc information can be foud here: http://www.muvium.com/Tools/uVMDK/uVMDK-Standard/com/muvium/apt/ADCReader.html

    I still don't get why ADC (for Javelin) needs an output pin.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-11 13:41
    The adc circuit looks like this

    ··················· +
    o Javelin ADC in
    ··················· |
    Vin o
    [noparse][[/noparse]10k]
    +
    [noparse][[/noparse]10k]
    o Javelin ADC out
    ··················· |
    ················ [noparse][[/noparse]0.1uF]
    ··················· |
    ···················-+- GND

    The ADC out pin outputs a pwm signal such that the voltage
    level at the ADC in pin is maintained at 2.5V
    The dutycycle of the pwm signal is then equal to the Vin voltage
    in (5/255) volt units

    regards peter
  • Robot FreakRobot Freak Posts: 168
    edited 2007-02-11 15:09
    Okay, I will go buy 2 10k-resistors, and 1 0.1uF-capacitor.

    Thanks!
  • Robot FreakRobot Freak Posts: 168
    edited 2007-02-14 20:11
    Thanks a lot, Peter Verkaik. It's working, so let's start programming!
    I've used the following connections, can you check if this is right?
    Thanks!
              +------[noparse][[/noparse]0.1uF]
              |         |
             GND 5V     |
              |   |     |
              |   |     |
              |   |     |
    Vss o-----+   |     +---------------o Javelin ADC in
    Vin o---------+     |
    Sig o-----[noparse][[/noparse]10k]-----+-----[noparse][[/noparse]10k]-----o Javelin ADC out
    


    Vss = ground pin from sensor
    Vis = 5V input on sensor
    Sig = signal from sensor

    Post Edited (Robot Freak) : 2/14/2007 8:30:27 PM GMT
Sign In or Register to comment.