I am just doing some initial inveastigations into using a common proximity sensor (BF-JK-5002C NPN NO) as a tachometer for a small diesel engine.
All hooks up OK using 12V and a magnet successfully activates it (this is a magnetic activated sensor). When the sensor is not activated, the voltage measurement on the sensor lead shows 12V. Activate it, and it drops to zero. All works!
Researching on the web, shows that users connect it directly to an INPUT_PULLUP pin on an Arduino. My questions are
- Why is the Sensor (Collector??) lead showing 12V?
- If the sensor lead shows 12V, wouldn’t that damage the arduino input pin?
- Shoud I opto-isolate?
Hi, I'll only bump this once. Here is a youtube video demonstrating the point about the 12V sensor voltage. Being a NPN setup, I can't understand how the collector/sink arrangement shows 12V. Any help appreciated
OK, I think I have the answer here
The sensor wire is connected to + (Vin) through a 10K resistor. When the sensor wire is floating, it will be at the same voltage as the power source (6-36V). Therefore, even though it 'sinks' when ACTIVE, when not active it would apply 12V (assuming it's powered by 12V) to an arduino pin which would exceed the pin specs.
Therefore, I'll conclude that opto-isolation is the way to go....
Better... add a 5K resistor in series to GND on the sensor line (as a voltage divider) will reduce the voltage on the sensor line to about 4.7V. The ACTIVE mode will still reduce the voltage to 0V
And now the great fun: yes 12V exceeds the specs of the pins, and yes you can connect it to the pin (but you need an extra resistor). The magic is in the clamping diodes, those keep the voltage on the pin down, but can not handle more than about 0.5 mA. So you need to limit your current to this (at 12V, it's (12-5)/R, so you need an additional 4k7 resistor.
Another method is to use a diode between your pin and the output, pointing towards the sensor, then enable the internal pull-up resistor. The sensor can pull low your pin, but the 12V can't reach it.
If that 10k resistor weren't there, indeed it would be a plain open collector output (would've been much better) and you could connect it directly to a pin with INPUT_PULLUP.
Of interest is that zener diode that's drawn in the schematic. I guess it's a 12V one, which would take care of voltage spikes on the power supply.