I am trying to build a simple mechanical input/output system that moves linearly. The primary requirement is that it is as cheap and simple as possible.
One method I'm investigating is to use a simple and cheap DC motor to drive a linear shaft (kind of like a rack-and-pinion).
What I'd like to be able to do is, while the motor is not running, detect if the user pushes back on the shaft. Even better would be to detect how far they pushed on it.
I could use clever sensors or slide potentiometers, but I'm wondering if I can just detect the current generated by the resulting rotation of the DC motor? When manually rotated, I imagine it would behave a little bit like a generator and produce some voltage?
Is this possible? If so, how might I go about doing this?
Permanent magnet DC motors are generators and produce a voltage proportional to the rotational velocity of the shaft. The output can be several volts for a small motor. If you ground one terminal, the voltage at the other will be positive or negative depending on the direction of shaft rotation. You can measure positive voltages with the analog input (do not exceed Vcc) but without additional circuitry, you can't measure negative voltages.
Use the attached circuit on the analog input pin to protect it from negative input voltages, or voltages greater than Vcc.
There are already diodes in the Arduino chip that can accomplish the same task that the two 1N4148 diodes do, but it is best not to stress them. The resistor values and the diode types are not critical.