ANET A8 optical z probe (BLtouch like with servo)

by aeropic Feb 24, 2018
Download All Files

Thing Apps Enabled

Please Login to Comment

Sir, I take my hat off to you. This design is a credit to you.
I printed the parts, Used a length of 1mm stainless steel welding wire for the probe that I had in my stock. I ordered a pack of 5 servos for around £6 delivered and wired one to the 12V fan supply - OOPS! that didn't work. Good job it was a lot of 5 servos I bought. Now, taking the supply from the back of the optical end-stop sensor (AS YOU INSTRUCTED) The replacement works perfectly. It just works so well. It makes me smile to see the servo deploying and parking the probe (don't know why, it just does).

As for performance, I get a reading of 0.00090 SD when testing repeatability. Amazing!

Thank you so much & best wishes.

Good it works fine... Mine is doing great job since Day one

I like this a LOT. I built it and did run into a couple of issues however. Turns out not all servos are created equal in that different brands of servo (hitec 55) home (0 command) at the other opposite end of rotation. I could not find a way in software to reverse the servo. In RC it's not a problem as you can set servo reversing from your transmitter, not so much in Marlin. If you do what I did (servo did not survive as I did not get the output gear back in proper registration on the shaft) and reverse the outer 2 wires of the pot inside the servo you can effectively reverse the servo response. It's an old RC trick when you could not reverse from your radio. You MUST be very careful to re-assemble the servo properly or do what I did and bugger the servo and buy a new one, with the right rotation. Hitec go the opposite way, Futaba go the correct way and I don't know about JR. I am VERY new at this 3D printing thing, and it's almost got the better of me a few times since I started, but it is very cool.
I am not skilled enough to make modifications to the design but after building it I would, if I could, modify to provide a real servo mount as in ears for the screw mount, Mod the cover to provide a visual indication of the servo position ( I left the rod longer than required and made a hole in the cover to allow the end to stick up. Possibly round or chamfer the cover to allow the filament to pass by more easily, and finally, as I am using a full ring for the cooling fan I had to dent in the area where the probe wire passes as the two parts interfered with each other.
Overall I am extremely happy with this device and I will not be going back to an end switch or prox of any flavor.
PS: I forgot to add when I posted this that to avoid actual modifications to the cable or board that I cut down a 14 pn wire wrap socket to make an extension. I cut the center out of the socket and trimmed the length to 5 pins, so I wound up with 2 rows of 5 and long pins sticking out to which I made the pin3 connection. I was then able to plug the ribbon cable onto the rest of the pins and the socket end onto the board header. The probe wire I used was a piece of 1/16" stainless steel TIG wire (Tungsten Inert Gas welding wire), I only used this as I had it readily available and it is stainless. Thanks again for the excellent device.

Thank you for this detailled feedcack I appreciate.
Concerning the servo rotation maybe under MARLIN you could try to modify this line :
'#define Z_SERVO_ANGLES {115,10} // Z Servo Deploy and Stow angles
into something like
'#define Z_SERVO_ANGLES {10,115} // Z Servo Deploy and Stow angles

Unfortunately, my printer is no more under MARLIN and I cannot test this for you (I am running KLIPPER !)

Thanks for the reply! I did try reversing the values as you have said. Now whether I did something wrong (likely) or it just does not like doing that, I do not know but it did not appear to make any difference. The servo still seemed to park the same was regardless of the values. I am for sure not saying I may not have forgotten to upload after I changed the values as I was trying just about everything I could think of to reverse the servo. I am unfamiliar with Klipper so now I'll have to have a look at that. I have to check out your other mods/improvements as well. I just don't know what I'm gong to do with all the inductive sensors I bought.... Another project!

If you want to see my other mods, I think the best ones are the exoskeletons which give LOTS of rigidity to this poor acrylic frame ;-)
The bearing housings are a must too, you save mass on the mobile carriages which is always good to print faster or minimize ringing...

According to this: https://youtu.be/il9bNWn66BY?t=705 and this: https://docs.google.com/spreadsheets/d/1QDtd-0IK79gme_f80Rw_PB-nIActKWJJJvvAYd4u2uM/edit#gid=0, it looks like all inductive sensors are very accurate so the only reason to use this method is for glass, right?

inductive sensors sense the top of a metal bed, if you place glass on top and if the metal bed is bumpy, the probe will say that the glass bed is bumpy ...
If you want to probe with glass you need to install the big 18mm in diameter probe whose weight is 80g ...

not even that, if I install glass I can't use inductive sensor since it doesn't sense the glass. By 'this method' I meant your optical sensor?

If your bed is only glass with no metal under the glass, yes you need a sensor able to sense the glass and the inductive will not work on glass only beds.
My probe touches the surface, it will work over any surface (metal, plastic, fabric, paper, glass ...)
But most often the glass is set on top the aluminum bed, then an inductive sensor will sense the bed under the glass. In order not to crash the probe into the glass, the gmass thickness has to be lower than the sensor sensing distance. The inductive sensors rated for 8mm are rated over steel and not aluminum. Hence a sensor supposed to sense metal at 8mm will sense alu only at 3-4mm
==> the glass should be no more than 2mm thick and the sensor the big one !

Can you share what you make of this: https://www.thingiverse.com/thing:2241424? The author didn't post M48 results and I don't have the technical background to see if it is good. Sounds like it would be less accurate as it measures distance, right?

Anet A8 Optical Sensor Mount for Omron Spy 412 Auto Bed Leveling
by chertle

Seems to be quite good the results are posted...
M48 P10 X100 Y100
ecv: Mean: 2.514750 Min: 2.503 Max: 2.520 Range: 0.017
Recv: Standard Deviation: 0.005640

M48 P10 X50 Y50
Mean: 2.431000 Min: 2.425 Max: 2.437 Range: 0.013
Recv: Standard Deviation: 0.003905

M48 P10 X150 Y150
Recv: Finished!
Recv: Mean: 2.454750 Min: 2.450 Max: 2.460 Range: 0.010
Recv: Standard Deviation: 0.003052

Results with 100Celcius Hotbed:

Send: M105
Recv: ok T:150.1 /150.0 B:101.5 /100.0 @:29 B@:127

M48 P10 X100 Y100
Recv: Mean: 1.705250 Min: 1.697 Max: 1.712 Range: 0.015
Recv: Standard Deviation: 0.004931

M48 P10 X50 Y50
Recv: Mean: 1.641500 Min: 1.635 Max: 1.647 Range: 0.012
Recv: Standard Deviation: 0.004213

M48 P10 X150 Y150
Recv: Mean: 1.637250 Min: 1.632 Max: 1.642 Range: 0.010
Recv: Standard Deviation: 0.004100

I just tested my stock sn04 and the results are

M48 P10 X100 Y100;
SENDING:M48 P10 X100 Y100;
M48 Z-Probe Repeatability Test
Mean: 1.386250 Min: 1.377 Max: 1.402 Range: 0.025
Standard Deviation: 0.007093

So no need to look for something better unless I wish to print on glass, right?

Are there benefits to this approach that are better than the hall-o sensors? Asking because these I can get for $10, but this approach requires me to assemble everything myself (didn't find a ready-made sensor)

The advantages of this approach are:

  • sensor close to the head which is better for accuracy
  • optical sensor is really very very accurate
  • no need of weird motions to release the pin,
  • no limitations in Z
    the cons are:
  • need of a servo to release the pin
  • some soldering is needed

If you would like to go for hallon, this is a good product with some of the above pros missing !
Should you want to keep an optical sensor just search for "touch-mi sensor" ...

Thanks. Did you make statistical tests to assert the precision? I saw a comoarison video where the bltouch sensor was worse than the inductive ones. And do you know why there are several alternatives for hall sensors but only one commercial for optical?

Yes, i performed several repeatability tests and the results are excellent (just read the description...).
I don't know why hall sensors are used so much... They are analog sensors with all their drawbacks in terms of drift and température sensitivity...

Thank you for the detailed responses. I'm sold!. Now need to find the time to assemble this...

Good décision ! You should not be desappointed... Just follow carefully the instructions.

Comments deleted.
Comments deleted.

I'm sorry to tell but I have a big problem with the setup, although I'm sure it will be perfect when it's working.
Also I'm going to be as accurate as possible to tell what I did so this comment might help some people with problems

I printed all parts and installed it in my Anet A8, everything fine, and installed it.
Wiring was no problem because I cut the flex cable to the display at line 3 and soldered the servo pwm signal to it, so I didn't had to solder to the PCB. Also I checked the IR sensor, it will bring 5V if nothing between the sensor and about 0,1V when blocked.
I put the servo arm down, pin head laying on the support, sent M119 and got an open message. Then I push the rod 2mm up, positioned the flag well, so M119 sends a triggered, so far so well. Also the pin is lower than the nozzle by about 4mm so it will trigger when the nozzle is still 2mm over the bed, so hardware should be all right.

So I went to modify the config file.
I started with the Anet A8 autolevel stock anet seonsor config file (because I had an inductive probe before) and changed it like this
changed Z_MIN_ENDSTOP_INVERTING to false
checked that Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is not commented out(also it's written in the Z Probe chapter far after the offsets, but I don't think this will make a change, but i had to search it)
commented out FIX_MOUNTED_PROBE (obvious, but maybe should be in the tutorial)
activated #define BLTOUCH
activated #define Z_ENDSTOP_SERVO_NR 0
activated #define Z_SERVO_ANGLES {115,10} (and changed the standard values)
changed X_PROBE_OFFSET_FROM_EXTRUDER to -27 and y_PROBE_OFFSET_FROM_EXTRUDER to 17 (not like in the tutorial,but measured it by hand) and set Z_PROBE_OFFSET_FROM_EXTRUDER to -3 (fine tuning will come later with m851 command)
changed Z_CLEARANCE_DEPLOY_PROBE to 5 and checked Z_CLEARANCE_BETWEEN_PROBES to be activated
checked AUTO_BED_LEVELING_LINEAR is active
changed the PROBE_BED_POSITION to left 20 right 200 back 200 front 20 because the standard values combined with new nozzle probe offset will bring a compiling error message (cannot reach position)
checked Z_SAFE_HOMING is active
changed NUM_SERVOS to 1
checked SERVO_DELAY is set to 300 and active

So far as described in the tutorial, I compiled and uploaded it, but my servo did not move with M280 command.
So I added

'#define SERVO0_PIN 27

down at the * R/C SERVO support chapter.

When uploaded, I noticed my extruder now turns backwards, regardless if I click extrude or retract.
So way up in the config file, I changed SWITCHING_EXTRUDER_SERVO_NR from 0 to 1, and now the extruder runs correct.
Also the M280 command will work correctly, sending
M280 P0 S0
will move the arm way up, I sent
M280 P0 S10
and positioned the servo arm so that the pin will be higher than the nozzle so it won't catch to the print, and locked the screw.

So for the final testing, I turned the servo down by
M280 P0 S10
and checked the sensor with M119, will reply open.
So I manually lowered z to about 2mm between nozzle and bed, M119 deliveress triggered.
Setting the servo arm up by
M280 P0 S10
pulles the rod up (and of course higher as the nozzle) so M119 sends triggered.

Now I wanted to check the homing by G28, but before I put the servo arm down again by M280 P0 S115 (or restarting the printer) and hit G28.

In your Youtube Video, the servo arm rotates down and the printer head drived down on the Z axis until the sensor triggeres, drives up until the sensor is open again, drives down until triggered, drives up, moves to next position, just what I would expect.
But my printer, while driving down the z axis, the servo arm rises!!!
This causes the sensor to trigger up in the air, far away from the bed, then driving up the z axis and at the same time the servo arm rotates down, the sensor is open, now driving down the z axis again (slower) but again the servo arm rises, the sensor triggeres up in the air again.
This happens when homing by G28 and also by leveling with G29.
The G29 command is handled pretty fast because it just jumps from x/y position to the next x/y position and waving the servo arm.

When the servo arm would stop this behaviour, I would be pretty sure it would drive down to the bed and trigger just as intended, so I could measure my Z offset and go to work, but this way my z axis is homed up in the air.

Why does the servo arm move while homing/leveling?

Currently I am printing with the servo arm turned so it won't trigger when up and after the leveling, I add a code
M280 P0 S0, but I had to move the flag so it will trigger not 2mm between nozzle and bed but with about 0,4mm so the M280 P0 S0 will pull just a tiny bit higher than the nozzle but this is pretty annoying, also when the printed filament will warp only a tiny bit the pin will run into the printing.

Also I tried to change the Z_SERVO_ANGLES {115,10} to other values like Z_SERVO_ANGLES {60,50} so the servo arm has not such a big influence to the rod and won't trigger the sensor when wrongly driving up during homing/leveling, but it seems entering different values has absolutely no effect, the servo arm still moves just like with the (115,10).
Also I commented out the Z_SERVO_ANGLES {115,10} and manually entered #define BLTOUCH_DEPLOY 70 and #define BLTOUCH_STOW 50 but still no change in the rotation of the arm.

How can I check why the servo arm is moving when driving down the z axis while leveling/homing and stop it or, if nothing helps, change the angles of the servo arm so I can add a M280 command in my printer settings after the G28 and G29?

In the attachment my config file

I assume you're running a MARLIN firmware.
Your mistake is that you think this is a fixed probe while it is not ! You also think it is a BL Touch while it is not.
I wouls advice you follw the instructions and use the provided configuration.h to introduce the adhoc settings inside your config (for instance using Notepad++ and its "compare" pluging would help).
Here is an extract of the provided configuration.h that you shall follow :

  • A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
  • (e.g., an inductive probe or a nozzle-based probe-switch.)
    //#define FIX_MOUNTED_PROBE


  • Z Servo Probe, such as an endstop switch on a rotating arm.

    define Z_ENDSTOP_SERVO_NR 0 // Defaults to SERVO 0 connector.

    define Z_SERVO_ANGLES {115,10} // Z Servo Deploy and Stow angles


  • The BLTouch probe uses a Hall effect sensor and emulates a servo.
    //#define BLTOUCH


    //#define BLTOUCH_DELAY 375 // (ms) Enable and increase if needed


First fix all this, and it should work fine !

Yes that sounds logical. The thing is called bltouch like probe so I assumed to activate BLTouch.
I had no idea what a BLTouch sensor even is, so I googled and saw that its probe goes in when triggered and jumps out again at the next position, which might be ideal for the BLTouch sensor but not for this solution. This also would explain why I can't change the deploy and stow angles.
I would like to test it but my printer is currently running a job, so I will test the z probe settings of your configuration file instead of bltouch and update the thread.

I have a working Genuine Geektech 3dtouch (BLTouch clone) which is working fine.
I have been told that the Optical Z Probe will outperform my setup.
If I duplicate the connections at the extruder end, I assume I will have no problems.

Marlin. Do I need to make any changes, other than the offset for the probe?
If so, I will make a backup of my configuration.h file.

I have ordered an optical sensor, should have it soon.

You cannot wire the Bltouch and this probe in parallel.... But you can unplug the Bltouch and use the wires coming from the Mother board.
Concerning Marlin, the configuration file will be different :

  • a servo must be activated, the Bltouch disabled
  • the offset will be different
  • the z min pin for the IR shall be set reverse

Just back up your file and make a diff between your file and mine. (under Windows use notepad++ and it's plugins 'comare')

Understood, and that is exactly what I will do.
Yes, I love using Notepad++ with the compare plugin.
It's the civilized way to do things.
I have all the bits printed.

Thank you for the detailed reply.

Hi there! I loved my sensor, but now that I'm installing a RAMPS board, I have no idea at all how to hook it up... Any clue? I need to know where the Servo wire goes, and where the three wires that used to go to the board go...

Hi aeropic,

Thanks for the guide! It is very helpful in setting up an optical Z sensor!

I did come across one discrepancy. Your instructions say:
V ---> to connect to the +5V = middle pin of the mother board Z-endstop conector
S ---> signal , to connect to the right pin (where the red wire of the mechanical switch went)
G ---> Ground , to connect to the left pin (where the black wire of the mechanical switch went)

The problem that I ran into was that I had to connect the signal wire to where the black wire was and the Ground wire to where the red wire was. This is completely opposite of your instructions. I think one of us has our wires crossed! Haha

The image of the Anet board clearly shows the proper pinout.
Perhaps update the image and add in the V, S, and G letters to the appropriate spots. You could then remove the verbiage for the pin locations and just refer people to the image.

Thanks a bunch! I'm a happy camper with my new Z-endstop!

OK, thanks for your feedback. i guess ANET delivers its endstops with different wiring colors (which is not important for a switch).
I suppressed any reference to the wires colors !
What is important is the fact that if you plug the sensor with a direct wiring (straight wires) it will not work !

Hi aeropic, many thanks for your awsome designs. I got a question, I stopped at this part:

"send a M119 ==> with the probe low you should get a OPEN status.
Manually rotate the servo to rise the pin by 5 mm, send another M119 you should get a TRIGGERED status."

The servo arm looks rigid and wont let me manually rotate it, is this normal? I'm afraid of breaking it

Hi Keeto,
If you're afraid to damage your servo, you may rotate it using the M280 GCODE...
Send something like M280 P0 S110 will rotate your servo to the 110° position (pin released)
M280 P0 S10 will retract the pin

But, the simplest way to perform this TRIGGERED/OPEN test is just to raise the pin manually and let the servo in the 110° position. You can even do this without installing the servo !

Oh, I see. Thanks a lot. I thought I had to rotate the servo arm, forcing it. I think I have a problem though. Im getting the status always open. What testisg probe am I suppose to choose? I may have got that part wrong, am I supposed to select the Bl Touch in Marlin configuration.h?

Well, unscew your sensor from the support, keep it plugged to the z-min endstop and perform two M119 tests one with nothing inside the sensor's fork, one with a piece of cardboard inside.
You should see the status in repetier changing OPEN/TRIGGERED

If not suspect your wiring. If your sensor is the one from China coming with a red PCB, just look at the back there are some letters for the connector :
U ---> to connect to the +5V = middle pin of the mother board Z-enstop conector
S ---> signal , to connect to the right pin (where the red wire of the mechanical switch went)
G ---> Ground , to connect to the left pin (where the black wire of the mechanical switch went)

Omg, many thanks. I feel so silly now. Found the problem!! I messed up the sensor wiring. Thanks again, queep up with your awsome work.

You're lucky if it did not fry the ANET's port ;-)

Yes indeed :). My servo is acting strange when I press bed level on Marlin though

connections for the standard servos are:

  • black (left) : ground
  • red (middle) : + 5V
  • yellow or white (right) = signal

test your servo first with
M280 P0 S10

Yep, it works fine when sending codes through pronterface, or when I autohome. Only acts strange when I press Bed Level on Marlin

you might get a problem in the configuration file ? PM it to me, I'll have a look to it ...

I just did, thanks a lot mate!

Has anyone tried Marlin Unified Bed Levelling instead of the standard Bilinear which most use?

Yes I did, but this option is too big in terms on memory footprint to be compatible with the ANET's board. And this is the reason why no ANNETer is using it !

What do you use as a starting figure to compile Marlin on this line, 0?

'#define Z_PROBE_OFFSET_FROM_EXTRUDER xxxxxxxxxx // Z offset: -below +above [the nozzle] to be trimmed on your machine !!!!!!!!!!!!!!!

put a value like 3.0
This will allow you to trim the right value under the LCD z-offset value + save value

Thanks very much for the reply. I have everything ready to fit. Probably Sunday will try and get it done. The only thing I’m a little sketchy on is the staring position of the flag just before it’s activated. Could you please perhaps share a pic or set of pics which depict the start and end positions of the flag. Much appreciated.

A drawing is better than long explanations ...

(It is with the pin being released ready to sense the bed),
The light from the IR LED triggers the IR switch, when touching the bed, the pin and the flag will go upwards, the flag will cut the IR light before the nozzle comes in contact with the bed...

Ok so with the pin touching the bed the two towers have to be fully exposed to each other and when the pin goes up they should be fully covered? Therefore should I set so the flag hole is just covering the towers when closed so when it opens it opens quickly and without delay. I’m guessing I’m looking to the pictorially the position of the flag relative to open and close in terms of how much of the towers have to be closed visible to be triggered.

When sensing the bed the only transition that matters is light ON --> light OFF. There is no notion of opening "quickly" here, the speed is only given by the motion in Z and not by the flag position.

basically, when the pin is released by the servo place the flag more or less in the position of my drawing then manually slide it upwards on the pin (with the pin always in its down position until the swich triggers (M119 GCODE shall read a "triggered" state) then slide the flag back by around 1.5 mm and you'll be ready (check that M119 gives an "open" state)!

It's easier to do than to explain ;-)

Brilliant thanks for that. Have everything pretty much ready to go so hopefully will post a made and some test results tomorrow. Thanks aeropic, great little project. You should think about making ready kits!!!

Ready kits . LOL : time consuming, not enough money to make with this and most important : my pleasure is open hardware ;-)

Yeah fair enough. Great idea though and it should suffer from the electrical interference that seems to bug the bltouch. See marlin had a host of features to turn off fans, heating etc now when probing because of the issues. This is a great idea which could be mass produced like the BLTouch with none of the side effects.

OK first problem. Im getting the triggered and open as expected, but when I home it crashes into the bed?! Any idea why that might be. Im using it on an MKG Gen 1.4 all other functions seem fine. Servo moves as expected and get open and triggered as in the instructions.

well you're on track if M119 is working and the servo too ...
I see two possible root causes:

  • either the triggering point (in terms of Z motion of the pin) is too high ? Have you checked that M119 triggering is before the pin goes higher than than noozle ?
  • or it homes outside the bed (I mean the pin is outside the bed). Have you activated the "safe homing" function in MARLIN ?

fantastic, that was the key. The trigger point before the probe goes higher than the nozzle. My sensor has an LED so its easy to see when it triggers. I can carry on with my testing and then subsequent tidying up of the wiring. Ill then post results. Thanks Aeropic :-)

Just slide the flag few tenths of mm upwards so that the triggering comes earlier..
Once in good position don't forget to add a drop of CA glue on the top of the flag+pin to glue it to the pin...

Then post a 'I made one " please ;-)

These are the results I get.

Recv: Mean: 0.054000 Min: 0.048 Max: 0.057 Range: 0.010
Recv: Standard Deviation: 0.003742
Recv: X:113.00 Y:78.00 Z:4.95 E:0.00 Count X:11300 Y:7800 Z:2000
Recv: ok

Ill post a made just as soon as I tidy up the wiring..

that's excellent !

It works great thank you! I had a problem with the left white frame hitting the flag when the x axis was homing as well as having to move the x home sensor to the rear by about 6 mm. I also installed 2 aluminum bushings for the pin. I used some 2-56 model push rod material for the pin and the bushings were made from aluminum tubing for a model fuel tank. This made the pin and flag very easy to move. I used a printer photo-interrupter and I am getting a test deviation of .0015-.0018 over about 10 M48 tests. Very very happy! I only had about 40 servos to chose from and settled on a 9 gram that was $2 a few years back

Maybe your ANEt is from a first generation ? Mine is from july 2017 and has no problem of interference with the X-endstop...

Very good performances with your M48 tests. And for the servo, I had the same problem to select the right one among my old (crashed) RC planes ;-)

Please post a picture in the "I made one" section.

just got the A8 in February so should be new stock. About the only thing I would suggest as an update would be a loose fitting tab to keep the flag from twisting. I glued a very small one to the sensor and that helped. The gap between the 2 portions of the sensor on mine is 5mm and the flag could twist about 20 degrees and I think that is what hung up on the x home switch. So it might just be my choice of sensor rather than the design. A friend has a electronics recycling center so I get to go shopping for free.

Ah yes, it comes from the sensor you got. Mine (either KTIR0311S or TCST2103) have a gap of 2.9 mm which leaves very few angular excursion to the flag to rotate. it is kept in place with the thin frame on the flag. Just print a thicker flag ?

That's what I thought, the little tab I glued to the sensor is working fine and I will keep an eye open for a different sensor. I want to clean up the wiring anyway.

I find this design quite interesting, maybe I'll make and add it to my A8.
In the meanwhile I would like to contribute to the insights on variance and photosensor, that maybe can help others in the make. This is a bit long, hope to not bore anyone :)

First things first: some low cost TCST2103 sensor modules mount parts marked as such, while I doubt they're original ones. I compared them to originals from Vishay official distributors, and they show some difference. I only have one "low-cost alternative" at hand, and it shows no ambient light filter on detector. This could be more of an issue: if any light (say a LED bed illumination) filters to sensor, can easily add a bias, that makes the sensor behave differently, on different areas of test. Just be warned: a cover to shield sensor is a good start.

TCST2103, like many others, is an analog part. With this I mean that light passes through the slit, photocurrent is proportional to light, and with its 1 mm slit produces a 10% to 90% (closed or open slot) with the flag traveling 0.6 mm perpendicular to the sensor (if the flag is very sharp transitioning). The sensing for "engaged" is then dependent on input level threshold of the control board, or in the end of the MCU input line. Let's say the MCU sees that happening at 63% equivalent position; what you would expect is that it happens always there, however this isn't so precise over time or temperature, or on different parts - although in the few repetitive tests of auto-leveling procedure it should stay quite consistent.
There are a few solutions viable, more or less complex or cheap. The easiest ones are with smaller slit size sensors, like with a 0.3-0.25 mm window, reducing that neighbourhood of 63% (or whatever is that value in your case) to happen always in a shorter distance, so reducing variance on an optical basis.
Another solution could be a digital sensor, like OPB461 or OPB666, to cite a couple of them. These sensors have an internal comparator which helps making transition very sharp from the beginning. However they cost some more, and are (sometimes) less available.
A small circuit with a comparator added to the sensor itself could also work, but it adds complexity (if you're not building electronics often), maybe I'll try that when I have time to experiment wit this design(!)

As a final note, I had another thought on a reason for which a similar setup (i.e. with TCST2103-alike parts) can result with so different values. The device is internally made of two (possibly) separated units: emitter and detector, encased in plastic black shell; if the two parts have a minimal chance to move inside that case (I've seen it happening with many other slot sensors) they could add a variable offset.
I see their best use is when both are soldered on the same small circuit board, to add rigidity - the flying wires connection works fine until you require very strict repeatability.

Interesting post, thank you.
I think you're right, using a ready soldered sensor on PCB would limit any risk of motion of the IR LED versus the IR photo trans.
I performed some tests with the cheap Chinese IR end stop coming with a labeled TCST3103, they are working pretty well with a repeatibility test performance equivalant to the KTIR0311S one.
I'm not sure that it worths the efforts to go for a trully digital sensor ...

This looks like a very good auto leveling system. I'm going to try and build one myself but it's nog very clear to my how averything should be wired. Is it the same as a BLtouch? Or where can I fine more information on how to wire the optical sensor and the servo.

Yes, it shares the same connection scheme than the Bltouch.

This is brilliant. Kudos!

Recv: M48 Z-Probe Repeatability Test
Recv: Finished!
Recv: Mean: -0.014250 Min: -0.015 Max: -0.012 Range: 0.003
Recv: Standard Deviation: 0.001146

Thanks aeropic!

Excellent results ! What is your sensor ?
Please post a make ...

I used a TCST2103 and trimmed the pcb. I will post a make tomorrow!

OK, I've just run the tests again but realised the X100 Y100 will move the head to a different place than the G28, not sure if that would affect it, but running with M48 P5 V2 E L2 (ommitting the X and Y co-ords)

Mean: -0.013500 Min: -0.023 Max: -0.005 Range: 0.018
Standard Deviation: 0.006819

M48 by itself I get
Mean: 0.033750 Min: 0.030 Max: 0.038 Range: 0.008
Standard Deviation: 0.002016

Not quite as accurate as yours still but what's 0.0005mm between friends :)

I've done some X, Y and Z mods so they might have something to do with the increase in repeatabilty too, but it's been working really reliably since getting it set up.

That's a pretty good result. With M48, You get a range better than 1 hundredth of mm, which is excellent.
Everything with a range better than 5 hundredth is good for bed leveling !

Many thanks for this, good little project and really clear instructions. I posted a pic in the "I Made One" and I used the cheapest board-based TCST2103 I could find using a 2.25mm dia coathanger that was 125mm long

M48 (default settings)
Mean: -3.774750 Min: -3.780 Max: -3.767 Range: 0.013
Standard Deviation: 0.004395

M48 P5 X100 Y100 V2 E L2
Mean: -3.671500 Min: -3.692 Max: -3.642 Range: 0.050
Standard Deviation: 0.022727

If I were going to offer any feedback about the design then two posts with screw holes to mount the servo to would be a nice addition, but only because I didn't have any stickypads to hand :)

Thank you for this nice feedback and for having posted a "I made one" (much appreciated).

Accuracy is good but not as good as with the KIR 0331S, you're the second one with a range (worst case) of 5 hundredths of mm while I get results with a 10 times better accuracy... I have ordered the cheap TCST2103 switch and will check as soon as available !

I did not add the 2 posts with screw holes for the servo mount only because my servo was not exactly the standard cheap one found for arduino applications, it was few mm smaller. Moreover I'm not sure the screw head would not interfere with the pin and its tab...
What could be done would be to introduce a possibility to press the servo in place from above with a flat printed piece of plastic and two screws ...

I'm more than happy with the levelling and accuracy, I'm getting perfect first layers and that's all that matters (and for £4.37 worth of parts)

I have a very clean window with a clean edge but watching the LED it does dim slowly rather than immediately - I would have gone the KTIR 0311S route but didn't seem easy to get hold of in a hurry.

The USB mouse wire I have also has shielding that I've not yet grounded, no idea if that would increase the accuracy or not, but when you're talking microns it probably counts for something

I'm also happy having glued the servo to the top, so keep the design as it is :) My servo has an arm mounting dia of about 4.8mm so the servo_arm.stl didn't really fit even after drilling so I ended up using the arm that was supplied with the servo.

The fact the led fades slowly is interesting and gives an indication of why we might get less accurate results with the TCST2103. When I get this sensor, it will be very easy for me to install it just as an endstop and compare the results with the KTIR0311 (I already get a now unused KTIR0331S IR switch installed as a z-endstop, installing there the TCST will be done in a couple of minutes ! The KTIR came fully bare and does not have a led, i cannot compare visually...
I'll come back here to post the results.

I don't think the grounded wire is needed, my wiring is somewhat "wild" with Three servo wires prolongators in serial !
For the servo arm, If you at the bottom of this comments page i posted several tries for a 4.8mm, it seems the one finishing with 44.stl gives the best results. (comment to laserbee)
I would advice you try it and use this curved arm as the standard one might be too close to escape the pad if when powered up the servo has a glitch...

Servo Arm 48small worked the best for me, popped on with just the right amount of force - thanks !

Perfect, the idea is to avoid the need of a screw.
I will add some 4.8 servo arms to the files section... Thanks for the feedback

Yeah, it was a really good fit, it didn't need the screw but I put on in anyway :)

I look forward to seeing if you get worse results with that sensor too. It's interesting that Maninashed got similar numbers to me (though his are slightly better...)

If your chip doesn't have an LED, how do you know when the thing triggers to set it up?

EDIT: Here's mine triggering:


I just trimmed the flag position using M119 which returns the status of the endstops...
Thanks for the video, the Led is definitely really nice.
I like seeing the probe being retracted by the servo, really more fun than an inductive probe

Comments deleted.
Comments deleted.

It works!

A few added notes, which I think you could add to your instructions: Using the optical sensor on the PCB as I did, you can get the 5v and ground for the servo straight off the back of the optical sensor, and then get the signal off the pad on the back of the LCD. This means a few less wires going back to your main board.

Secondly, a 2.5mm knitting needle works well as a pin. You do have to heat up the top thingy for it to squeeze in though, and the flag is a bit fiddly until the glue has set.

Very cool !
The way you wired the servo is correct and is exactly the way I did too. I will explain this in the instructions thanks.
Please post a picture in the "I made one" section.

And if you could perform a M48 test under MARLIN I would be interested in the results with this sensor...

Send: M48 P5 X100 Y100 V2 E L2

Recv: Mean: -0.010000 Min: -0.037 Max: 0.033 Range: 0.070
Recv: Standard Deviation: 0.025495
Recv: X:113.00 Y:78.00 Z:9.39 E:0.00 Count X:11300 Y:7800 Z:3756

That range and standard deviation are a LOT higher than yours... Any ideas what might be the issue?

Try just sending the following G code to home all axis this only M48 without any E nor L parameters


Is your pin moving freely ? What is the color of the filament you used for the flag ?

Flag is black, probe is loose enough...

M48 Z-Probe Repeatability Test
Recv: Finished!
Recv: Mean: -0.037000 Min: -0.057 Max: -0.008 Range: 0.050
Recv: Standard Deviation: 0.015321
Recv: X:123.00 Y:88.00 Z:9.39 E:0.00 Count X:12300 Y:8800 Z:3756

Two options:

  • either the KTIR 0311S is a better IR switch than the TCST 2103 .... I will test the second as soon as I get it from China
  • or you get a flimsy frame. Mine is very very rigid as I added to the stock frame all the exoskeletons you will find in my things... Please post a picture of your whole ANET.

You could try to repeat the M48 test with the X carriage placed close to the X endstop so that there would be less leverage on the X rods. This is just to perform a test it will not solve anything. (take care however that the pin is over the bed !)
Nevertheless, your accuracy is good enough to get a good first layer don't worry.

Actually, I think I may have found something that could cause it more than frame wobble. My frame is pretty sturdy, bolted down to wood, &c...

I'll do a bit more investigating, but to be honest that accuracy is probably still better than I would have measuring it by hand! :)

One thing I need to sort out is a swipe line just before printing. As it does the levelling after heating up, it tends to ooze quite a bit of filament. Even with a skirt and good brim, it still tends to drag a bit of loose filament across the print surface. I am going to try to figure out how to make it do a single line across the front of the frame to get rid of any oozed filament!

Also, I'm printing a new filament guide that I designed, as I found the filament was catching the flag, and making the printer go all wonky (it kept going up and up, as the flag wasn't falling!)

for the swipe line, just add some GCODE in the slicer.

For the filament guide, I guide the filament through a guide attached at the right top screw of the LCD screen, the coil being on a shelf at the top right of the printer, the filament never goes in the top of the pin. Would that be the case, if would be easy to add a cover over the servo...

Ah, see, my filament is on a shelf behind and to the left of the printer, so the filament gets pulled right across the servo. My guide seems to have done the trick, though, and means the filament will always be guided straight down into the print head.

I've got an idea for the inconsistent accuracy of you probe.
Are you using BED PID ? If not the bed which is heated with a bang bang regulation at a frequency of around 5 seconds might dilate/retract and show a different Z position to the probe each time it is sensed... (You can see the bang bang regulation just looking a the bed red LED)

The way to see if this is a good clue is to try a M48 test with bed and nozzle both cold (at ambient temperature)...

Let me know ;-)

Yep, I've got bed pids enabled. I just tried it cold, and got this:

Recv: Mean: 0.030250 Min: 0.017 Max: 0.045 Range: 0.027
Recv: Standard Deviation: 0.008548

Which is a LOT closer to what you got on standard deviation, but still five times the range...

Well, this means you get something moving (either the bed or the bearings, or the frame ...) I don't think the problem is coming from the IR switch itself ..
I'm sensing on a glass bed clamped over the aluminum hot bed...
How is set up you bed ? I screwed (nut+ screw) a M3 bolt at each 4 corners or the bed, removed the threads in the H plate holes and adjust the height from under the H plate with wing nuts... The springs are rather compressed (15mm between bed and H plate)

My bed is set up exactly like yours, glass plate on hot bed, thumb screws underneath...

But I don't think it's something moving: when the test probing is happening it's only the z-axis that is moving, and only a tiny amount. I very much doubt that is causing the frame or the bearings to move, as the bed isn't moving between probes...

Recv: Mean: -0.034500 Min: -0.050 Max: -0.015 Range: 0.035
Recv: Standard Deviation: 0.009474

Recv: Mean: -0.026250 Min: -0.058 Max: -0.008 Range: 0.050
Recv: Standard Deviation: 0.013705

Recv: Mean: -0.027750 Min: -0.035 Max: -0.015 Range: 0.020
Recv: Standard Deviation: 0.005750

Recv: Mean: -0.494500 Min: -4.848 Max: 0.040 Range: 4.888
Recv: Standard Deviation: 1.451382 (NO idea what happened here!)

5 mm ????
Is you flag clean with sharp edges at the level of the window ? No remaining small hair ?
Is the pin really free to move ? Is it heavy enough (not alu knitting needles ?)
Temporarily try to place some M3 nuts at the bottom of the pin to increase the mass...

Yeah, that one was weird.

But my flag is clean, the pin is loose (maybe too loose??), and I've just put a big nut on the top:

Recv: Mean: -0.013750 Min: -0.030 Max: 0.010 Range: 0.040
Recv: Standard Deviation: 0.012158

For sure it's weird ...
The other figures are quite good. Since indeed only Z is moving maybe you get a poor Z bearing ? I got one that was a nightmare when rotating it perpendicular to the rod I got around 1mm of play...

I'm not really sure which bearings you are talking about, but I will have a play around with it tomorrow and see what's what. As you said, this is still accurate enough, I just think it could be better!

I've ordered another sensor just to make sure.

the bearings which are inside the white parts (left with motor mount and right) each side of the X carriage

@ laserbee : here is a head_cover to protect the mobile part from interfering with the filament. Not the nicest, but it should do the job. You need a small support to print it (rotate it 90° on X to put it flat on its big side).

It would be easy to include on the top a filament guide if you wish ?

Thanks for that!

I;m actually going to try to redesign the whole sensor support with a cover integrated into it. Though yours, with a filament guide, might work better than that!

Incidentally, I've tried a different sensor (same as the one before) and am getting the same readings more or less than I did before. I might order one of the ones you've got, and see if that makes a difference.

I introduced some fun ...

Wow, that's really cool! I will have a play around, and let you know how it goes!

except the color ;-) it seems quite good !

I changed the depth and cleaned the logo... If you print one take this file !

Now with added filament guide! (though I used the wrong one, and lost the logo. Oops.

One last question. I need to cut a new metal pin, as my extruder is a little lower. When the pin is ALL the way down, how far lower than the tip of the nozzle should it be? I don't want to cut it too short; I've stolen a knitting needle from the missus and she'll kill me if I steal another!

When the pin is all the way down (resting on the top paddle that shall be installed on the pin), the pin shall be lower than the tip of the nozzle by 4 to 5 mm.
This 4 to 5mm has not to be accurate as the final trimming will be done by sliding the plastic flag...

Aeropic this is such a great idea. Kudos to you.

For the wire I've used a piece of 14AWG wire, it seems to fit perfectly.
I think there might be an issue with the commands for testing. In the configuration file you have M280 but for the test, the M290 command is used. Also I had to add #define SERVO0_PIN 27 to the configuration.h file.

thanks !
The wire diameter is sipposed to be around 2 mm so that's rather 12AWG but as long as is fits the flag slot, it is not that important !
I made a typo error, the servo move command is indeed "M280 P0 Sxx" (I'll edit the doc thanks) (https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0ahUKEwip6riniNPZAhVFWsAKHcU8CUEQFghiMAM&url=http%3A%2F%2Fmarlinfw.org%2Fdocs%2Fgcode%2FM280.html&usg=AOvVaw2rR_QCZ5KHlVaG-o6D7qNu)

Concerning the addition of the servo pin, I do not understand why it was not needed for me !!!

Hi there. I'm interested in your design as an alternative to splashing out thirty quid on a BL Touch...

I have a few questions...

Firstly, it's a couple weeks since you uploaded it. Are you still happy with the design? Is there anything you'd change? Is it working well for you?

Secondly, I know very little about Arduino, so don't really get the changes you made to your configuration.h file. Is there any way you'd be able to upload your file, so I could compare it with mine and better understand where and how those changes are made?

Thirdly, would the following two components be suitable for this build:



The optical switch seems to be on a bit of PCB, does that mean it would not need the resistor?

Sorry for all the questions!

Hi LaserBee,

I do understand you, there is no need to spend such an amount of money for a z probe ;-)
Yes, I'm really very happy with this design. I does the job pretty well and even if meanwhile I've received my replacement inductive probe I will for sure keep the optical one which gives several advantages:

  • lighter (the inductive weights 80g)
  • closer to the nozzle
  • less intrusive, once retracted the pin is nearly at the level of the bottom of the heatblock which gives the opportunity to clean the nozzle easily
  • very accurate

concerning the configuration.h, I uploaded it yesterday, but take care I have several other options activated in MARLIN (linear advance, PID, ...) that might not cope your needs, just use it for comparison...

the components you selected are fine. The optical endstop will do the job but you'll have to trim the PCB length. A big advantage of this one compared to the bare optical switch is that is comes with ready soldered resistor ans with a LED (which is nice). As it seems attractive, I ordered one in China to replace mine ;-)
Thickness of the TCST2103 case is just 0.3mm thicker than KTIR0311S, stay tuned I will post a mod of the support to fit the TCST2103 (one line to fix in the SCAD file)

EDIT : done, IR_support_TCST2103.stl is on line

Thanks for the quick reply, and the advice! I will order up the sensor now. Seems I already have one of those stepper motors, so that's one thing less I need!

Is there an advantage to using an optical sensor rather than a physical end-stop switch? This system replaces the need for the Z endstop, right? So you could potentially re-use that switch, mount it on the bracket somewhere, and have a tab on the probe "click" it, rather than trigger the optical sensor?

It is not a stepper motor, but a servo motor like this one: (search for arduino micro servo)

Yes there are several advantages with the optical endstop !

  • smaller and can be located on top of the pin rather that at the end
  • higher accuracy as there is no mechanical contact
  • less prone to failure due to contact oxydation ...
  • to use a switch you need some pressure on the contact so with a switch any desgn of a probe I know is to attach the probe to the servo arm... Here again servo positionning is not rocket science... ;-)

Ah, I meant Servo motor. In fact, I think I have that exact one, out of a Arduino starter set!

Those reasons for the optical sensor are good, especially the fourth one. The optical sensor will have absolutely no resistance, so won't "bend" and throw off the calibration.

As soon as I've built it, I'll let you know how it works! (if I don't have more questions before then!

If the servo arm does not fit well on your servo, it is quite easy to modify the diameter, just let me know...

Sorry to ask another simple question, but I'm struggling to figure out exactly what kind of wires and connectors I should be buying to wire this in. I'm not scared of soldering, but don't have things like crimpers...

Could you point me in the right direction?

well you could buy some wires with plugs at the tip like this one:

then solder some wires to get the good length.
Same can be done for the servo plug or you can soldier a 3 pins male connector and insulate the solder joints...

Ah, I've already got loads of those 3 pin JST's! Which is the plug I need for the servo?

The servo comes with a standard 2.54 mm spaced female dupont connector. You can plug inside à 3 pins standard male connector

Perfect, thanks. Parts should arrive tomorrow!
I printed the servo arm, and my servo doesn't fit in it. Any chance you could upload one where the axle is 4.8mm diameter?

here are two options they differ by 0.1mm in diameter... just print both and tell me which one fits ?

They are both slightly too large, I'm afraid! Sorry, i didn't get your question about counting teeth. As far as I can tell, there's 20 teeth.

here are 3 other dimensions.
Each 0.1mm smaller 48large>48small>46>45>44

Smallest of the three is a tight fit, but will probably work the best! Thanks a ton!

Also, I cut the sensor off where you said, and hopefully the wee bit of copper I cut wasn't inportant! :D

No problem, it will be easy ! How many teeths on the head ?