The motor shown in the picture will be used as a pump, its main task will be to move the piston forward and backward. The result of its operation should be to push the air to a certain value. Initially I wanted to use the current consumption as a feedback for determining the torque to change the direction of the piston I wanted to use the current consumption value as feedback, but I came to the conclusion that this is not the best option as well as the rotation time, because the load on the motor will increase over time, and therefore it will move the piston slower. I've come to the conclusion That it is necessary to count number of made revolutions, but here a way for counting of made revolutions I could not think up. Maybe someone has already done something similar? Or there are other options for solving this problem?
If you want to move the piston between two positions, then the best and safest way is to detect the end positions of the piston.
Limit switches are the normal way to do this, a pair of micro-switches that the piston presses at the end of its travel would be a cheap and easy way to do it, with a simple interface.
Or you could attach a magnet to the piston, and use a pair of Hall switches, if you wanted a non-contact method.
You could count turns of the shaft with a rotary encoder and some logic or an MCU, but that would always be vulnerable to losing the true position of the piston, so you would probably want real switches at the ends anyway to establish the true position, or as a backup.
\$\begingroup\$ Or a rotary encoder and one limit switch to register "home". Lots of ways to skin this cat -- but my upvote is because you led with "detect the end positions of the piston". \$\endgroup\$ Jan 23 at 15:39