I am writing an Arduino code with 3 arrays.

Two of those are double and other one is int. Further first two arrays have nearly 420 elements for each. Now I noticed that with more that 89 elements on 3rd array the program stall, and stuck executing. But with 89 or less number of element it runs with out an issue.

What would be the issue?

  • 2
    That's hard to tell without seeing your code.
    – StarCat
    Jul 7, 2020 at 17:34
  • The limit is 32767 elements. Anything else is a problem with your code.
    – Majenko
    Jul 7, 2020 at 17:36
  • Also be sure to not be too close to the max memory. If there is not enough space left to put variables on the stack, the program will crash some way
    – chrisl
    Jul 7, 2020 at 18:14
  • 1
    Are these arrays declared by size at compile time? what does the IDE report as far as your memory use is concerted when it compiles the program. As stated before, kinda hard to help without seeing your code.
    – Chad G
    Jul 7, 2020 at 23:23

1 Answer 1


A Mega has 8 KB of memory.

You are using:

  • double (same as float on an Arduino, see double) , 4 bytes * 420 elements * 2 arrays = 3,360 bytes
  • int (2 bytes) * 89 = 178 bytes

In total this is 3,538 bytes

This is about 50%, so I'm unsure what the 'rest' is. You can take a look at the other related question that may show some answers (like using dynamic memory, memory gaps, or local/stack variables): What are the traditional ways to optimize program memory usage?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.