I am building a positioner and I store the current position to EEPROM when the move is complete. On start up, I want the positioner to return to the HOME position. I am running an UNO powered from the USB. My problem is that if the Arduino is turned off, I would like to stop the move and store the current position before the Arduino dies.

Note that this would also be relevant to devices like thermostats which remember the set point through a power outage.


  1. Store position in EEPROM at each step. No, that will wear out the EEPROM.

  2. Connect a large capacitor from +5V to Gnd. When this falls below a set level, trigger an interrupt (ISR) that stops motion and stores current position in EEPROM.


  1. Will #2 work, and how could I program it?
  2. Any other ideas I am missing?
  • Option 3: only store the position after 10 seconds of no change. Option 4: have a way of measuring the absolute position of the thing that is rotation, so there is no need to remember it's previous position. Option 5: Since you want to HOME it when power is reapplied, you could add a sensor that detects when it is in the HOME position. This is what some 3D printers do with limit-switches. They rotate the motor till the limit switch is triggered.
    – Gerben
    Oct 31, 2018 at 13:11
  • Why not just store the commanded position? If power should be lost, you can have it go to where it was last commanded.
    – CrossRoads
    Oct 31, 2018 at 13:23
  • @CrossRoads, that is option 6? Then option 7 is: use fram adafruit.com/product/1895 and store as often as you want.
    – Jot
    Oct 31, 2018 at 13:43
  • Yes, FRAM would be great too, practically infinite # of stores (Trillions). Store a hundred thousand a day for 100 million years.
    – CrossRoads
    Oct 31, 2018 at 14:16
  • How can I program that in Arduino? @Prof Huster > 5. When the number of writes gets to about 5000, increment the address of the data in EEPROM[0].
    – user58316
    Jul 22, 2019 at 16:05

2 Answers 2


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 – 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.


Thanks for all the suggestions. At first I wanted a circuit like @ratchet freaks. I wanted to keep the mechanics and circuits very simple since the positioner is 3D printed and uses a standard M3 screw to move, so that rules out limit switches and encoders. I also realized the typical move only takes a max of 10 seconds, so I could just store the commanded position like @CrossRoads suggested. When the HOME command is given it steps back to 0.

Here is my Answer:

  1. Store the EEPROM address of the persistent information at EEPROM[0].
  2. At that Address store the persistent information:
  3. Item 1: EEPROM[EEPROM[0]] The number of writes to this address block as a two byte unsigned int.
  4. Item 2: EEPROM[EEPROM[0]+2] The commanded position as a two byte signed int.
  5. When the number of writes gets to about 5000, increment the address of the data in EEPROM[0].

Working this way I'll gradually burn out the Arduino EEPROM, but it will take many years!

  • @JRobert: With that scheme, EEPROM[0] gets written every 5000 cycles. Nov 5, 2018 at 20:12
  • The address is updated every 5000 cycles of 5000 writes, so about 25 million position updates. Plenty for my use! Nov 12, 2018 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.