Problems with Serial Communication

What is wrong with this code, does it even work?
-The sensors are LDR (photocells)
-The code is designed to output certain numbers to the serial line when an LDR drops below a value of 150 (should the code be doing this or is this dictating the natural flow of information?)
-We are also receiving no information at the other end through max.

This programme is designed with the intention to trigger audio samples in Max.

int LDRpin1 = 0; //LDR1 in analog pin 0
int LDRpin2 = 1;
int LDRpin3 = 2;
int LDRpin4 = 3;
int LDRpin5 = 4;
int LDRpin6 = 5;
int val1; //value for LDR1
int val2;
int val3;
int val4;
int val5;
int val6;


void setup() {
  Serial.begin(9600); // baud rate
  pinMode(LDRpin1, INPUT); // declare LDR's as INPUT
  pinMode(LDRpin2, INPUT);
  pinMode(LDRpin3, INPUT);
  pinMode(LDRpin4, INPUT);
  pinMode(LDRpin5, INPUT);
  pinMode(LDRpin6, INPUT);
}

void loop () {
  
//LDR pin 1
val1 = analogRead(LDRpin1); //Reads the value in LDR# and stores variable
if(val1 < 150) //if value is lower than 150
{
  Serial.print(0); // print 0 to serial line
  Serial.print(" ");
}

//LDR pin 2
val2 = analogRead(LDRpin2);
if(val2 < 150)
{
  Serial.print(1);
  Serial.print(" ");
}

//LDR pin 3
val3 = analogRead(LDRpin3);
if(val3 < 150)
{
  Serial.print(2);
  Serial.print(" ");
}

//LDR pin 4
val4 = analogRead(LDRpin4);
if(val4 < 150)
{
  Serial.print(3);
  Serial.print(" ");
}

//LDR pin 5
val5 = analogRead(LDRpin5);
if(val5 < 150)
{
  Serial.print(4);
  Serial.print(" ");
}

//LDR pin 6
val6 = analogRead(LDRpin6);
if(val6 < 150)
{
  Serial.print(5);
  Serial.print(" ");
}
  Serial.println();
  delay(2);
}
Serial.print(0); // print 0 to serial line

Do you want 0, or '0'. In the world of ASCII, the two are very different.

My guess is, you want '0' (as in the character 0, not the value zero). Follow suit with all the other values you are printing out.

Well there are 6 parts of the code which use this process with their respective numbers in the print function. Ive basically taken whatever value comes from the LDR’s organically and instead printed in the serial line with a number respective of their LDR number. So LDR1 prints out 0, LDR2 prints out 1 etc etc.

Although I do not know and this is a guess, I think this is where I have went wrong. Should I be printing my own information to the serial line or the natural values from the LDR?

Well there are 6 parts of the code which use this process with their respective numbers in the print function

...where there should be just one, with some arrays.

We are also receiving no information at the other end through max.

You should try a very simple sketch just to test the communication, something with Serial.println("test") in the loop(). If that works, then you switch your focus on the code you posted.

Assuming that what you wrote is what you want, you can simplify somewhat (and see more of what’s going on) with something like:

int i,t=0,v;

void setup(void)
{  Serial.begin(9600);
   for (i=0; i<6; i++) pinmode(i,INPUT);
}
void loop(void)
{  for (i=0; i<6; i++)
   {  if (150 > (v = analogRead(i)))
      {  Serial.print("Pin");
         Serial.print(i);
         Serial.print("=");
         Serial.print(v);
         Serial.print(" ");
         t = 1;
      }
   }
   if (t)
   {  t = 0;
      Serial.println();
      delay(2);
   }
}

AWOL:

Well there are 6 parts of the code which use this process with their respective numbers in the print function

...where there should be just one, with some arrays.

Apologies, by arrays you refer to?

arrays