Data section exceeds available space in board

I’m making a small game recently and I want to use Arduino uno to do it. My code compiles without problems, but when I upload it, I get an error like the one shown in the picture, is it because I have too many variables defined?
Can someone please tell me how to fix it?

Arduino:1.8.12 (Windows 10), Development board: "Arduino Uno"

The project uses 6336 bytes, which occupies (19%) of the program storage space. The maximum is 32256 bytes. data section exceeds available space in board

Global variables used 3046 bytes, (148%) of dynamic memory, leaving -998 bytes for local variables. The maximum is 2048 bytes.
There is not enough memory; visit the following URL to follow the instructions to reduce memory usage.
Error while compiling for development board Arduino Uno.

Turn on in File -> Preferences
"Show detailed output during compilation" option
This report will contain more information.

The site referred to in the message has several options, but that is quite a bit of space that you need to get back.

The space used for variables is reclaimed when a function completes, so if you have variables declared at the global level that can be declared within the function, then that can save some space. Of course, the space is required when the function executes, so this method of saving space depends heavily on the program architecture.

If you put your string constants in EPROM that saves space (even though they are declared globally).

A more extreme solution is to store constant data to a SD card, but this also relies on only needing to load small amounts of data from the card at any one time.

If you are able to upgrade from the UNO then the 2560 has more SRAM, while ADAFruit and DFRobot have variants that use the ATSAMD21 chip with 32k (although these are 3.3v devices).


Hey Lance,

To add to Jeff’s recommendation I’d also suggest taking a look at the RPi Pico.


1 Like

A good news, I solved this problem by F().

 case 49:
        if((r_flag1 == 0)&&(RecievedTemp1[14]==2))
        r_flag1 = 1;
//        quan[0]++;
//        quan[3]++;
//        quan[7]++;
        else if((r_flag1 == 1)&&(RecievedTemp1[14]==2))
         r_flag1 = 0;
//        cha[0]++;
//        cha[3]++;
//        cha[7]++;
1 Like