PDA

View Full Version : npn reflective photo sensor input



Armadus
- 17th September 2007, 22:29
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.A/id.5305/.f?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.

BrianT
- 17th September 2007, 22:58
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

Darrel Taylor
- 17th September 2007, 23:31
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,

BrianT
- 17th September 2007, 23:39
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

mackrackit
- 18th September 2007, 00:04
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.

Darrel Taylor
- 18th September 2007, 00:28
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>

Armadus
- 18th September 2007, 01:00
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.

Archangel
- 18th September 2007, 04:52
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

Dave
- 18th September 2007, 13:09
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