Save Data before Shutdown
Thermostats would save the set point to eeprom once when the set point it set by the user. On startup it would just read the set point.

The analogue pins measure relative to VCC. So if you short the analogue pint to VCC the result will remain at max even as the voltage drops.

Instead use a diode to separate the measurement point from the power supply.







simulate this circuit &ndash; Schematic created using CircuitLab

As long as power is supplied the gpio input will be high. As soon as the power is removed the gpio pin will be low and the capacitor will need hold enough charge to save the position.

However what would happen if the positioner is manipulated when the arduino is off? Most devices have a callibration routine using end-of-travel detection or something similar they run on startup to find the home position.