Is it possible to store values on an Arduino Uno for some days?

Hello,

I am still a very new to Arduino. But so far, I love it. Until now, I have successfully built the idea I had in mind, based on an Arduino Uno R3. It is just a counter based on an ultrasonic sensor which sends the "count" in realtime to an app I have developed via a Bluetooth component (HC-05).

Now, I would like to know if it is possible to store the count number on the Arduino itself, and only send the total when I request a synchronisation in the app. For example, the sensor counts 100 movements in a week and at the end of the week, I sync the arduino to my app. I would like the 100 result to be displayed into my app when I sync and reset the count to 0 on the arduino when it is done.

First of all, is it possible to store a value in the Arduino memory for some days? Would it be possible to do something even more ambitious and for example, store the count number for each days? And in my app, I would know how many counts have been calculated for a particular day?

Thanks for your help!
Axel

Your description is a little ambiguous. If the Arduino remains powered it will remember values for years, not just days. But all the collected data would be lost if the power failed.

To save data when the Arduino is de-powered you can write it to the onboard EEPROM memory. Be aware, however, that the EEPROM memory has a limit of about 100,000 write cycles so you need to be careful not to write the data more often than is absolutely necessary.

...R

Thanks for the fast reply. And you are right, I would like to keep the infos in memory even when the Arduino is de-powered.

Since it has a limit of 100,000 write cycles, is it still something which is often done in Arduino development? I mean, isn't it a bad practice? Maybe, what I could do is only write one time per "Arduino" session. Possibly just before it is shut down. Is it possible?

Possibly just before it is shut down. Is it possible?

Yes, if the program can somehow detect that the power is about to be lost.

You could regularly measure the supply voltage on an analog input, and if it falls below a given level, write the data you need to be saved to eeprom. If you had a suitable bulk storage capacitor ( perhaps 100uF? ) that would have enough energy to perform this task .

Note you will need a fixed reference - eg the internal 1.1v - to do this. Using the fullscale ( 5v) will only give you a proportional reading, which is useless. A suitable potential divider will be needed.

Recover the data when the arduino is powered up again.

Allan

Write-on-power-off is tricky. You need a lot of power and time to adequately flash the data into the EEPROM. (In this context a millisecond is a lot of time.)

Make it write the count every hour or something. Then you might lose up to an hour's worth of counting but at the end of a year one or two hours missing is no big loss.

If you connect up a ds1302 rtc module, they have about 30 bytes of battery-backed ram you can use. The rtc will keep track of the day or date also, so you can maintain a count for each day for a couple of weeks (maybe a month if the counts never exceed 255).

PaulRB:
If you connect up a ds1302 rtc module, they have about 30 bytes of battery-backed ram you can use.

Interesting. I presume you mean that an Arduino program can write any data it likes into those 30 bytes?

...R

As I understand it, yes. I don’t have one to test, my only ds1302 module packed up a few years ago. I only have ds3231 now and they don’t have any spare ram it seems. They do have AT24C32 eeprom chips, which have limited write cycles, 1,000,000 claimed which is 10x the Arduinos internal eeprom.

No, it's actually 56 bytes that are available on ds1307. 64 bytes in total, first 8 contain the date/time etc. So that's enough for 28 days' data assuming one 16 bit int per day.

100 movements in a week and updating the eeprom every time that the count changes allows for 1000 weeks recording; that's nearly 20 years. I would not worry about that.

Thank you very much for all of these informations! I really appreciate.

In fact, about the problem of detecting when the device is shutting down, I have thought about a simple workaround : I will just add a switch off button on my Arduino. And I will simply write to the EEPROM just before the line to switch off the Arduino. Is it a good solution in your opinion? Then, I will lose the data only if the battery is totally dead or if it is removed.

fraxool:
Is it a good solution in your opinion?

Yes. IF you always remember to press the button before disconnecting the power.

...R

Or add an FRAM memory chip, write to it as often as you like. Fast SPI speeds so no internal EEPROM 3.3mS write times, 10 to 100 trillion write cycle capability.
https://www.digikey.com/product-detail/en/cypress-semiconductor-corp/FM25040B-G/428-3200-ND/3788662
Larger memory sizes available also.