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.
http://www.arduino.cc/en/Guide/Troubleshooting#size
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.
2 Likes

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).

2 Likes

Hey Lance,

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

Liam.

1 Like

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

 case 49:
        if((r_flag1 == 0)&&(RecievedTemp1[14]==2))
        {
        Serial.println(F("ST<{\"cmd_code\":\"set_image\",\"type\":\"image\",\"widget\":\"image2\",\"image\":\"circle\"}>ET"));
        r_flag1 = 1;
        quan_hang1++;
        quan_lie1++;
        quan_youxia++;
//        quan[0]++;
//        quan[3]++;
//        quan[7]++;
        Serial.println(F("ST<{\"cmd_code\":\"set_enable\",\"type\":\"widget\",\"widget\":\"button1\",\"enable\":false}>ET"));
        }
        else if((r_flag1 == 1)&&(RecievedTemp1[14]==2))
        {
          Serial.println(F("ST<{\"cmd_code\":\"set_image\",\"type\":\"image\",\"widget\":\"image2\",\"image\":\"x\"}>ET"));
         r_flag1 = 0;
            cha_hang1++;
            cha_lie1++;
            cha_youxia++;
//        cha[0]++;
//        cha[3]++;
//        cha[7]++;
            Serial.println(F("ST<{\"cmd_code\":\"set_enable\",\"type\":\"widget\",\"widget\":\"button1\",\"enable\":false}>ET"));
        }
        
        break;
1 Like