Activated NPN Proximity sensor to turn ON external LED - Page 1
Forum section: electronics / beginners

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 09:52:39 am
content: hi all,so i have a little project that involves a NPN Inductive proximity sensor. The sensor has an internal LED but i would like to use an external LED as well.Sensor is powered by 24V and when it detects the metal, sensor LED goes ON but the output signal is then pulled low. I've had some success with 2N2222 transistor configured as NOT gate inverter but having difficulties finding correct resistor values, external led is even too bright so it doesnt go OFF at all or too dim... not even sure this is the right way to do it.I can not use any MCUs for this, it has to be direct connection, i can not use PNP probe either, it has to be NPN.Any help would be highly appreciated.Many thanks,Alek

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 12:21:25 pm
content: Ok, so i have this working in a way per the schematicNow, resistors are what's confusing me here (i have no formal training in electronics). This works OK but when i power on the PSU, LED blinks once and then turns off, as it should... everything works.LED blinking on power ON looks to me like something is wrong with my resistor values. If i place R1 to be 100k, i get no more blinking but the LED is very dim in this case.Any help would be great.Many thanks

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 20, 2022, 12:31:21 pm
content: just connect the LED in series with a 15K to 25K resistor between the +24V and the sensor output (the one you labelled as probe signal).

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 12:42:30 pm
content: Quote from: BeBuLamar on December 20, 2022, 12:31:21 pmThanks, but i need inverted signal... this is NPN sensor and if i do as you said, i think the LED would be ON when the sensor is OFF (no metal detected)?Will test shortly.

author: mikerj
author_rank: Super Contributor
timestamp: December 20, 2022, 01:16:24 pm
content: An NPN sensor has an open collector output so you need a pull-up resistor on sensor output to switch on your 2N2222 on. However this circuit will invert the signal i.e. sensor off=LED on. Either configure your 2N2222 as an emitter follower, or use a PNP transistor wired as common emitter to make the LED switch on when the sensor does.

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 01:25:50 pm
content: Quote from: mikerj on December 20, 2022, 01:16:24 pmthanks mikerj!I am measuring voltage between the probe output pin and the probe ground, i get 24V when the probe is NOT triggered, and 0V when the probe is triggered and this is why i need the inverter to turn the LED ON when probe output is 0V, otherwise my LED is ON when the probe is not triggered.From my research, this "NOT gate" inverter should work without issues, and it sort of does, except for the led blink when the system powers on.Many thanks,Alek

author: mikerj
author_rank: Super Contributor
timestamp: December 20, 2022, 01:46:04 pm
content: If the sensor output has enough current to drive an LED (quite possible) then simply connect your LED + series resistor between the +24v rail and the NPN sensor output and it will do what you want it to.

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 04:36:31 pm
content: Quote from: BeBuLamar on December 20, 2022, 12:31:21 pmQuote from: mikerj on December 20, 2022, 01:46:04 pmI was pushing my idea about inverting the signal and making a super complex thing out of something so simple, without actually thinking about what you guys were saying, twice!Thank you!!! so simple and it works great.

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 20, 2022, 05:36:17 pm
content: Quote from: mikerj on December 20, 2022, 01:16:24 pmIt's not inverted. The only different is that you switch the negative end instead of the positive end. It would work just fine. Most of the sensor I worked with (and believe me I worked with a lot of inductive sensors) they are rated at around 100mA and the LED needs 20mA max I would think so it's fine to do what I suggest. And don't use pull up resistor. They are OK only to send the output to a high impedance input (like the input of a PLC) but not to light up an LED.

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 05:56:28 pm
content: Quote from: BeBuLamar on December 20, 2022, 05:36:17 pmthank you! yes, 20mA LED should not be an issue here and i guess it does not affect the functionality of the probe?Another issue, datasheet of the 3D printer MCU suggests i should use a pull up resistor (4k7) between V+ and probe output... so if i do add a pull-up, it should still be ok?Many thanks

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 20, 2022, 06:10:38 pm
content: Don't use the pull up if you just want to light up the LED. Just try it like I said and see if it's OK. Pull up I don't think would work for the LED.

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 06:15:58 pm
content: Quote from: BeBuLamar on December 20, 2022, 06:10:38 pmi got you but, i need to use the LEDandconnect it to the MCU :-)i am screwed am i?

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 20, 2022, 08:14:40 pm
content: What kind of input impedance your MCU is? May be we can figure something out.

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 20, 2022, 08:38:17 pm
content: By the way does your MCU take 24V input? or lower voltage?

author: elcrni
author_rank: Regular Contributor
timestamp: December 20, 2022, 10:56:28 pm
content: Quote from: BeBuLamar on December 20, 2022, 08:38:17 pmQuote from: BeBuLamar on December 20, 2022, 08:14:40 pmI am not really sure, there is no real datasheet on the MCU (BigTreeTech - Octopus V1.1).Thank you very much for your help.Alek

author: elcrni
author_rank: Regular Contributor
timestamp: December 21, 2022, 09:27:03 am
content: OK, found a bit more info, turns out i can use other sensor ports WITHOUT the pull-up resistor, but in that case i need BAT85 diode, which is ok anyway. Dedicated inductive probe port i am using now has an optocoupler that requires pull-up.So in this case, if i use one of the other ports, i do not need the pull-up and can safely leave the LED how it is now...Also, this part is confusing, using pull-up in combination with pull-downMany thanks,Alek

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 21, 2022, 10:20:52 am
content: But why do you have to use the NPN sensor? Can you use PNP sensor?

author: elcrni
author_rank: Regular Contributor
timestamp: December 21, 2022, 12:21:17 pm
content: Quote from: BeBuLamar on December 21, 2022, 10:20:52 amWell, first of all, i have quite a few pricier probes from Pepperl+Fuchs, ALL NPN... so i thought i could use what i have.Most important thing is, it has to be NCIf i goPNPway, that would mean i could easily use external LED the way i have it now, and use pull-down internal resistor, without any further complications?Many thanks

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 21, 2022, 02:53:37 pm
content: If you have a PNP sensor you don't need any pull down resistor just the current limiting resistor to limit the current thru the LED when you supply it with 24V. You can convert an NPN output of the sensor to PNP by using a PNP transitor instead of using still another NPN transitor as in your original design. I am sorry that I don't have the mean to draw and post a schematic diagram for you.

author: elcrni
author_rank: Regular Contributor
timestamp: December 21, 2022, 03:01:50 pm
content: Quote from: BeBuLamar on December 21, 2022, 02:53:37 pmsomething like this?

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 21, 2022, 04:25:40 pm
content: Yes but I don't think you need the R2 and the R1 value is chosen so that the transitor is going to be just above the saturation level not too much more.

author: elcrni
author_rank: Regular Contributor
timestamp: December 21, 2022, 04:28:41 pm
content: Quote from: BeBuLamar on December 21, 2022, 04:25:40 pmI dont need both resistors or i need both but different values?Thank you!

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 21, 2022, 04:41:25 pm
content: I don't think you need R1 at all. 2K for the R2 seems about right. It should drive the transistor into saturation.

author: elcrni
author_rank: Regular Contributor
timestamp: December 21, 2022, 04:58:19 pm
content: Quote from: BeBuLamar on December 21, 2022, 04:41:25 pmYep, works in both scenarios, with and without R1.Well, i think this ends my quest, i have a PNP probe now.Thank you very much for all your help!

author: elcrni
author_rank: Regular Contributor
timestamp: December 22, 2022, 05:44:23 pm
content: OK, everything great so far but need just one thing...NO Probe works as intended, LED light up when the metal object is detected.NC probe - LED is always ON except when the metal is detected.What's the easiest way to control when the LED is ON?i.e i prefer to use NC probe, and would like to tunr the LED ON when the object is detected?Many thanks,Alek

author: elcrni
author_rank: Regular Contributor
timestamp: December 22, 2022, 06:02:52 pm
content: ok, i think i've figured it out, another inversion of the signal with NPN transistor.Edit: NOPE, now i got NPN sensor again, darn!

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 22, 2022, 07:40:40 pm
content: You just want to make it difficult or there really is a reason for your preference of the NC probe? P&F do make inductive proximity sensor with both NO and NC output so you can use both.

author: elcrni
author_rank: Regular Contributor
timestamp: December 22, 2022, 07:50:11 pm
content: Quote from: BeBuLamar on December 22, 2022, 07:40:40 pmHahaha, NO!The reason is, i had a situation recently when cable in drag chains gave up and printer toolhead crashed in to the print bed, no significant damage done but still.With NC probe this should not have happened i think, as on wire break it would output signal as "triggered" probe and would stop all movements.Thanks again for your help, really appreciate it!

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 22, 2022, 08:45:14 pm
content: Since it's for work so I don't think cost would be an issue. If I were you I would look for a probe with complementary outputs. One NC and one NO. The NC is for the MCU to shut down the machine and the NO is for the LED. Or you can use a relay. I don't think it's a good idea to build stuff up but better assemble from off the shell parts. Do it in a way that if any of the component is broken it's easily replaced.

author: elcrni
author_rank: Regular Contributor
timestamp: December 23, 2022, 01:49:32 pm
content: hey, thanks again man!This is not work, rather very serious hobby, plus i like to make things myself and not always find ready made solutions.I have found some PNP NC probes that fit my requirements (m8 mount specifically) and i am doing further tests.Another thing confuses me, ok i have NPN probe, signal goes through PNP transistor as per previous schematic i posted, and i get inverted PNP output, basically a PNP probe...Now, if i use PNP probe and run the signal through the same converter, the output signal should still be PNP? Based on my hobby electronics knowledge, PNP can not invert PNP signal?I have the LED working in all scenarios as it should, except for NC where the LED turns OFF on sensor activation, but i can live with that.Thanks again,AlekEDIT: no wait, if i run PNP NC signal through the converter, i still get PNP but this time NO signal?oh dear, i am a bit lost

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 23, 2022, 02:37:40 pm
content: You can invert the output of an NPN output by using the pull up resitor but it only works for your MCU input. For the LED it's too much current to use the pull up resistor.

author: elcrni
author_rank: Regular Contributor
timestamp: December 23, 2022, 03:39:45 pm
content: Quote from: BeBuLamar on December 23, 2022, 02:37:40 pmClear!but the thing that confuses me still, it looks to me that the PNP inverter that i use, schematic below, inverts the state of thePNPprobe, so PNP NC becomes PNP NO? is this possible? (if i feed PNP probe signal where it says NPN Input)

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 23, 2022, 04:24:50 pm
content: No it only convert a NPN output to PNP but the PNP transistor is on when the NPN from the probe is on. So they both on and off together. You would need an inverter (not gate). But if you don't mind having the probe output to activate a small DPDT relay then it becomes very easy.

author: elcrni
author_rank: Regular Contributor
timestamp: December 23, 2022, 04:46:51 pm
content: Quote from: BeBuLamar on December 23, 2022, 04:24:50 pmOK, i am confused as when i drive PNP NC probe signal through PNP inverter (intended for inverting NPN to PNP) i get the LED inverted, works like PNP NO... So bottom line is, its still PNP NC but the LED is now inverted.What kind of relay? smaller the better in any case.Many thanks,Alek

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 23, 2022, 04:54:43 pm
content: Something like one of this from IDEC. Just pick one with the right voltage in your case it's 24VDC.chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://www.idec.com/language/english/catalog/Relays/RelaySocketFamily.pdf

author: elcrni
author_rank: Regular Contributor
timestamp: December 24, 2022, 05:12:26 pm
content: Quote from: BeBuLamar on December 23, 2022, 04:54:43 pmGot it! All working as intended now!Thank you so much for your help!Alek