Hello!
I have a automated dispensing mechanism and I'm wondering if there is a way to count the number of times a program is run and store that value to refer back to later. Essentially, there is a limited number of items it can dispense and I want the program to notify the user when it is empty and needs to be refilled, then have it automatically set itself back to 0.
Hopefully this makes some sense; I know I can make a counter if I add some input element like a sensor to determine when an object is dispensed, but I'm not sure how to store that value when the machine is turned off and I was curious if this could be simplified to be done without an external input (aside from the program being selected and run).
One way to remember stuff across power cycles is to use EEPROM to store it.
using arduino eeprom
and poke around a little.
If you literally mean just a count of the number of times the thing has been powered up, it would be fairly easy to
read the number of times previously
increment
store that new number
right in your setup(), then go on to the rest of your code and use the new number in any logic that is to be informed by how many times it has run.
HTH
a7
There’s nothing wrong with counting UP, but often these mechanisms count down to zero.
No code changes if you want to change the starting value. Severa simple ways to do that.
EEPROM is your friend, just like google.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.