Introduction: Anet A8 (Prusa I3) Auto Leveling Using NPN NC Proximity Sensor and Skynet3D V2 Firmware

Manually leveling the bed is getting annoying after some time. Most people will want to add auto leveling for this reason and also to gain more precision when printing larger parts. The surface of the bed can change when heated...

You will need very few material for this :

  • the proximity sensor: 4mm is a pain, get a 8mm! Now this instructable is going to concentrate on the 4mm NPN normally closed (NC)
  • optocoupler FL817C (or anything you can find in the electronic trash)
  • soldering iron, solder
  • multimeter (important to test that everything is working)
  • Firmware : skynet 3d v.2 or whatever you think may be better (see facebook page)

Warning : do not "auto home" on your printer before you are absolutely sure the sensor is working! Otherwise you will most likely brake something, the little steppers for the z axis are pretty strong. In doubt, stay close to the power cable.

Please take the time to read the official documentation before you do anything. You may also want to take a look at peoples comment. While this worked for me, depending on the new revisions and the kind of probe you get, you may have to adjust this procedure.

Step 1: Printing the 3d Holder and Fixing the Probe

Get it from thingiverse : OR

(or search for variants)

Now if you have the terrible 4mm probe, you are up for some fun. The probe and the extruder nozzle need to be close in height. I recommend having the nozzle 2mm lower than the probe. Using the Anet A8 menu, lower the z axis by 0.1mm to find the perfect adjustment. Make sure the probe wont touch the print (that is why it needs to be a little higher).

Step 2: Doing the Electronics to Replace the Switch

The switch comes normally openend (NO). If you have a normally closed (NC) sensor, than you will have to change some settings in the firmware to say "STOP" when the circuit is opened. I will assume it is your case also.

Connect the probe

The brown wire goes directly to the power supply 12V (+).

The blue wire can be connected to the board's old switch black wire, which is a common ground.

The black wire will output 12V when the sensor is far from any metal and 0V when it is close to a metallic object. Test this with a multimeter to be sure you have the same kind of sensor I have and adjust accordingly if it is the opposite. Connect this to pin 1 of the optocoupler.

Now from my (only one) experience, the intensity of that 12V is pretty low, just enough to light an LED. That is why I decided to connect the probe's output directly to the optocoupler without any resistor to lower the voltage. Again, measure what comes out with a multimeter in case you have a different sensor and add a resistor if you need!

The role of the optocoupler is to use the 12V from the sensor to close the 5V switch without risking sending some 12V in your Anet controller (that would fry it).

For the rest, just follow the figure above.

Step 3: Optional : Add a Safety Switch

If something goes wrong with the sensor, the steppers may try to lower the z-axis completely, damaging your printer for sure. For example, if something is restricting the plate from moving, or it skips a turn, the probe may be left in the void and won't detect the plate. That is why I recently added a safety switch as a precaution.

This is super easy to do. Cut the red wire from the Z-Stop connector in two parts and connect them to the switch ends so that it is normally closed. The switch will be a little lower that the sensor and if something goes wrong it will trigger the z_min.

Step 4: Testing the Sensor With Cura

Board must be connected to USB and you will need Cura software for this step, with Pronterface UI selected.

Bring the print interface (file, print). Issue the command M119 to see if z is TRIGGERED or opened. Try this a few times with a metal object in close proximity.

If it doesn't change, that is bad! Try testing with a multimeter. Test on the collector/emmiter side of the optocoupler. You should measure 5V when the optocoupler is not triggered and very close to 0V when it is triggered. On the anode/cathode side, you should measure 12V when the sensor is far from metal and 0V when in proximity (that is with no optocoupler connected). Review datasheet if needed, maybe the optocoupler is fried or not triggered? Test it in recommended conditions or try another one...

Step 5: Install the New Firmware and Adjust Z-offset on the Printer

Now I am just going to cover this very quickly for skynet3dv2.0. Follow instructions from skynet or whatever other firmware you choose for more details.

Ok, so you are in Arduino IDE and you need to change a few parameters in Configuration.h :

  • The sensor offset x and y from the extruder nozzle. Measure the distances with a ruler.
  • Invert the value for the z_min position (if applicable).
  • Choose the LCD display (this firmware supports a better display or the regular one, you need to choose).

Once it is changed, upload it. If you did it right you should have the display updated with the new firmware logo...

Adjust the z-offset on the printer

For this, simply lower the z-axis with Cura Ponterface UI. Home All and then manually lower z by 1 or 0.1mm steps with a piece of paper underneath the nozzle. When you feel some resistance, issue a M114 command to know the position of the z-axis.

Now on the printer, go to the motionmenu and select z-offset. Enter the value you just found. Go to control and store memory. Try to Home All again and lower the z-axis by 10mm (by default at the end it will be raised 10mm above the plate). Check if you see some resistance.

Adjust the start G-code

Simply put G29 just after G28, this is for the auto leveling.

That's it, you did it, hopefully! Let me know how it goes in the comment section :)


leonardog94 (author)2017-08-11

Hi, thanks for the guide.

According to the wiring "diagram" i need to link the ground to the optocoupler cathode and then it goes form the emitter to the board ground, but do i need to link them directly too?

Kev_MTL (author)leonardog942017-08-11

They should be the same ground already, so just use the one from the board.

leonardog94 (author)Kev_MTL2017-08-11

So this way is fine?

Kev_MTL (author)leonardog942017-08-11


leonardog94 (author)Kev_MTL2017-08-11

So i can't understand the meaning of that "blue bridge" between cathode and emitter

Kev_MTL (author)leonardog942017-08-11

It only means that you can use the GND from the board or from the power supply, or both, they are the same actually (test it with a multimeter using the continuity mode: it will go beeeeeeep!). If you use the one from the board then you only have one wire to connect to the power supply... for me it seemed easier at the time. You are right, I could change the diagram if it is confusing, but I am too lazy ;-)

leonardog94 (author)Kev_MTL2017-08-12

it doesn't work... the led which show if circuit is closed is always on and I can't get any output from pin 4

Kev_MTL (author)leonardog942017-08-12

You mean the LED on the probe? If that is the case, it is either a bad probe or the wiring is not ok. Don't trust the color of the wires, verify the spec sheet (or the ebay page if you bought it there). Now if it was connected to a 12V source, it may be fried. Get a multimeter and test the probe alone before going any furether.

indiomara (author)2017-08-10

Hello, thank you for the guide.

i have one question before start with the installation. I'm not sure if the components that i have are compatible with your guide.

i have this sensor: LJ12A3-4-Z/BY, Capacitive proximity switch, blue cap, PNP NO

and i have also a set of STK. 10 x EL 817 Optoisolatore/Optocoupler

i can use those components, or i have to order a new one?

thanks in advance!

Kev_MTL (author)indiomara2017-08-10

It should work, but always test every step of the way to be sure. With a multimeter you can verify the 12V output of the probe when it is in proximity of a metallic object or not. As for the optocoupler, you can cheat with a higher input voltage if the current coming out of the probe is very low, 12V won't be a problem (so far for me it has always been the case, tried with two different probes). Try to light a LED if you have one (make sure to check the polarity) and if it lights up just a little you are good to go. Next step, connect the optocoupler and measure the output while playing with the probe. Let us know how it goes! One advice I can give you is that with a 4mm probe you better always watch your printer (at calibration time) and make sure the probe is perpendicular to the plate on every corner (there is no room for errors when you only have 4mm). Make sure to put back the switch as a safety measure, in case the head crashes on the plate. After awhile, I have upgraded one of my printer with a 8mm, both are working fine, but I prefer the 8mm one.

eveminelove (author)2017-08-01

Hey Kev_MTL, I'm totally puzzled by electronics part. I have an LJ18A3-B-Z/BX probe (i think that is the same as -8 version) and an optocoupler SRD-12VDC-SL-C with 6 nodes and an H/L switch (pic -
1. So in which position I should set that small jumper-switch? Near "L" or "H" or remove it?
2. Which cables and colors go where? NO, COM, NC and DC+, DC-, IN
3. My Z end stop switch currently have red wire in COM and B-R wire in NO, how to hook up it to the new system and do I need to solder a Black-red wire to NC like on your pic?

I'm ready to provide better pictures when everything will be done, so you can extend your tutorial with optocoupler SRD-12VDC-SL-C for the future.

Kev_MTL (author)eveminelove2017-08-01

What you have is a relay board, protected by an optocoupler. A relay is not good because it is mechanical and it will not fire instantly. What I did was unsolder the optocoupler from a similar relay board and that is the only thing I used. For the wiring, make sure not to fry your probe. Check the listing, the spec sheet, etc. If you can get your hands on a multimeter it will help you. Before you connect anything, try your probe alone and see how it reacts when it gets closer to metal, etc. Then you can connect the optocoupler. I believe the spec sheet is this :

eveminelove (author)Kev_MTL2017-08-01

Thanks for quick response.Since I barely understand anything in that manual and don't have a multimeter, I guess will keep leveling manually. I ordered that pre-made board to avoid soldering resistors and other things, thought i can just connect everything with crimps and that it. Too bad wasted time on firmware updates and other stuff.

AndrewR269 (author)2017-04-05

I have made my sensor with a voltage divider and it triggers good, but I have a problem with the homing. Home position of the x axis is in my case -33 and of course in this case when the z is going home, the sensor can't trigger because it is in empty space. How can I solve this problem?

BartlomiejA (author)2017-02-15

Does anyone know what the Vcc on the atmega1284p on anet a8 controller board is? I need it to work out the logic voltage levels. I currently get a signal at 3.45 V going into the controller board but I'm worrying it might be too little to properly register as a high. What do you guys think?

Kev_MTL (author)BartlomiejA2017-02-15

The 7805 voltage regulator brings the 12V input down to 5V, so the logic of the board is 5V. Try to measure the voltage between the red and black wire of the z-stop connector, you should get 5V. Now keep in mind that there is a 10k pull up resistor, so the pin on the chip is set to high by default. When you bring it to ground, it goes down to 0V.

BartlomiejA (author)Kev_MTL2017-02-15

Many Thanks for your help. I am however facing another issue now :<.

I am attempting to setup auto leveling on my A8 with the LJ18A3-8-Z/BX. I tried the potential divider approach with 10K and 15K resistors first. Before hooking those up the output from the sensor was 12V and theoretically my potential divider should drop this down to about 4.8V. This however was not the case as I was getting 3.45V. I checked the output voltage from the sensor after connecting said resistors and it dropped down to 9.12V O.o .Effectively making my potential divider not valid anymore. I tested the potential divider by itself in a separate circuit and it worked great.

I had some L7805's laying about so I also tried it with those instead of the potential divider approach. In a regular circuit without the sensor it worked great as 12V got converted to about 5V. As soon as I changed the input to the L7805 to be from the sensor output, I was only getting out just over 2V.

To summarise it seems that as soon as I connect anything on the sensors output it drops in voltage which breaks the setup that was hooked up. I ordered some optocouplers as suggested in this instructable however I can't get over why the above is happening in the other approach. Any ideas? Thanks.

Kev_MTL (author)BartlomiejA2017-02-15

I did this instructable because I went through the same kind of issues. In the end, I realized that the 12V output from the proximity sensor has a very weak intensity, a few milliamps from what I recalled. So I tried connecting a LED directly to it, to see if it would light up like crazy (and burn) and it did not, it was pretty dim. That made me think that I could just hook up the optocoupler without any resistor, because the internal LED of the optocoupler would not burn if the voltage is dropped by the internal resistance. So far it still works. So in the end, I think the proximity sensor is just sending a weak signal. V = R * I could be helpful to figure out what is going on, but first we would need to understand how the proximity sensor really works and why is the output so weak. I am no expert in electronic, just a guy trying to print! If anyone can dig into this, that would be awesome!

BartlomiejA (author)Kev_MTL2017-02-16

Well. I'm glad I wasn't the only one going crazy. Had resistors laying about so I thought I'd go with the potential divider approach. If I knew I would have ordered the optocouplers earlier. As for the reason to all this I have my suspicions as to whether the stock PSU is powerful enough.

LucT11 (author)2017-02-05

what kind of specification are acceptable for thes octocouplers? because i am not familiar with the kind of electronics.

KT Gadget (author)LucT112017-02-08

Most sensors like these will accept the 12V from the power supply, however, a resistor is needed to drop the voltage from the proximity sensor to the MAX voltage of the input side of the opto-coupler (this can range from 1.5V - 5V depending on the opto-coupler being used. Make sure to read the specs properly). The output side to the control board is (for the most part) just an open/closed switch for the microcontroller "switch" port to use. So imagine the output of the opto-coupler is the mechanical switch in this case.

The case where a resistor is not needed is if the opto-coupler is mounted on a board you can buy that already has the circuitry built in to use 12V off the bat and hook up the wires to the control board.

andyp108 (author)2017-01-31

I like your idea of using an opto-coupler to protect the device, which would be helpful if it ever goes internally short. But, opto-couplers should normally have a resistor at the input, which is basicaly like an LED. Just like an LED, without that resistor, your shorting out your PSU, or at the very least overloading it. Example of a resistor on your opto-coupler can be seen in the circuits on google:-

SteveRoy (author)2017-01-14

Wouldn't be better to fix the issue that is causing the printer to be out of alignment? My Prusa i3's have a simple z-axis adjustment that only needs a tweak after many prints. Having z-axis movement during the x & y movement can't be a good thing, the CPU has to work harder, the printing will be slower and really it's compensating for something that isn't right in either the design or build of the printer. Yes I know Jozef Pruda has added leveling to his new MKII i3.

lvk4 (author)2017-01-07

i have skynet v2 on anet a8 with sensor. new version of skynet v2.2

Swansong (author)2017-01-06

This would be really neat for the one at our library :)