Basic Serial Out issue with Array

hi There, I'm trying out a basic program which is supposed to output a set of values on a for loop.

void setup(){
  Serial.begin(115200);
}
#define s 870
void loop(){
  int in[s]={
    0    }; 
  int on[s]={
    0    };
  Serial.println("abc");
  for(int i = 0; i < s; i++){
    Serial.println("abc");
    Serial.println(in[i]);
    //Serial.println("abc");
    Serial.println(on[i]);
    //Serial.println("abc");
    delay(500);
  }
  Serial.println("abc"); 
}

The problem is that in the loop if the in and on both are used, the serial output does not display anything, even the abc text, which is out of the loop...if I take out one of the in or on statements, it works fine. Can someone tell me whats going on here ?Thanks in advance

Which MCU/board you are using?

defining some thing below the setup() is not right place.

#define SIZE 10
void setup(){
  Serial.begin(115200);
}

void loop(){
  int in[SIZE]={0};
  int on[SIZE]={0};
  Serial.println("abc");
  for(int i = 0; i < SIZE; i++){
    Serial.println("abc");
    Serial.println(in[i]);
    //Serial.println("abc");
    Serial.println(on[i]);
    //Serial.println("abc");
    delay(500);
  }
  Serial.println("abc"); 
}

By following above style/rule of code i hope it will run. One more thing, size of array EDIT~~:/variable~~ depend on MCU RAM.

Thanks. You were right. When i reduced the length of the arrays it worked. For the benefit of others, I used a Arduino Uno Rev C. Maybe will try with Mega...

#define s 870
void loop(){
  int in[s]={
    0    }; 
  int on[s]={
    0    };

That's 3480 bytes of RAM, when you have 2048. No wonder it crashed.

Thanks I didnt think of the calculation.....Now I know... :slight_smile: