Guides

Guide: How to Setup Auto Bed Leveling (Ender-3)

Auto Bed Leveling (ABL) is one of those convenience features I’ve heard about for years, but it seemed complex and unnecessary for most 3D printers. My thoughts changed when I picked up the Ender-3 a few months ago, the build plate was warped in the middle and raised several millimeters higher than the outer edges, forcing me to work around it with each and every print.

While there are several decent aftermarket solutions, such as borosilicate glass and magnetic flex plates, I took the opportunity to setup Auto Bed Leveling instead. As this feature maps the build surface and compensates for minor variations, it seemed to be the perfect option for my uneven bed.

Unfortunately my electrical knowledge leaves something to be desired, and most guides assume a moderate level of expertise. From resistors to diodes, there is no shortage of ways to solve this problem, but my goal was to find a cheap, simple and clean method to make the project as easy as possible.

Auto Bed Leveling Parts

Purchased Parts List

Inductive ABL Sensor - $3.99
12V Optocoupler – $4.99
 
14 Gauge Silicone Wire - $5.48
14 Gauge Spade Terminals - $6.19
50 PCS JST-XH 2-pin Female Connectors w/ 120mm Wire - $8.99

Printed Parts List

Optocoupler Case
ABL Sensor Mounting Bracket

Overview

Most Auto Bed Leveling sensors require 6-36V to operate, but the board is only able to provide 5V. This may be enough for some probes, but it will greatly reduce the maximum detection distance. The advertised range is also rated for iron alloys such as steel, so our aluminum bed will reduce that distance even further, losing at least several millimeters.

To provide adequate voltage for the sensor, we will connect it to our 24V power supply instead. This voltage is perfect for the probe, but too much for other electronics and can fry the board, meaning we can’t just wire it up directly and start using it. To solve this problem, we will use an Optocoupler, a small circuit board which isolates the connections. It will provide the full 24V to our sensor and limit the output to our board at 5V.

Preparing the Optocoupler

I can’t solder to save my life, it brings on an instant anxiety attack and my hands start to shake like crazy. Unfortunately we have just 2 options, purchase a 24V Optocoupler from China and wait months for it to arrive, or buy a 12V Optocoupler and solder a different resistor in place. I’m not a patient man and I wanted this done, where I opted for the quicker (albeit more painful) route.

Note: Skip this step if you have a CR-10 or other 12V machines, it is only necessary for 24V power supplies.

So what do we have to do? There are 2 resistors on the Optocoupler board, labeled as R1 and R2 respectively (see image below). To make this compatible with 24V electrical systems, we need to remove the resistor located at R1 (below the LED light) and solder a 4.7K ohm resistor in its place. As far as soldering projects go, it is very straight forward and that is all it takes to prepare it for a 24V machine.

Auto Bed Leveling Probe

Since the Ender-3 uses the same X-carriage design as the CR-10, there are already dozens of printable brackets to choose from. The box style SN04 sensor is cheap, compact and looks like it would mount on the carriage without additional hardware, but it sits just a bit too far from the build plate to get triggered.

Although my initial plans didn’t work out, the Ender-3 SN04 Mounting Bracket on Thingiverse ended up solving the problem. It fits around the hotend cover and bolts in place using the existing screw holes. This particular probe also has elongated mounting slots that support height adjustments, making it easy to tweak the position as needed.

This particular design does however need longer screws to account for the thickness, where I used (2) M3x12mm bolts for the bracket and (2) M3x25mm bolts for the sensor. The sensor screws were actually a bit too long, but I placed M3 nuts below the head to act as spacers and reduce the total length.

Once the sensor bracket is printed, insert (2) M3 nuts in the back to give the bolts something to thread in to. To install it, just remove the 2 screws holding the hotend cover in place, one above and one to the left, then run the longer M3x12mm bolts through the bracket and in to the carriage. From that point, just screw the probe to the mounting bracket using the M3x12mm bolts, we will do the height adjustments once we have wired it to the machine.

To keep the sensor wires out of the way, use a few zip ties and attach them to the existing hotend cables. This will prevent the wires from getting caught on anything while printing and makes the setup look a bit more organized as well.

Wiring Instructions

At this point, we can start wiring up the Optocoupler board and connect it to the power supply, electronics board and bed leveling probe. We will need 2 sets of cables to get started, one for power and one for the sensor signal. While these can be bought prefabricated from online vendors, I would suggest making them yourself.

Sensor Signal Wires: Use somewhere between 22-26 gauge wire with a female 2 pin JST-XH connector on one end. These are common across many 3D Printers, often used for endstops and fans, where it is nice to have a kit on hand to make them as needed. If you have old 3D Printer electronics laying around, you may even be able to cut the wiring off a spare part to use for the signal wires.

Assuming this is a one time project and you don’t need an assortment of options, you can just grab a pack of wires pre-made, like these 50 PCS JST-XH 2-pin Female Connectors w/ 120mm Wire. Before ordering, make sure to measure the distance between your control box and Optocoupler location to confirm they will reach. Otherwise, if you have an infinite list of DIY projects ahead, I would advise picking up a JST-XH Connector Kit and some 22 AWG wiring to have on hand. The following are what I used…

720 PCS JST-XHP Connector Kit - $15.99
22 AWG Flexible Wire - $16.09

Power Supply Cables: Generally speaking, power supply cables are made from 14 gauge silicone wire with spade connectors crimped on the ends. This is what I am going to be using and would suggest doing the same, however the power draw will be quite low and smaller cables such as 16-18 gauge should work just fine. All you will need is a cheap crimping tool, I picked mine up from Home Depot a couple years ago for $7 and change.

14 Gauge Silicone Wire - $5.48
14 Gauge Spade Terminals - $6.19

Wiring Diagram

There are several existing diagrams floating around online, but they are either difficult to follow or misconstrue the information. To keep things simple, the illustration below aligns with the colors used in this guide and should make it easy to understand what wires go where.

To get started, use a small flat head screwdriver and loosen the two set screws on top of the 3 port connector, labeled OUT and GND. Strip about 5mm off the ends of both wires, then insert the Z-Endstop Signal Wire in to OUT and the ground wire in to GND. Tighten the set screws back down and clamp the wires in place.

The electronics box has a large opening on the back side, giving us space to run the wires from behind. Go ahead and unplug the original Z-Endstop and replace it with our 2 pin connector instead. As pictured below, the left side (green wire) is SIGNAL and right side (yellow wire) is GROUND, so depending on the color of your wires, make sure this is in line with your Optocoupler connections.

Next up, we will need to run the cables from the power supply to the Optocoupler board. To access the terminals, remove the cover that is held in place by 2 bolts on the back side, and mounted to the frame with 2 bolts on the front. Once these are out, the power supply can be taken off the machine and the cover should slide off the bottom.

The power supply has a total of 3 positive (V+) and 3 negative (V-) terminals with 2 of each available. Using the 14 gauge power cables, feed the ends with crimped connectors through the cover until they can reach the terminals. For the sake of consistency, the red wire (positive) goes to V+ and black wire (ground) goes to V- terminals.

Once finished, we are done with the power supply and can reassemble the unit before mounting it back on the frame. Next up we need to run these cables from our Power Supply over to the Optocoupler.

Using the wiring diagram above, start with the black V- power cable and the blue ABL sensor wire, these are both neutral and will connect to GND on the Optocoupler. Since we already installed one of the signal wires here (yellow in my case), we now have a total of 3 wires running to the port. It will be a tight squeeze, but loosen the set screw until the clamp is completely open and it should fit without any problems.

We will do the same thing with the red V+ power cable and the brown ABL sensor wire, which are both positive and will connect to the 2-pin INPUT+ connector on the other side. Loosen up the clamp, insert these wires together in to the port and clamp it back down.

That just leaves us with the black ABL sensor wire which provides the signal input to the board. Connect this to the 2-pin INPUT- connector next to the red/brown wires and clamp it down as well. When you are finished, it should look like the photos below.

To keep things looking nice and clean, we can print out a case for the Optocoupler module and mount it to the frame. I used Hatchbox Black PLA which matched the Ender-3 quite well, placing it directly behind the control box. This reduced the amount of visible wires and everything else is hidden in the back of the machine.

This particular case is not a perfect fit, there is quite a bit of spare room inside and the mounting holes are too far apart for 4040 extrusion. It is however a great design and still usable, so I opted to secure it using (2) M5x10mm bolts and square nuts that I had on hand. I believe the Ender-3 comes with spare T-nuts as well, which can be used as a substitute.

Carefully tuck everything inside of the case, making sure not to put any stress on the wires.  Put the lid on top to keep everything in place and you are finished with the Optocoupler wiring. Go ahead and turn the machine on and use a piece of metal to test the sensor, which should light up when it is detected.

Assuming everything works, now is a good time to go ahead and do a rough calibration of the probe. Slowly lower the X-axis until the nozzle is right above the bed, using a piece of paper to test distance as you normally would when leveling. With the nozzle at the proper height, adjust the Auto Bed Leveling sensor until that is the exact point it triggers and the LED light comes on. This can take a few minutes to get perfect, but only needs to be done once.

Marlin 1.1.9 Firmware Changes

While the official Ender-3 firmware is open source and available on Github, it’s an outdated version of Marlin, lacks several basic safety features and has no support for Auto Bed Leveling. In fact, most of the Auto Bed Leveling code has been stripped from the configuration file, making it a headache to implement after the fact.

As of Marlin 1.1.9, a sample Ender-3 configuration file is now included with the files. This has been used as a base for the modified firmware below, documenting each specific change made in the description. For those that wish to setup the latest Marlin firmware from scratch, these can be used as guidelines.

My biggest concern with enabling Auto Bed Leveling was that many owners reported it would require a trade-off of features. The Melzi board only has 128k flash memory, and ABL uses a good chunk of this to operate. Hell bent on keeping the LCD screen and SD Card support, 2 options that are most often sacrificed, I managed to fit BILINEAR Auto Bed Leveling by disabling just the SPEAKER, ARC_SUPPORT and EEPROM_CHITCHAT (EEPROM is still enabled). When everything was said and done, it worked out to a total of 98% flash memory usage and 29% variable memory usage, leaving enough wiggle room for later adjustments.

LP3D Ender-3 Marlin 1.1.9 ABL Firmware

This custom firmware has been specifically made for the Ender-3, uses the default printer settings and the Auto Bed Leveling configuration we setup above. If you used a different sensor, mounting bracket or even some other machine, it may be necessary to adjust the probe offsets and other values to reflect your specific 3D Printer. The full list of my changes are documented in the description on Github, so feel free to use those as needed.

Lastly, if you haven’t done so already, you will need to flash a Bootloader on the control board. This is a necessary, one-time precursor that will allow you to flash your choice of custom firmware on the Ender-3 or CR-10. My previous guide covers this process from start to finish and is available at the link below.

Guide: How to Flash a Bootloader on Melzi Boards

23 thoughts on “Guide: How to Setup Auto Bed Leveling (Ender-3)

    1. No problem, I hope it helps! I plan to polish things up a bit tomorrow and add some more info about the firmware, then share it with the Ender-3 community in hopes it can assist others to do it cheap and easily.

    1. Thanks for the feedback! The kits are nice but I had a hard time justifying the price when it comes to about 1/3rd the cost of the entire machine. When I realized you can do the same thing for less than $20 and have almost identical results, I was bound and determined to go that route and share what I learned.

  1. Tha k you for this excellent tutorial.

    This my be a stupid question, but will this work with a mirror glass bed? Also, could you please point me in the direction of how to level the bed going forward? Is there a gcode you run on the machine before printing to auto level? Or does it just sense the surface of the bed and compensate as it prints?

    Thank you!

    1. It would depend on the thickness of the glass/mirror, but I probably wouldn’t use this particular sensor on them. For an inductive probe, I would probably go with one of the options that have 8mm sensing distance, or just a BLTouch that uses a pin to probe the surface instead. The rest of the guide is pretty much universal across machines (Ender-3, CR-10, etc) and sensors, but the probe I used is pretty specific to a metal build surface.

      As for the G-Code, I am actually going to add a bit at the end of the guide to cover this. As a very general idea, you just add a couple commands to your Startup G-Code. “G28;” will home all of the axis, followed by “G29;” which will run the Auto Level process. Other commands like “G92” can be used to raise/lower the nozzle after the leveling is done, but I will delve in to that more on the next update.

        1. That should work better on a glass bed, powered from the PSU I would expect it to have somewhere between 4-6mm range for aluminum. You will need a different mount but otherwise will follow the guide as-is. When picking out a bracket, just make sure to find one that is easily adjustable, that will make things much more simple when fine tuning the position of it.

          I have only seen pictures of the 24V optocouplers, they definitely look longer but it is hard to gauge by how much. The case I used is pretty spacious inside, so I would expect it to fit but may be a bit more snug length wise.

  2. A silly question, actually how the auto bed leveling works? I mean let’s assume i have a 8mm sensing distance proximity sensor mount on it…should the sensor same level as the nozzle? If yes, how the system knows that it should leave some gap(0.2mm? is this adjustable?) between the nozzle and the surface (eg. aluminium base + 4mm glass thickness). Hope to learn some theory behind the mechanism…

    1. I think you set the nozzle the height you want it from the bed (using a piece of paper to check for clearance between the nozzle and bed), and then adjust the height of your proximity sensor so that it JUST triggers (so the sensor in reality may sit further away from the bed then the nozzle).

      1. This is definitely it in a nutshell. If your sensor has a greater detection distance, it will be mounted further away from the build plate. You want the sensor’s trigger point to be exactly the same as when the nozzle is the correct distance from the bed. For a 4mm detection distance, this may mean the sensor is 1-2mm higher than the nozzle. For an 8mm detection distance, it would be a bit more than that.

    1. Hi Jimmy,

      That one will work fine for 24V 3D Printers like the Ender-3. The only reason I didn’t recommend it is due to the longer shipping times from Aliexpress. Other than that, this would absolutely be the preferred Optocoupler to use. If you plan to print a case similar to mine, just make sure to measure it first as the photos of that one make it look longer than the 12V I am using.

  3. Thanks brett for the great guide, but ive noticed that changing the z offset does nothing, do I need to disable software endstops? the printer will not go into -ve z values

    1. Hi Jake,

      I’m actually writing a separate guide/article on configuring & calibrating the ABL sensor this week, where I feel this is a more involved subject that needs separate coverage. I will personally need to revisit the process myself, but I do believe I had to disable software endstops to get negative Z values.

      Just as a side note, the most confusing part (for me) when configuring was that the specified offsets didn’t take effect during the homing process. This wasn’t mentioned in any of the guides I found, so I kept making changes that seemingly didn’t take effect until the actual print started.

    2. Hi Jake,

      This is actually something that I encountered myself and took me quite a while to figure out. The Z-offset only affects the nozzle position during printing, not while the sensor probes the bed. I continued to run G29 (probe command) checking the nozzle height and finding no difference. Given it’s a bit too complex to combine in to this article, I am working on a follow-up guide now that covers how to calibrate the sensor properly after setup, should have it available in the next day or two!

      1. I am following your tutorial and I am anxiously waiting for your guide to calibrate the sensor abl.thanks for what you do.

        1. Thank you for the reminder on that, I will have it published later tonight or tomorrow morning at the latest. I ran in to some issues with the initial calibration, which resulted in some delays until I found a better method. After re-calibrating this weekend with a much more effective (and simple) process, I will be writing up the guide today and recap the steps.

  4. hello breed, everything I managed to put into operation according to your instructions.Firmware is super !!! but I do not want to fix the fan. It is still spinning on 100% paja czech republic

    1. Hi Fang,

      No problem, glad to hear that you appreciated it! While I haven’t used the 24V Optocoupler from Aliexpress, it should be the exact same except you won’t need to solder a new resistor to it. Just skip the “Preparing the Optocoupler” section and go straight to the “Wiring Instructions”, it is already made for 24V and has the same connectors as the 12V one that I used.

  5. Hi
    At first great tutorial!
    A little question:
    Doeas the z endstop switch put +5v to the board ore 0V ground? At the moment i cant figure out because im the next week not at home. Thanks and Greetings from Austria!

Leave a Reply

Your email address will not be published. Required fields are marked *