LED screen

Hi all,
I’m building an LED screen. Right now it’s 3x3. The problem is that I’m trying to make it display some images but it doesn’t stop flickering. Does anyone know why is it happening? Here is the code I’m using. I’m receiving a String from processing with the states for each LED on. I added an image of the connections at the end of this post

Thanks in advance.

char val;
String data = "";

int pinColumn = 11;
int pinRow = 8;

const int ancho = 3;
const int alto = 3;

int leds[ancho*alto]; 

int matrizLeds[ancho][alto]; 
int contador = 0; 

int temporal[alto]; 
char recibido[ancho*alto];

int counter = 0; 
void setup()
  for(int i=8; i<15; i++){
    pinMode(i, OUTPUT);
  for(int i=0; i<ancho*alto; i++){
    leds[i]= 0;

void loop()
  if (Serial.available()) 
    val = Serial.read(); 
    if (val != 'L') 
      recibido[counter] = val;
      leds[counter] = int(recibido[counter]);
      counter = 0;
      contador = 0;
      for(int i=0; i<alto; i++) { // row scan
        for(int j=0; j<ancho; j++) { // column scan
          matrizLeds[i][j] = leds[contador];
          contador ++;

void encenderLeds() {
  for(int i=0; i<ancho; i++) { // row scan
    for(int j=0; j<alto; j++) { // column scan
      if(matrizLeds[i][j] == 49){
        Serial.print("entre i=");
        Serial.print(" j=");
        digitalWrite(i+pinColumn, HIGH);
        digitalWrite(j+pinRow, LOW);
        digitalWrite(i+pinColumn, LOW);
        digitalWrite(j+pinRow, HIGH);


Could the flicker be due to the large amount of slow serial data you're outputting?

Drop all the printing. Read this:- http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html It is what you are trying to do.

Thank you both! I removed the Serial printing and it's now working :)