# Detecting a threshold position in movement

I am raising an object/platform up and down using a DC motor connected to a threaded rod. I wish to know exactly when the top of the object reaches a certain threshold point during its movement, sort of like a limit/end-stop. See drawing below.

What would be the best way to do this such that my microcontroller can be notified with low latency (< 50 ms) and good positional accuracy (< 1 mm)? Would mounting a simple reflective optical sensor at my desired height do the job?

Note: I understand a stepper motor + driver would have been an acceptable solution but I'm going with a DC motor for lower cost, and because I only need to "know" one position along the movement.

• Maybe a slotted hall switch with matching metal screen? – venny Sep 15 '14 at 20:57
• Would you be more specific? You wrote "... microcontroller can be notified with low latency", how long is that, 1 millisecond, 100 milliseconds? You wrote "good positional accuracy", what does that mean, 1mm, 0.1mm, 10mm? – gbulmer Sep 15 '14 at 21:54
• @gbulmer: Good point; I have specified them with an edit above. – boardbite Sep 16 '14 at 0:01

A limit switch, such as one of these:

They're cheap and plentiful. For a switch like that, you would connect the digital input pin of the microcontroller to the common pin of the switch. The NO and NC pins of the switch would be connected to power and ground. When the switch is relaxed, the digital input sees one voltage. When the object gets close enough to depress the switch, the digital input sees the other voltage. Your microcontroller then tells the motor to stop.

For a non-mechanical solution, you can use a magnetic proximity sensor. The simplest would be a reed switch. When a magnet mounted on the moving part gets close to the stationary reed switch, the switch activates and signals to the microcontroller similar to the limit switch. Reed switch are also very cheap.

Beyond that, there's a world of proximity sensors that represent the whole range of cost, complexity, and accuracy. Just type "proximity" into Digikey to get an idea.

• Yup, come in lots of flavors. Fancy ones have ball bearing rollers on the end of the lever arm. – George Herold Sep 15 '14 at 22:21
• Microswitch used to be a brand name for this style of snap-action switch, but it's become genericized. Because of the snap action they've got quite good repeatability. – Spehro Pefhany Sep 15 '14 at 23:52

Another cheap alternative is an (IR) slotted sensor. They are used a lot in printers.

• In this kind of arrangement, I suppose there would be some opaque tape or plastic overhang of the moving cartridge head, that can go into the slot? – boardbite Sep 17 '14 at 1:00
• Correct. (which in itself is too showrt for a comment :( ) – Wouter van Ooijen Sep 17 '14 at 6:02