Ad Space — Top Banner

Sketch too big / exceeds program storage

Arduino Microcontroller Board

Severity: Moderate

What Does This Error Mean?

This error means your compiled sketch is larger than the Arduino's flash memory. The Arduino Uno has 32KB of flash (minus 0.5KB for the bootloader). Remove unused libraries, optimise code, or upgrade to a board with more flash.

Affected Models

  • Arduino Uno (32KB)
  • Arduino Nano (32KB)
  • Arduino Mega (256KB)
  • Arduino Leonardo (32KB)

Common Causes

  • Too many libraries included
  • Large lookup tables or constant arrays
  • Extensive use of Serial.print with long strings
  • Floating-point math library included (adds ~2KB)
  • Unnecessary code not removed

How to Fix It

  1. Remove #include for libraries you are not using.

    Each included library adds to the program size. Remove any you are not actually calling in your code.

  2. Use PROGMEM for large constant arrays.

    const int table[] PROGMEM = {1, 2, 3, ...}; PROGMEM stores data in flash without duplicating to RAM.

  3. Replace float calculations with integer math where possible.

    Including float math pulls in the floating-point library (~2KB). Use integer math with scaling (e.g. millivolts instead of volts).

  4. Upgrade to an Arduino Mega (256KB flash).

    The Mega has 8x more flash than the Uno. Or use an ESP32 with 4MB+ flash.

Frequently Asked Questions

What is the difference between program storage and RAM?

Program storage (flash) holds your compiled code — 32KB on Uno. RAM holds variables during runtime — 2KB on Uno. This error is about flash being full, not RAM.

Can I see how much space each library uses?

In Arduino IDE 2.x, the output shows program storage used after compilation. Remove libraries one at a time and recompile to see how much each adds.