# Arduino Uno R3 sketch freezes when using LED Matrix LED

**URL:** <https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851>\
**Category:** LEDs and Multiplexing\
**Created:** [February 28, 2025, 8:30am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851 "2025-02-28T08:30:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaplauncher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gaplauncher/32/1126596_2.png) [@gaplauncher](https://forum.arduino.cc/u/gaplauncher)\
**Post date:** [February 28, 2025, 8:30am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/1 "2025-02-28T08:30:46Z")

</div>

Hello All,

i have a issue with a sketch on a Arduino Uno R3 (even tried on Arduino Nano).  
I display some stuff on a 8x32 LED Matrix.  
The Arduino is powered by a 9V Block battery.

When i let it run it just freezes after around 20 minutes.

It does not happen when plugged into USB on my PC.  
But it is not low power of the battery because when i unplug the battery for some time it works again when plugging the battery back on.

I suspect it´s a problem with the code. As if RAM is full.  
I crawled this (and other) forums, trying different solutions but nothing helps.

Help would be highly appreciated because its for a costume for my daughter for next monday.

Here is the code (it has the pin definition for the NANO in it):

```arduino
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <avr/wdt.h>

#define delay_t 1 // in milliseconds

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

//Hardware SPI Arduino UNO
//CLK Pin > 13 SCK
//Data Pin > 11 MOSI

#define CS_PIN 10

// Hardware SPI connection
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

byte four[8] = {0x00, 0x1c, 0x36, 0x36, 0x3e, 0x36, 0x36, 0x00};
byte three[8] = {0x00, 0xcf, 0xcf, 0x86, 0x86, 0x86, 0x86, 0x00};
byte two[8] = {0x00, 0xe3, 0xf3, 0xb1, 0xb1, 0xf1, 0xe1, 0x00};
byte one[8] = {0x00, 0x60, 0x61, 0x61, 0x61, 0x79, 0x78, 0x00};

byte fourout[8] = {0xff, 0xe3, 0xc9, 0xc9, 0xc1, 0xc9, 0xc9, 0xff};
byte threeout[8] = {0xff, 0x30, 0x30, 0x79, 0x79, 0x79, 0x79, 0xff};
byte twoout[8] = {0xff, 0x1c, 0x0c, 0x4e, 0x4e, 0x0e, 0x1e, 0xff};
byte oneout[8] = {0xff, 0x9f, 0x9e, 0x9e, 0x9e, 0x86, 0x87, 0xff};

void setup() {  
  mx.begin();
  mx.control(MD_MAX72XX::INTENSITY, 0);
  mx.clear();
  }

void loop() {
  drawShapeLotta1();
  drawShapeLotta2();

  delay(10);
}

void drawShapeLotta1() {
  for (int i = 0; i <= 7; i++) {
    mx.setRow(0, 0, i, four[i]);
  }
  delay(delay_t);
  for (int i = 0; i <= 7; i++) {
    mx.setRow(1, 1, i, three[i]);
  }
  delay(delay_t);
  for (int i = 0; i <= 7; i++) {
    mx.setRow(2, 2, i, two[i]);
  }
  delay(delay_t);
  for (int i = 0; i <= 7; i++) {
    mx.setRow(3, 3, i, one[i]);
  }
  
  delay(200);
  mx.clear();
}

void drawShapeLotta2() {
  for (int i = 0; i <= 7; i++) {
    mx.setRow(0, 0, i, fourout[i]);
  }
  delay(delay_t);
  for (int i = 0; i <= 7; i++) {
    mx.setRow(1, 1, i, threeout[i]);
  }
  delay(delay_t);
  for (int i = 0; i <= 7; i++) {
    mx.setRow(2, 2, i, twoout[i]);
  }
  delay(delay_t);
  for (int i = 0; i <= 7; i++) {
    mx.setRow(3, 3, i, oneout[i]);
  }
  
  delay(200);
  mx.clear();
}

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 28, 2025, 8:37am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/2 "2025-02-28T08:37:25Z")

</div>

> [@gaplauncher](#):
>
> I display some stuff on a 8x32 LED Matrix.  
> The Arduino is powered by a 9V Block battery.

how are the LEDs powered ? what's the circuit ?

(a surge in current after a while when the battery starts getting heavily used could lead to a voltage drop that would crash your MCU. When you power from USB you get a steady ~5V/500mA from the PC and so won't see such an issue unless you want more than 500mA)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [February 28, 2025, 8:53am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/3 "2025-02-28T08:53:30Z")

</div>

Adding to J-M-L's reply another possible reason might be that your display is drawing too much current; with a voltage regulator that has barely any cooling it might go into thermal shutdown.

A battery like below? Not really suitable for Arduino projects.

 ![shopping](https://europe1.discourse-cdn.com/arduino/original/4X/b/b/5/bb5e9bdb7cad3a248c130e4ce30d5c0c5b99148c.webp)

---

<div class="post-metadata">

**Author:** ![gaplauncher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gaplauncher/32/1126596_2.png) [@gaplauncher](https://forum.arduino.cc/u/gaplauncher)\
**Post date:** [February 28, 2025, 9:07am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/4 "2025-02-28T09:07:56Z")

</div>

Hey, ok, is there anything that i can do in the code to not make the voltage drop?  
Like f.e. only using graphics for each of the 8x8 LED matrix separately and not more than one at once?

---

<div class="post-metadata">

**Author:** ![gaplauncher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gaplauncher/32/1126596_2.png) [@gaplauncher](https://forum.arduino.cc/u/gaplauncher)\
**Post date:** [February 28, 2025, 9:19am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/5 "2025-02-28T09:19:20Z")

</div>

And if i am allowed to ask. What would be a appropriate battery?

Thanks for the replys so far!!

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 28, 2025, 9:24am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/6 "2025-02-28T09:24:17Z")

</div>

> [@gaplauncher](#):
>
> What would be a appropriate battery

did you use that type of 9V battery ? it's definitely not suitable

Duracell publishes some data about the current / voltage

 ![9V-discharge](https://europe1.discourse-cdn.com/arduino/original/4X/6/1/f/61f2a0d3938bfe214d242e92e5500bdcb891b9fd.jpeg)

on the curve on the right side, you can see that at 250mA the voltage drops significantly really fast.

a Lithium Ion battery is more suitable as it can provide way more current

* * *

> [@gaplauncher](#):
>
> anything that i can do in the code to not make the voltage drop

if you want to use less current, you just need to turn less LEDs on and may be play on the intensity through PWM. the more LEDs, the more current. but really as you can see from the curves, this type of battery is not good for such a project. Keep it for your smoke detector.

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [February 28, 2025, 9:26am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/7 "2025-02-28T09:26:57Z")

</div>

> [@gaplauncher](#):
>
> What would be a appropriate battery?

5 or 6 AA batteries in series to Vin would be a better option. You might still run into the problem of overloading the voltage regulator and therefore might need a separate 5V for the display.

Alternative can be a power bank and feed the complete setup from that over USB.

---

<div class="post-metadata">

**Author:** ![gaplauncher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gaplauncher/32/1126596_2.png) [@gaplauncher](https://forum.arduino.cc/u/gaplauncher)\
**Post date:** [February 28, 2025, 10:00am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/8 "2025-02-28T10:00:43Z")

</div>

Hey, the powerbank is a good tip!!  
I just connected one i had lying around to it and it seems to work.  
Also thanks @J-M-L for the information and all!  
I was not aware about the 9V battery issue!

Thank you all a lot....it should be ok now...

Will post pictures of the device later if everything works fine...

Cheer Daniel

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 27, 2025, 10:01am UTC](https://forum.arduino.cc/t/arduino-uno-r3-sketch-freezes-when-using-led-matrix-led/1358851/9 "2025-08-27T10:01:24Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
