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.
Purchased Parts ListSN04 Inductive Sensor (3 Pack) - $12.00
12V Optocoupler - $16.99
14 Gauge Silicone Wire - $5.48
14 Gauge Spade Terminals - $7.49
5 PCS JST-XH 2-pin Female Connectors w/ 100mm Wire - $8.99
Printed Parts List
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.
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 5 PCS JST-XH 2-pin Female Connectors w/ 100mm 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 - $14.99
22 AWG Flexible Wire - $20.99
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 - $7.49
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.
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.