Arduino Uno R3 sketch freezes when using LED Matrix LED

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

#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();
}

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)

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.

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?

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

Thanks for the replys so far!!

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

Duracell publishes some data about the current / voltage

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


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.

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.

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

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