Hi guys just a simple curiosity, I was thinking about making a menu for an irrigation sistem. Part of the menu would ask the user to enter how many times do they want the soil sensor to measure moisture (ex. If they set it to 24, it would check once per hour).
I was thinking of making the arduino create new variables for the number of times the soil sensor will go off, so the arduino can store each reading in a new variable.
My question is: is there a way to make the arduino create new variables as needed? If so, how? If not, how could i go about doing this?
You could make a function which takes the array size as a parameter. Then, inside your function you could create the array with that size and do all reading + calculation there.
Depending on how many you want to store, you might run out of memory.
Keeping a log like this is more a job for an SD card in my view.
Look up data logger shields on ebay.
arduino_new:
You could make a function which takes the array size as a parameter. Then, inside your function you could create the array with that size and do all reading + calculation there.
This approach can cause problems in the small memory of an Arduino. It is better to create the arrays at compile time and make them as big as the largest that will be required.
boylesg:
Depending on how many you want to store, you might run out of memory.
Keeping a log like this is more a job for an SD card in my view.
Look up data logger shields on ebay.
Robin2:
This approach can cause problems in the small memory of an Arduino. It is better to create the arrays at compile time and make them as big as the largest that will be required.
...R
The array will be created on stack so it won't hurt.
Donsa:
Hi guys just a simple curiosity, I was thinking about making a menu for an irrigation sistem. Part of the menu would ask the user to enter how many times do they want the soil sensor to measure moisture (ex. If they set it to 24, it would check once per hour).
I was thinking of making the arduino create new variables for the number of times the soil sensor will go off, so the arduino can store each reading in a new variable.
My question is: is there a way to make the arduino create new variables as needed? If so, how? If not, how could i go about doing this?
Thanks a lot.
why would you need a bunch of new variables to store an interval?
creating an array on the stack isn't a problem, until you do something dumb... like a) creating a monster of an array (demonstrated) or b) reading/writing beyond the end of your array (same problem in the heap);
it is common to see an array created in a function (e.g. a string buffer) and Arduino can handle that very easily. You have a stack, so you may use it.
If there is not defined an upper or max limit for the taken measurements in this case variables or elements in array then there is very high possibility to run out of any memory available. How is it possible to deal with infinite saved values in finite storage?
First i would determine whats the limit that makes sense for your project then will go from there if 10 readings then make array of 10 elements of appropriate type if 1000 etc then decide if toucan fit in flash if not fit in eeprom(taking into consideration max write cycles), if thats not enough then sd shield and so on.
Thanks guys, so helpful! Ill go with an array like many suggested. I just didnt want to do create the variables, of course i can write 24 variables and leave them there waiting, but i thought there was a better way to do it. Also thanks for the sd card tip, i was thinking about something like that but i didnt know where to start.