Arduino Memory

Hi I want to program a counter trought my arduino I know it is really easy to do but here is the difficult part

I want to unplug my arduino and when I plug again start from the last value I left. in other words save all the previous data at my arduino memory

It is possible to do that?
What I need to do it?

Hello,

How fast will the value of the counter change?

If not often (once per hour, for example), then you can write the value of the counter to the EEPROM memory everytime the value changed. Because the EEPROM has a limited amount of write cycles before it starts to fail to be written, you must not write every milliseconds to it. Then in setup(), you read the value from EEPROM.

Also, there are hardware ways to make the arduino detect that it's about to shutdown, so you can write in EEPROM at this moment.

guix:
Also, there are hardware ways to make the arduino detect that it's about to shutdown, so you can write in EEPROM at this moment.

This piqued my interest. Can you explain further? ie If the power is cut to the Arduino, which is the usual way of shutting it down, how can this be achieved?
Or do you mean a button would need to be pressed immediately before power-off, to save the counter value at that moment?

Supercap and boost regulator to hold the voltage up even longer.

Delta_G:
You can use a supercap to hold just enough voltage to run the processor just long enough to get in a couple of eeprom writes before the processor dies.

I considered something like that, but how do you detect that shutdown is about to occur? Constantly monitor the supply voltage maybe, and if it dips below a certain threshold, quickly save the counter to EEPROM? (As long as the supercap can keep the voltage up long enough for a couple of analogRead()s and then the time it takes for an EEPROM write. (Not sure how long an EEPROM write takes.)
I'd be concerned about that method too, unless either the internal 1.1V or an external reference is used.
Or is there a more elegant way of doing it?

Edit: I just found an old thread on the subject here:- Power loss save...

Edit2: After a little further thought, and considering the overhead for the constant analogWrite() calls and the 100uS per call, plus the fact that the calls are bound to come some time apart, I like the idea of an external comparator, detected by a pin-change interrupt.