# End-stops vs Encoders

**URL:** <https://forum.farmbot.org/t/end-stops-vs-encoders/2280>\
**Category:** Getting Started\
**Created:** [July 18, 2017, 10:52am UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280 "2017-07-18T10:52:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![whitecaps](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/w/ea5d25/32.png) [@whitecaps](https://forum.farmbot.org/u/whitecaps)\
**Post date:** [July 18, 2017, 10:52am UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/1 "2017-07-18T10:52:23Z")

</div>

I am a newbie to CNC machines. I’ve read the Farmbot doesn’t ship with end-stops but that they are a common way to calibrate for accuracy on CNC machines. The Farmbot docs give the option of automatically calibrating with rotary encoders or DIY end-stops which some people have written about using on this forum.

I need my Farmbot to be very accurate i.e. to nearest mm and I expect I am going to need to automatically calibrate it often.

I read this post and kinda wanted to know more [First Seeding, latest issues](https://forum.farmbot.org/t/first-seeding-latest-issues/2090/2).

So I have the following questions which I think would be really helpful to others in the community, feel free to provide links as answers:

1. Which is the best method for accurate automatic calibration encoders or end-stops and why? (A brief explanation of the pros and cons would be awesome)

2. What end-stops are recommended and where to buy?

3. What are the directions to install end-stops onto the Arduino RAMPS?

4. How do I get the Farmbot software to recognise them i.e. do I need to do anything other than turn on “Enable Endstops” in the Web Apps Hardware Settings?

---

<div class="post-metadata">

**Author:** ![Loveny](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@Loveny](https://forum.farmbot.org/u/Loveny)\
**Post date:** [July 18, 2017, 11:24am UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/2 "2017-07-18T11:24:07Z")

</div>

I have used (and seen used on professional CNC machines) these end-stops:-

> [@Nema 17 no encoders?](https://forum.farmbot.org/t/nema-17-no-encoders/1874/4):
>
> I used magnetic proximity sensors which are widely used in industry for this type of function; the sensor is [https://www.digikey.com/products/en?keywords=59145-010](https://www.digikey.com/products/en?keywords=59145-010) and the matching magnet is [https://www.digikey.com/products/en/sensors-transducers/magnets-sensor-matched/566?k=57145-000](https://www.digikey.com/products/en/sensors-transducers/magnets-sensor-matched/566?k=57145-000). You’ll need to work out how to mount them, here’s a picture of one of mine:

> [@Nema 17 no encoders?](https://forum.farmbot.org/t/nema-17-no-encoders/1874/8):
>
> @chrisb Thanks for the info about this magnetic endstop slight_smile I’ve just found (i think) the same ones in my country stuck_out_tongue[https://www.elfadistrelec.pl/pl/czujnik-reed-littelfuse-59145-010/p/13756644?q=59145-010&page=1&origPos=1&origPageSize=50&simi=97.8&no-cache=true](https://www.elfadistrelec.pl/pl/czujnik-reed-littelfuse-59145-010/p/13756644?q=59145-010&page=1&origPos=1&origPageSize=50&simi=97.8&no-cache=true)[https://www.elfadistrelec.pl/pl/magnes-trwaly-littelfuse-57145-000/p/13756667?q=57145-000-ND+&page=1&origPos=1&origPageSize=50&simi=92.97&no-cache=true](https://www.elfadistrelec.pl/pl/magnes-trwaly-littelfuse-57145-000/p/13756667?q=57145-000-ND+&page=1&origPos=1&origPageSize=50&simi=92.97&no-cache=true) Last question, how did you connect them to the RAMPS c…

They’re magnetic sensors, pretty sure they would be solid state so no moving parts to wear out. They’re sealed so suitable for operation in most environments. The receiver is normally open, so you just connect them to the RAMPS board as indicated somewhere in the documents, organised so that they switch to 5V when activated. Last time I tried them with the farmbot software they were detected reliably for homing, but not so in normal operation. But homing is when they should be used to get the best accuracy. The farmbot homing sequence isn’t as accurate as it could be, but you’ll need to make a feature request to get them to improve their homing sequence (or make the changes yourself).

Others may have alternative/better suggestions…

---

<div class="post-metadata">

**Author:** ![Klimbim](https://forum.farmbot.org/user_avatar/forum.farmbot.org/klimbim/32/1240_2.png) [@Klimbim](https://forum.farmbot.org/u/Klimbim)\
**Post date:** [July 19, 2017, 8:39pm UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/3 "2017-07-19T20:39:21Z")

</div>

@Loveny: What is the distance versus triggering graph for those? I am thinking about the reaction time of the board if the motor drives into them very fast… If that is a bit different each time you try it because of the processing time of the board, this could be a problem?!

---

<div class="post-metadata">

**Author:** ![Loveny](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@Loveny](https://forum.farmbot.org/u/Loveny)\
**Post date:** [July 19, 2017, 10:40pm UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/4 "2017-07-19T22:40:04Z")

</div>

I looked them up and they’re not solid state, the receiver is a reed relay switch (given the price that makes sense). Distance vs triggering will vary from device to device, orientation of the magnets, and magnet strength. None of that is important for setting an accurate position, the only thing that is important is repeatability. I know from my experience that relays are surprisingly consistent in operation, so while they may have ~1ms operation time, whatever the time is will likely be the same every time, probably to within 5% or less.

I’m using mine for setting the home position, and the algorithm I use has the motor moving slowly at 50 steps/s, so that’s 20ms between steps. I’m sampling the input at 100kHz (every 10 microseconds), so I will detect the input and stop the motor at exactly the right position every time. The only question is the repeatability of the sensor switching. I have a commercial CNC machine here that uses the same sensors, and I’ve never noticed a repeatability problem with it.

There are plenty of ways to detect an accurate position, each with varying characteristics. I’d be interested to know what anyone else thinks would be a better method. It would be better to use a hall effect switch, but that requires power and then sealing. Or an optical slotted switch, but you’d have to keep it clean and clear of debris.

As for driving into them, that’s a control system problem… don’t move the gantry outside the set boundary. My maximum speed is something like 2000 steps/s, which is only 500 microseconds between steps, so my 100kHz sampling still far exceeds the step rate, so I’ll detect the sensor within 1 step. So to avoid hitting the sensor I just need to slow down fast enough. I’m getting \>10mm clearance between the magnet and sensor, so I just have to slow down and stop within 10mm.

---

<div class="post-metadata">

**Author:** ![Klimbim](https://forum.farmbot.org/user_avatar/forum.farmbot.org/klimbim/32/1240_2.png) [@Klimbim](https://forum.farmbot.org/u/Klimbim)\
**Post date:** [July 20, 2017, 6:46pm UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/5 "2017-07-20T18:46:53Z")

</div>

> [@Loveny](#):
>
> Or an optical slotted switch, but you’d have to keep it clean and clear of debris.

Regarding optical sensors, I`ve got some experience, working in that field:  
Laser Sensors: Forget about them in “real” sunlight conditions. None I reviewed would be accepting the outside ambient  
sunlight “disturbance”.  
Ultrasonic: Forget about it, if you´ve got wind floating across the thing will get mixed up.  
Hall: Could work, why not? You would need to power them but that is not a problem. You could even very nicely set your “calibration” curve mm vs. voltage output…

> [@Loveny](#):
>
> My maximum speed is something like 2000 steps/s, which is only 500 microseconds between steps, so my 100kHz sampling still far exceeds the step rate, so I’ll detect the sensor within 1 step

Which A/D are you using? The one from the RAMPS? Why is that then a problem for the guys to sample that high? 100kHz are crazy to sample and way way way enough. Lets say at least 2 times the frequency you would need:  
2000 steps / s equals 4 KHz to detect a step correct, right?

Looking forward into an interesting discussion @Loveny 😉

---

<div class="post-metadata">

**Author:** ![Loveny](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@Loveny](https://forum.farmbot.org/u/Loveny)\
**Post date:** [July 20, 2017, 11:39pm UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/6 "2017-07-20T23:39:56Z")

</div>

The sampling rate is for generating the step frequency, not measuring it. The higher the sampling frequency the less jitter you get on the output frequency.

The encoders are read directly in the micro timer, no sampling required (other than that of the micro which is up around 50MHz). But if I were using an AVR then I’d certainly be trying to get the sampling rate up around 40kHz based on the measurements I made at the beginning. That’s certainly do-able but it would require moving the count maintenance out of the ISR (and everything else too), just do the sampling (and frequency generation). Alternatively, I’d consider moving the encoder signals onto external interrupt pins.

The end stops are sampled at 100kHz because that’s a convenient place to read them, and doesn’t involve anything other than to read the state and stop the motor if activated.

We use infra-red proximity sensors on the cricket bowling machines I design, they work fine in direct sunlight. We don’t need any position accuracy so I haven’t assessed their performance in that regard, I’d expect the magnetic ones to be better though. The infra-red sensors aren’t suitable for wet weather outdoor use, although because I’ve got my unit in a greenhouse I’ve fitted an analogue infra-red (10-150mm) sensor to the bottom of the seeder tool to measure how far away the soil is, so I can plant roughly at the correct depth.

---

<div class="post-metadata">

**Author:** ![roryaronson](https://forum.farmbot.org/user_avatar/forum.farmbot.org/roryaronson/32/24_2.png) [@roryaronson](https://forum.farmbot.org/u/roryaronson)\
**Post date:** [July 21, 2017, 2:13am UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/7 "2017-07-21T02:13:10Z")

</div>

I’d love to see your soil depth sensor explained in more detail in another topic 🙂

---

<div class="post-metadata">

**Author:** ![Klimbim](https://forum.farmbot.org/user_avatar/forum.farmbot.org/klimbim/32/1240_2.png) [@Klimbim](https://forum.farmbot.org/u/Klimbim)\
**Post date:** [August 1, 2017, 7:58am UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/8 "2017-08-01T07:58:43Z")

</div>

> [@Loveny](#):
>
> I’ve fitted an analogue infra-red (10-150mm) sensor to the bottom of the seeder tool to measure how far away the soil is, so I can plant roughly at the correct depth.

Do you have more information @Loveny?

---

<div class="post-metadata">

**Author:** ![Loveny](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@Loveny](https://forum.farmbot.org/u/Loveny)\
**Post date:** [August 1, 2017, 8:17am UTC](https://forum.farmbot.org/t/end-stops-vs-encoders/2280/9 "2017-08-01T08:17:25Z")

</div>

> [@Seeder IR distance sensor](https://forum.farmbot.org/t/seeder-ir-distance-sensor/2308):
>
> @roryaronson Here are some details of the distance sensor I added to the seeder. It’s an infra-red distance sensor from Sharp, on a carrier board from Pololu, this one I think [https://www.pololu.com/product/2474](https://www.pololu.com/product/2474). Here are some pictures:- The sensor connects to the 5V/Gnd and gives an analog output which varies with the distance (between 10cm and 150cm). The output isn’t linear because it measures infra-red reflected energy, so it needs calibrating, but that’s easy enough; jus…
