npn reflective photo sensor input


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2005
    Posts
    28

    Default npn reflective photo sensor input

    I want to use a 25V reflective photo sensor as a digital input for a PIC 16F628.

    Attached is a sketch of the circuit I am working with.

    For information on the sensor see:
    http://www.factorymation.com/s.nl/it...category=14137

    This circuit works while the PIC input is high, but is unreliable when pulled low.

    Any suggestions on how to use an NPN photo sensor as an input.
    Attached Images Attached Images  

  2. #2


    Did you find this post helpful? Yes | No

    Default A2 to base needs resistor

    Not sure what you mean by ' unreliable when pulled low' but the connection from A2 to the relay driver transistor needs a resistor. As you have it, A2 tries to go to 5 volts but the emitter base junction clamps at 0.7 volts. A2 may deliver up to 25 mA or the excess load may reset A2 to 0 volts. That may be causing internal problems with the PIC. Try 1-5 k ohms between A2 and the base.

    HTH
    Brian

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    To form a Voltage Divider, the 10K resistor needs to go to ground.
    Pin B7 will connect to the point in-between the resistors. Same as the N.O. output.

    HTH,
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default Voltage divider

    Hi darrel,
    I don't think that is it. Yes the 10k should go to ground but the internal protection diodes will clamp the 24V to 5.7 volts and the maximum current out the pin will be 19/57 mA or about 350 uA. I have seen a Microchip app note that puts mains voltage via a large resistor direct to a PIC port pin, not unlike what is being done here.

    Cheers
    Brian

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I use a n channel mosfet for this type of thing. Sensor signal to gate with a pull down resistor.

    PIC pin pulled high, mosfet takes it low when sensor is triggered.
    No need to worry about the 25V. Just use a common ground.

    More parts but works well.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BrianT View Post
    Hi darrel,
    I don't think that is it.
    Oh, I agree with your other post for the "IT".
    Unless it's a pre-biased transitor, as soon as it trys to engage the relay, it's going to reset the PIC.

    Was just trying to add some more.
    And after looking a little further, I'd say, leave the sensor like it is, But add a 10K resitor from the N.O. output to gnd.

    That would still give the voltage divider, and some protection against incorrect wiring.

    I know you can clamp things with the diodes, I see it used all the time for RS232 etc.
    Just a personal thing I guess. I try to keep the inputs between 0-5V at all times.
    <br>
    DT

  7. #7
    Join Date
    Sep 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Thanks for the help

    Thanks to everyone for the help. I am not sure why, but moving the 10K to ground does not work.

    With the 10K to the input the circuit works, but it is inconsistant which I think may be due to noise.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Armadus,
    If I read the schematic correctly, from the data sheet, this PIR is supposed to sink the current when switched on, and so should be connected to the pic pin directly. As it is wired, it wil merely reduce the voltage to the calculated divider voltage, roughly 1/5 of the 24v supply, the rest of the time the pin will be somewhere between that value and 24v depending upon how much current the pic is sinking through the resistors.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Armadus, The sensor is an open collector device. Just provide a pullup resistor of about 4.7k to +5 volts and you are good to go......

    Dave Purola,
    N8NTA

Similar Threads

  1. Reading A Photo Resistor using ADC
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2007, 09:28
  2. Replies: 5
    Last Post: - 2nd March 2006, 09:21

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts