Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper

per and easiest way) – So many questions …

SO MANY QUESTIONS …
I must be missing something.

J A N UA RY 1 8 , 2 0 1 7 BY W E B B E S

Don’t trust the internet (and how to add an


Inductive Proximity Sensor to your 3D printer
the proper and easiest way)
Every now and then I still fall for it. Whenever I’m trying to accomplish something I’ve
never done before, I start a Google search to nd some nice video’s or blog posts that
explain how I can accomplish this speci c kind of task. That in itself is perfectly ne,
however… one should not stop using its own brain!

This week I wanted to add an Inductive Proximity Sensor (LJ12A3-4-Z/BX) to my 3D


printer as touching the printer bed while measuring the distance towards the printer bed
has an actual effect on the measurement.. duh. Especially when you have a round
aluminium printer bed that has supports at three “corners” only.

Side note (1): The main reason I own a 3D printer is that I’m into electronics – I like to built
and program my own IoT hardware – and wanted to be able to print my own custom cases.

So let me refer you to some contents on the internet that explain how to install this
proximity sensor:

instructables
youtube
thingiverse
forums.reprap.org

They all tell you to work with a voltage divider as these sensors are powered by 6V to 36V,
which means that their signal wire can be at that level to. Most 3D printer control boards
https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 1/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

however are Atmega based, which have max input of 5.5V. My MKS Base V1.5 printer
board, is indeed based on an Atmega 2560 and suffers that same limitation.

This all seemed very legit, so without thinking, I started to built a voltage divider,
following their samples. I started out by combining 6.8kΩ and 4.7kΩ as this does stay
within the standard range of “pull-up” values which is between 4.7kΩ and 10kΩ.

Voltage divider v1

Tested my voltage divider with a 9 volts battery, and it all worked out ne. So let’s tear
down my printer and add the proximity sensor. Installed the sensor together with the
divider and… nothing! I then tested the voltage divider in combination with the sensor
(don’t ask me why I didn’t test it with the sensor the rst time) and noticed that the output,
which should be around 5V, was around 2.5V only. OK, that might be an indication that the
supplied current is not enough to maintain the “high” voltage when we are “pissing” away
2.5 mA towards Gnd. That is a bit weird as 2.5 mA is not that much, but let’s give it a try by
using some higher value resistors. I don’t have the 15kΩ and 10kΩ mentioned in the video
at hand so let’s take a 68kΩ and 47kΩ!

Voltage divider with very high resistance

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 2/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

I was amazed as well, but indeed, this seemed to be the solution as the measured voltage
now was 4.5V. Still to far off in my opinion, but it is high enough to pass as a logic high so
let’s continue. Connect the sensor, con gure the printer rmware and see what’s
happening! Ehmm… nothing. Even though the sensor’s LED lights up when I approach it
with something metal, the printer software still says NO.

Let’s take the digital multi meter at hand again and see what’s going on. We rst measure
the sensing pin on the printer board. I’m pretty sure I disabled the pull-up in the rmware
so we should measure either a oating pin, or something close to GND.

Side note (2): In electronics we do not like oating pins. We either pull them softly, but
fully, up towards Vdd or down to GND.

But wait! It reads a high 5V! That’s not good. Veri ed my rmware and the pull-up is
indeed disabled, so did they add some hardware pull-ups?

Please tell me they didn’t. Because if they did add a standard hardware pull-up between
4.7kΩ and 10kΩ , I will indeed never be able to pull it down to LOW through the 68kΩ
resistor in my voltage divider. OK, getting a bit tired of it but, never give up and search for
the schematics on the printer board then.

You can nd some sort of design of the board on GitHub, but that is not detailed enough.
Luckily I found someone with the same issue that I had and he had a solution! Hurrah, all I
needed to do was to remove some resisters from the printer board and then it will all work.
So I prepared my soldering iron to attack my printer board and then……

NOOOOOH, of course not. It was just then when I nally decided to use my own brains. I
should be able to solve this myself! Serious? I almost got medieval on the ass of my
printer board with a soldering iron.

So let’s use our brain and look at the schematics of these type of sensors.

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 3/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Sensor wiring NPN PNP

The sensor type I’ve got is NPN NO which means that you measure the BLACK line and:

when it is not sensing anything inductive nearby, it should be open and thus oating
when it is sensing anything inductive nearby, it will be connected to GND

Hmmm… oating. Remember when I said we don’t like oating pins in electronics? We
would like to have either all or nothing. So in this case, the following will most probably be
true:

when it is not sensing anything inductive nearby, it will be pulled up to Vdd


when it is sensing anything inductive nearby, it will be connected to GND

So let’s draw a logical design on how an NPN transistor with a pull-up would look like.

Logical NPN with pull-up

We should be able to measure that with a digital multi meter. Just measure the resistance
between BLACK and BROWN. I did and guess what? I indeed measured an almost perfect
standard pull-up value of 10kΩ.

But wait a second… that’s why our voltage divider gave such weird values! What we
thought was this:

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 4/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Voltage divider v1

Actually was this:

Actual voltage divider

And that’s why it all didn’t work. Once we started to create a voltage divider with insane
values it started to work as the 10kΩ did not have that high of an impact any more.

We can now also answer the question of how we actually should connect our NPN sensor
to our printer board. We do need a voltage divider, but one of the resistor values is already
given. We can use the following formula to calculate the required value of the second
resistor R2:

Voltage divider formula

Or navigate to http://www.raltron.com/cust/tools/voltage_divider.asp if we are lazy.

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 5/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

The output should be 7142.86Ω.

To be on the safe side we pick a standard value which is less so we end up with 6.8kΩ. Our
nal solution just looks like this:

Final solution

Indeed, all we need to do is add a single 6.8kΩ resistor between BLACK and BLUE and all
should work ne.

Once the single resistor was added, I veri ed all voltages with my digital multi meter and it
all worked perfectly ne.

Don’t forget that you do need to change your rmware because we still need to invert our
end stop. It is HIGH when not triggered and LOW when triggered.

const bool Z_MIN_ENDSTOP_INVERTING = true;

So after all I got it working in the easiest, cheapest and most logical way one can, simply
by using my own brain.

The moral of this story is to never stop thinking yourself and to not blindly trust all stories
on the internet. Use your brains!

That being said! Don’t just do as this posts says! First you have to verify which type of
sensor you’ve got. If you have a NPN type of sensor, you should be able to measure the
10kΩ pull-up resistor between BROWN and BLACK. If you have a PNP type of sensor, you
will most probably(I don’t own one) be able to measure the 10kΩ pull-down resistor
between the BLACK and BLUE. In case you’ve got a PNP type of sensor, the very rst
voltage divider should indeed be used.

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 6/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Voltage divider v1

One thing is sure. IF you do connect your sensor to 12V (which you should as that is within
the specs!) you should not go without any voltage regulation, even though many people
suggest you should. It doesn’t matter which type of sensor, you should not connect them
as is to your signal wire if the sensor is connected to 12V.

* * * U P D AT E * * *

Boris had a perfect comment on using a diode instead. And, believe it or not but, using a
1N4148 diode was my rst solution. So I did test using a diode and that also works
perfectly ne, simply because the direction in which the 12V current would like to ow
when the sensor is open will be blocked by the diode. The internal (or hardware) pull-up
still pulls the Atmega’s sensor pin to HIGH however.

Current ow when the sensor is open

But as soon as the sensor is closed, the diode would allow the 5V current to ow in the
opposite direction towards ground, which pulls the Atmega’s sensor pin to LOW.

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 7/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Current ow when the sensor is closed.

So both the proper voltage divider and a diode can do the job. Which one you prefer… well,
the diode might actually be safer to use (they often call it a protection diode with a reason
;-)) if installed correctly, but it also depends on what you have at hand and even what you
prefer I guess. The reason I preferred to explain the voltage divider in the rst place, is
that one cannot wire the resistor in the wrong direction. If you do that on the diode, you
will permanently damage your printer board.

* * * U P D AT E 2

While I was watching referrals to this blog post I noticed some Swedish(?) web site. When
I looked at that blog post (after translation) it showed an ever better way of connecting
the sensor to the printer board by using an opto coupler. I know a lot of people don’t have
one of these lying around, but if you do… you can’t be any safer. Check it out here.

Share this:

 Facebook  Twitter  LinkedIn  Reddit  Pinterest 5

Like this:

Like
Be the first to like this.

3 D P R I N T E R , I N D U C T I V E P R O X I M I T Y S E N S O R , I N S TA L L AT I O N , L J 1 2 A 3 , M K S , P U L L - U P

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 8/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

24 Replies to “Don’t trust the internet (and how to add an Inductive


Proximity Sensor to your 3D printer the proper and easiest way)”

Boris
F E B R U A R Y 2 1 , 2 0 1 7 AT 7 : 2 8 P M

Good job, smart done and clear explained.


May I ask you something. I’m ghting with MKS Gen-2z v1.1 board on 3D printer. It has a
standard hardware pull-up resistor. Now trying to use NPN NO capacitive sensor (LJC18A3-
H-Z/BX) for autobedleveling. Already played with voltage divider from Tom’s guide etc. Got
oating values, as you did. After reading your article I measured resistance between brown
and black and it is in nite. The resistance between black and blue is 1.15 kOhm. Made double
check: it is NPN NO sensor. Any ideas?

Boris
F E B R U A R Y 2 1 , 2 0 1 7 AT 1 0 : 1 6 P M

Update: I used 7.3 kOhm resistor (just did not have other closer to needed value) as you
described. In rmware I have disabled pull-up resistor. Now sensor state is reproducibly
shown as Low when not triggered and High when triggered (checked using M119 and G31
commands). By the way it shows 5.37 v and 120 mcA when not triggered and 3 mV and 1 mA
current when triggered.
I thank you SO MUCH for your investigation! If you don’t mind I will post links to your blog at
the places where other lucky owners of MKS Gen-2z boards with built-in pull-up resistors will
probably look for the solution: groups of Sunhokey printer owner at thingiverse.com,
facebook, 3dtoday.ru.
Thanks again!

Webbes
F E B R U A R Y 2 3 , 2 0 1 7 AT 1 0 : 1 9 A M

Nice to hear it worked out for you. Please feel free to share this information in any form you
like. You can even copy the contents to your own blog if you like. As long as the information is
shared and you don’t charge people money for it, I’m ne with it.

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 9/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Boris
F E B R U A R Y 2 3 , 2 0 1 7 AT 3 : 5 6 P M

Here are recommendations about using diode. I don’t quite understand how it works.
Solution with resistor looks safer for me, because diode failure is much more probable than
resistor failure
https://www.facebook.com/groups/sunhokeyprusai3owners/1407992025924842/
Quote from there:
James Brown The NPN sensor drives low when activated, if you have a voltage divider, it may
not work properly. The voltage divider will itself form a divider with the on-board pull-up,
preventing the signal going fully low; depending on resistor values it might or might not work.
A better solution is to use a reverse biased diode, when the sensor drives high, the diode
blocks the signal (too high a voltage for the board), when the sensor drives low, the board pin
is pulled down to ~0.7V (one forward diode drop).

Webbes
F E B R U A R Y 2 4 , 2 0 1 7 AT 6 : 0 4 P M

Thanks for your reply. The diode was my rst solution but I eventually went with explaining
the divider as this allows me to actively pull-up instead of relying on the hardware or
software pull-up. Besides that, the resistor cannot be wired in the wrong direction as can be
done with the diode, which would damage the printer board.

But, to prevent confusion on what to use I decided to update the post to re ect the diode
option. It makes it more complex as a whole, but at least, it is now complete.

For those people that are wondering if you could combine the two: “Yes you can!”. But the
resistor would be completely redundant until the diode somehow shorts out, or is installed in
the wrong direction. In the latter case you would not damage your printer board, but the head
would crash into the bed as its hardware or software pull-up current will be blocked from
owing away to ground by the diode. But I sure hope you at least test the “switch” before you
start a bed level.

sb43201
F E B R U A R Y 2 8 , 2 0 1 7 AT 1 2 : 2 3 A M

For thick glass bed (>3mm), use Omron E2BM18KN16WPC12M 16mm NPN inductive sensor.
Also, it has better circuitry that doesn’t require resistor or diode.
https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 10/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

http://www.mouser.com/Search/ProductDetail.aspx?R=E2B-M18KN16-WP-
C1_2Mvirtualkey65350000virtualkey653-E2BM18KN16WPC12M

Webbes
F E B R U A R Y 2 8 , 2 0 1 7 AT 1 0 : 5 6 A M

It indeed looks like the Omron E2BM18KN16WPC12M 16mm NPN inductive sensor does not
have an internal pull-up and thus can be used safely without any voltage regulating at all.

Did you test this with a digital multi meter yourself?

sb43201
F E B R U A R Y 2 8 , 2 0 1 7 AT 1 0 : 0 4 P M

Yes, I tested and the output is 5v oated/connected\ when powered by 12V.

Webbes
M A R C H 1 , 2 0 1 7 AT 1 0 : 1 6 A M

Perfect. Thanks for letting us know.

Ricky Manner
A P R I L 1 2 , 2 0 1 7 AT 7 : 3 9 P M

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 11/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

I tried the optocoupler 4N25 as described in the Swedish blog post – it didn’t work. I’ve seen
other articles where people are applying 12V and a 1KOhm resistor to the cathode, and the
signal pin to the anode … anyone have a capacitive NPN NO sensor working with a 4N25 or
optocoupler ?

Benjamin
J U N E 3 0 , 2 0 1 7 AT 1 2 : 4 8 A M

I had the same problem and i x it like you.


Thanks!!!

Can Dogancan
A U G U S T 9 , 2 0 1 7 AT 7 : 0 9 P M

I tried the ***UPDATE 2 from the Swedish site. Unfortunately 1K ohm can only drop voltage to
2.5V and controller still accepts is as HIGH. After replacing the R with a 2.2 ohm. I got 2 Volts
and it was enough for the controller for returning LOW. I tried it with 12mm NPN and 18mm
NPN (both inductive) and 18mm Capacitive all worked but best was capacitive one.

Paul
A U G U S T 2 2 , 2 0 1 7 AT 1 0 : 2 5 P M

My solution was just to change the signal pin to a not used one on my mks gen 1.4. I took pin
44(aux 2)and in the ramps pin le changed the z min endstop pin to 44. Re ashed marlin and
it worked.

Webbes
A U G U S T 2 3 , 2 0 1 7 AT 1 0 : 2 0 A M

Going through the datasheets I did not found this pin to have a higher voltage rating. Can you
point us to any reference that states that 12 Volt on this pin is supported?

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 12/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Paul
A U G U S T 2 3 , 2 0 1 7 AT 1 : 4 1 P M

I did not feed it with 12 V. I used the 5 V and the gnd directly from the endstop connection. So
the braun wire of the LJ12A3-4-Z/BX Inductive Proximity Sensor Switch NPN no connected
to 5V, the blue wire connected to gnd and the signalbwire to pin 44.

Paul
A U G U S T 2 3 , 2 0 1 7 AT 2 : 3 9 P M

The black wire is the one that is connected to pin 44.

Paul
A U G U S T 2 3 , 2 0 1 7 AT 4 : 1 4 P M

I also have a prusa i3 with a rumba board where I just connected the 3 wires off the lj12a3-4-
z/bx(npn no) directly on de z min endstop connection. Only the endstopconnection of the
rumba is not tted with pullup resistors that one works straight away.

Henry
A U G U S T 3 1 , 2 0 1 7 AT 1 2 : 4 4 P M

Thank you very much, it helps!


I use a schottky barrier diode instead of 1N4148 for it has a faster reaction.
uncomment PROBE_DOUBLE_TOUCH in marlin, it now has a tolerance of less than 0.05mm

alan
S E P T E M B E R 2 , 2 0 1 7 AT 4 : 1 4 A M

i have lj12a3-4-z/by PNP/NO type


and A8 printer, i still cant good wiring to tell me what to do ….

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 13/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Webbes
S E P T E M B E R 1 1 , 2 0 1 7 AT 3 : 0 3 P M

As it is a PNP NO sensor, you should measure either oating or GND when not sensing
anything nearby or input V+ when sensing anything nearby on the BLACK wire.

Input V+ should be between 6V-30V. Based on the input voltage you use (12V?) and any pull-
down resistors (internal or external) attached to the BLACK wire to prevent it from oating,
you should calculate the required voltage divider.

I would recommend you to start by measuring the resistance between BLACK and BLUE
wire. This will give you the value of an internal pull-down resistor if any.

Riekus
S E P T E M B E R 9 , 2 0 1 7 AT 1 1 : 0 3 A M

when using a ramps, on what pins would you install your cables?

Webbes
S E P T E M B E R 1 1 , 2 0 1 7 AT 3 : 0 4 P M

Unfortunately I do not have the datasheets of your printer board (ramps version?) or your
sensor, so I cannot help you out here.

mika
O C T O B E R 2 6 , 2 0 1 7 AT 7 : 4 7 P M

I just had the same issue and i had come to the same exact conclusion, funny how i also came
across the guy that gave advice to remove the onboard pullup resistor lol anyways thanks

Alex
O C T O B E R 2 7 , 2 0 1 7 AT 1 2 : 3 0 P M

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 14/15
11/20/2017 Don’t trust the internet (and how to add an Inductive Proximity Sensor to your 3D printer the proper and easiest way) – So many questions …

Hello, can you please redraw a nal version with a diod for dummies (people who do not have
experience to read schematics)? Like blue wire does here, brown there etc.

Also i saw alot of people hook up old end stop sensor as backup measure, to prevent events
when proximity probe failed. That switch have 3 nodes, i cant understand how to wire the
electronic trigger chain (com, nc and something i cant recall)

https://mertarauh.com/2017/01/18/dont-trust-the-internet-and-how-to-add-an-inductive-proximity-sensor-to-your-3d-printer-the-proper-and-easiest-way/ 15/15

You might also like