Posts: 22
Threads: 3
Joined: Mar 2023
Reputation:
1
02-01-2025, 03:01 PM
(This post was last modified: 02-01-2025, 03:17 PM by tanoshimi.)
I've just come across this thread having almost exactly the same problem: I have a 12V PNP sensor, which I've wired as follows:
Brown: 12V
Blue: GND
Black: DI1 (or any of the other DIx pins)
The sensor itself has a red LED that indicates when it has been triggered. With just Brown and Blue connected, it works correctly, and I can use a multimeter to measure the output on the Black (output) wire changing from 0V to 12V.
But as soon as I connect the Black wire to any of the six "Dry Input" pins, the sensor immediately reads as if it has been activated.
According to the schematic, the DI pins should go to the anode of an optocoupler, but it seems to be actively pulling up the signal.
Oh no wait, hang on... I was getting IN_D1 mixed up with INPUT_D1. So, yeah, the inputs are all actively being pulled up to 12V through the 2kΩ resistors R38 - R43. That's.... a pain.
Can anyone provide a clear example of how you're meant to wire a PNP/NPN sensor then? (and would it be different if the sensor was NO/NC?)
Posts: 27
Threads: 4
Joined: Jan 2025
Reputation:
1
02-02-2025, 12:13 AM
(This post was last modified: 02-02-2025, 12:19 AM by twostar.)
I looked at this too, and posted this explanation of how the inputs and outputs work. You can't put 12V on the input because it's already at that level, you need to connect the input to ground to bypass the 12V pullup.
I looked at butchering the board (which I really don't want to do) so you can feed in the 12V externally but it'd be more complex surgery than I'm willing to undertake. Another option would be to use an external relay board (for infrequent switching) or solid state relay to convert the PNP -> dry contact.
Posts: 7,137
Threads: 882
Joined: Oct 2020
Reputation:
175
(02-01-2025, 03:01 PM)tanoshimi Wrote: I've just come across this thread having almost exactly the same problem: I have a 12V PNP sensor, which I've wired as follows:
Brown: 12V
Blue: GND
Black: DI1 (or any of the other DIx pins)
The sensor itself has a red LED that indicates when it has been triggered. With just Brown and Blue connected, it works correctly, and I can use a multimeter to measure the output on the Black (output) wire changing from 0V to 12V.
But as soon as I connect the Black wire to any of the six "Dry Input" pins, the sensor immediately reads as if it has been activated.
According to the schematic, the DI pins should go to the anode of an optocoupler, but it seems to be actively pulling up the signal.
Oh no wait, hang on... I was getting IN_D1 mixed up with INPUT_D1. So, yeah, the inputs are all actively being pulled up to 12V through the 2kΩ resistors R38 - R43. That's.... a pain.
Can anyone provide a clear example of how you're meant to wire a PNP/NPN sensor then? (and would it be different if the sensor was NO/NC?)
digital input short with GND, just 0V means trigger. it's logical ON
digital input =12v, NOT trigger. it's logical OFF
Posts: 22
Threads: 3
Joined: Mar 2023
Reputation:
1
Thankyou both @admin and @twostar for your fast replies - I appreciate it.
However, I still feel there must be something I'm missing here
I understand how the "dry" digital inputs can be used in the simple case of shorting to GND via a momentary button press, a toggle switch, or a relay, etc., but those are very limited examples, and (for me, at least) not useful.
What I'm trying to do is connect a PNP/NPN sensor to the KC868-A6, like any of the following:
Perhaps I made a false assumption, but I honestly thought these were pretty standard sensors so it wouldn't be a problem connecting them! The signal output line has 12V or 0V depending on the state of the sensor but, as described previously, they simply don't work when connected to any of the DI pins, due to the presence of the pullup resistor on the optocoupler.
Surely other users must be using these sorts of sensors? I'm just not quite sure how without modifying the board?! (which I've already had to do once to remove the pullup resistors R23/R31 and make the IO-1 and IO-2 pins usable as an output for a WS2812B strip)
Posts: 27
Threads: 4
Joined: Jan 2025
Reputation:
1
I'm wondering if you could abuse an NPN sensor, which switches the GND side, to do this? Looking at the first link you provided:
that switches the load to GND, so if you take the black wire and connect it to the KC868 input, with the KC868 and sensor sharing the same +12V and GND, that might work. You'd probably want to get one or two of the sensors first and check that the black wire is open-circuit to GND when not triggered and closed-circuit to GND when triggered before you connect them to the KC868.
Posts: 22
Threads: 3
Joined: Mar 2023
Reputation:
1
And honestly I thought that was going to work. When wired like that, a NPN sensor appears to behave correctly (i.e. the LED indicator on the sensor lights up when an object is detected, unlike with the PNP sensor that remains permenantly triggered), and the output wire switches from 12V to GND, but it does not get registered as a change in input from a digitalRead of the PCF8574 input.
I was beginning to wonder whether I had somehow damaged the optocoupler or PCF8574, but don't think I have since it still correctly reads an input if I simply attach a short wire from DI to GND.
Posts: 27
Threads: 4
Joined: Jan 2025
Reputation:
1
Hmm, odd, I would have expected that to work... if you're registered on somewhere like EEVBlog you could try asking on there. Actually before you do that can you check the voltage on DI (with the sensor connected) to make sure that it actually is being pulled down to GND? With the various pullups and things in both devices it could be that there's not enough voltage difference across the opto LEDs to light them. A high-impedance meter connected to the sensor output might give a different reading to the KC868 connected as an actual load.
Posts: 22
Threads: 3
Joined: Mar 2023
Reputation:
1
(02-02-2025, 10:35 AM)twostar Wrote: Hmm, odd, I would have expected that to work... if you're registered on somewhere like EEVBlog you could try asking on there. Actually before you do that can you check the voltage on DI (with the sensor connected) to make sure that it actually is being pulled down to GND? With the various pullups and things in both devices it could be that there's not enough voltage difference across the opto LEDs to light them. A high-impedance meter connected to the sensor output might give a different reading to the KC868 connected as an actual load.
Thankyou again for your input, I'm very grateful.
" A high-impedance meter connected to the sensor output might give a different reading to the KC868 connected as an actual load. " -> This is my only real conclusion too.
I suppose the answer I was hoping to receive was from someone who had practical prior experience of connecting one of these sensors and could confirm "Doing it like this works in practice". And then I could be certain that it's something I'm doing wrong. And I'm just surprised that nobody has done that - rather than the theoretical "well, this _should_ work".
I'll continue to experiment. Perhaps adding some amount of pull-down resistor on the signal wire will cause it to toggle the right side of whatever threshold is required. Although I'm reluctant to add too many external components - one of the attractive features of using the Kincony boards in the first place was for everything to be on the board already. Otherwise I might have well have just spun up my own PCB....
Posts: 27
Threads: 4
Joined: Jan 2025
Reputation:
1
Unfortunately you might be the person who provides the practical experience :-). To quote Blackadder (UK comedy):
Quote:Farewell, Blackadder! The foremost cartographers of the land have prepared this for you! It's a map of the area you'll be traversing.
[Blackadder looks at the blank map]
They'd be very grateful if you could just fill it in as you go along.
Posts: 22
Threads: 3
Joined: Mar 2023
Reputation:
1
Ok, well I've made some progress... the good news is that I think 12V NPN NO sensors _will_ work the way as was expected above, directly connecting the signal output to a DI pin. Have not tested with 5V yet, and I'm fairly sure that PNP won't work at all without some sort of additional transistor circuit (e.g. an 2N2222 would probably do the job).
The bad news (and the reason why it took so long to confirm the point above.....) is that there appears to be a bug in the PCF8574 library which Kincony use in their demo scripts, that causes the values returned by digitalRead() to be zero if you call it twice in quick succession (it seems related to the internal buffering it employs here: https://github.com/xreef/PCF8574_library...4.cpp#L869 )
But switching to using Rob Tillaart's library instead, I can consistently read a NPN sensor at least! https://github.com/RobTillaart/PCF8574
|