Detecting a threshold position in movement

motormovementsensor

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.

enter image description here

Best Answer

A limit switch, such as one of these:

enter image description here

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.