low memory available, stability problems may occur
Arduino IDE shows a low memory warning:
How can I solve it?
In the above warning, 'program storage space' is FLASH memory, and 'dynamic memory' is SRAM memory. Arduino usually has much more FLASH memory than SRAM memory. Low memory here is on SRAM memory. To reduce SRAM memory usage, You can do the following:
Store static strings in flash memory by using the F() macro
For example, change:
To
Change variable size to the minimum size by changing variable type
For example:
In the above code, maximum value of variable is 254. it only need one byte to store. int type takes two bytes. We can reduce the size by changing the type to byte, which takes only one byte. The above code become:
Remove unused variables
If variables are declared but not used, remove it to save memory.
Use String.reserve() when using String object
If you use String objects, use reserve() function to your strings to prevent the memory from fragmenting
In this case, you need to know maximum size of String you will use. For example:
Use local variables instead of global variables if possible.
For example, change
To
Move constant data to PROGMEM
By moving constant data to PROGMEM, we can save SRAM memory. See Arduino - PROGMEM
Buy Arduino
1 × Arduino UNO Buy on Amazon | |
1 × USB 2.0 cable type A/B Buy on Amazon | |
1 × Jumper Wires Buy on Amazon |