How to use multiple LEDs

int sensor1 = A1;
int sensor2 = A2;
int sensor3 = A3;
int sensor4 = A4;
int sensor5 = A5;
int sensor6 = A6;
int sensor7 = A7;
int sensor8 = A8;
int sensor9 = A9;
int sensor10 = A10;
int sensor11 = A11;
int sensor0 = A0;
int LED = 2;
int LED1 = 3;
int LED2 = 4;
int RELAY = 5;
int LED14 = 14;
int LED15 = 15;
int LED16 = 16;
int LED17 = 17;
int LED18 = 18;
int LED19 = 19;
int LED20 = 20;
int LED21 = 21;
int LED22 = 22;
int LED23 = 23;
int LED24 = 24;
int LED25 = 25;

void setup(){
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED14,OUTPUT);
pinMode(LED15,OUTPUT);
pinMode(LED16,OUTPUT);
pinMode(LED17,OUTPUT);
pinMode(LED18,OUTPUT);
pinMode(LED19,OUTPUT);
pinMode(LED20,OUTPUT);
pinMode(LED21,OUTPUT);
pinMode(LED22,OUTPUT);
pinMode(LED23,OUTPUT);
pinMode(LED24,OUTPUT);
pinMode(LED25,OUTPUT);
pinMode(RELAY,OUTPUT);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
pinMode(A6,INPUT);
pinMode(A7,INPUT);
pinMode(A8,INPUT);
pinMode(A9,INPUT);
pinMode(A10,INPUT);
pinMode(A11,INPUT);

}

void loop(){
Serial.println(analogRead(A0));
delay(10);
Serial.println(analogRead(A1));
delay(10);
Serial.println(analogRead(A2));
delay(10);
Serial.println(analogRead(A3));
delay(10);
Serial.println(analogRead(A4));
delay(10);
Serial.println(analogRead(A5));
delay(10);
Serial.println(analogRead(A6));
delay(10);
Serial.println(analogRead(A7));
delay(10);
Serial.println(analogRead(A8));
delay(10);
Serial.println(analogRead(A9));
delay(10);
Serial.println(analogRead(A10));
delay(10);
Serial.println(analogRead(A11));
delay(10);

if(analogRead(A0) < 300){
digitalWrite(14,HIGH);
delay(100);
}
if(analogRead(A1) < 300){
digitalWrite(15,HIGH);
delay(100);
}
if(analogRead(A2) < 300){
digitalWrite(16,HIGH);
delay(100);
}
if(analogRead(A3) < 300){
digitalWrite(17,HIGH);
delay(100);
}
if(analogRead(A4) < 300){
digitalWrite(18,HIGH);
delay(100);
}
if(analogRead(A5) < 300){
digitalWrite(19,HIGH);
delay(100);
}
if(analogRead(A6) < 300){
digitalWrite(20,HIGH);
delay(100);
}
if(analogRead(A7) < 300){
digitalWrite(21,HIGH);
delay(100);
}
if(analogRead(A8) < 300){
digitalWrite(22,HIGH);
delay(100);
}
if(analogRead(A9) < 300){
digitalWrite(23,HIGH);
delay(100);
}
if(analogRead(A10) < 300){
digitalWrite(24,HIGH);
delay(100);
}
if(analogRead(A11) < 300){
digitalWrite(25,HIGH);
delay(100);
}

else {
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(14,LOW);
digitalWrite(15,LOW);
digitalWrite(16,LOW);
digitalWrite(17,LOW);
digitalWrite(18,LOW);
digitalWrite(19,LOW);
digitalWrite(20,LOW);
digitalWrite(21,LOW);
digitalWrite(22,LOW);
digitalWrite(23,LOW);
digitalWrite(24,LOW);
digitalWrite(25,LOW);

}
}

Do you have a question?
Code tags?

Before you go much further, please find out about arrays.

I want to make the above code to operate the lamp. The sensor is IR position control. When each sensor A0~A3 is detected, A0 = 14 LED ON , A1 = 15 LED ON. I want to turn on LED2 separately when all of A0~A3 are LED ON. Also, I want to turn on LED 3 when all of A4~A7 are LED ON, and turn on LED 4 when A8-A11 is on. Lastly, I want to turn on RELAY 5 when all A0~A11 are LED ON, but I want to ask how to proceed with the code. I've never done any coding before, so I'm at a loss. I need your help.

Hello
a structured array would be helpful too.
You can make logical group containing the pin information for the ADC and related LED. A subroutine==method has to handle this object and generate action on the result.
Have a nice day and enjoy coding on C++.

So how did you produce that code?
Is this a class assignment?
What sort of Arduino is this?

I found it on the internet with an Arduino Mega 2560 and made it. I'm asking because it doesn't work.

What does it do that you don't expect?
What doesn't it do that you do expect?

Have you looked at using array(s) yet?

FIRST I just want to turn on RED LED by analog signal, SECOND and when 4 RED LEDs turn on, one green LED turns on.- It should not work when 3 random RED LEDs are applied. GREEN LED works only when 4 RED LEDs are turned on unconditionally.
THIRD I want to operate 4RED LED * 3LINE = 12RED LED = RELAY ON. I want to implement this kind of behavior, but I can't.

How are we supposed to know from your code which pins control red LEDs, and which are green?

int sensor1 = A1;
int sensor2 = A2;
int sensor3 = A3;
int sensor4 = A4;
int sensor5 = A5;
int sensor6 = A6;
int sensor7 = A7;
int sensor8 = A8;
int sensor9 = A9;
int sensor10 = A10;
int sensor11 = A11;
int sensor0 = A0;
int LED = 2; //1F GREEN LED
int LED1 = 3;// 2F GREEN LED
int LED2 = 4; //3F GREEN LED
int RELAY = 5; // ALL RED ON LED -WORK
int LED14 = 14; //1F RED LED1
int LED15 = 15; //1F RED LED2
int LED16 = 16;//1F RED LED3
int LED17 = 17; //1F RED LED4
int LED18 = 18; //2F RED LED1
int LED19 = 19; //2F RED LED2
int LED20 = 20; //2F RED LED3
int LED21 = 21; //2F RED LED4
int LED22 = 22; //3F RED LED1
int LED23 = 23; //3F RED LED2
int LED24 = 24; //3F RED LED3
int LED25 = 25; //3F RED LED4

Please post links to that.


const byte RELAY = 5;

struct panelRow {
  const byte sensors [4];
  const byte redLEDs [4];
  const byte greenLED;
} ;

// You will need to put your own values in here.
struct panelRow panel [4] = { { {A0, A1, A2, A3}, {2,3,4,6}, 7},
                        { {A4, A5, A6, A7}, {8, 9, 10, 11 }, 12 },
                        { {A8, A9, A10, A11}, {13,14,15,16 }, 17},
                        { {A0, A1, A2, A3}, {17, 18, 19, 21 }, 21}
                      };  
 
void setup()
{
  Serial.begin(115200);

  for (int row = 0; row < 4; row++) {
    for (int redLED = 0; redLED < 4; redLED++) {
      pinMode (panel [row].redLEDs [redLED], OUTPUT);
      digitalWrite (panel [row].redLEDs [redLED], LOW);
    }
    pinMode (panel [row].greenLED, OUTPUT);
    digitalWrite (panel [row].greenLED, LOW);
  }
 
  pinMode(RELAY,OUTPUT);
  digitalWrite (RELAY, LOW);
}

void loop()
{
  int panelSum = 0;
    
  for (int row = 0; row < 4; row++) {
    int rowSum = 0;
    for (int  redLED = 0; redLED < 4; redLED++) {
      int reading = analogRead (panel [row].sensors [redLED]);
      if (reading < 300) {
        digitalWrite (panel [row].redLEDs [redLED], HIGH);
        rowSum++;
      } else {
         digitalWrite (panel [row].redLEDs [redLED], LOW);
      }
    }
    if (rowSum == 4) {
      panelSum++;
      digitalWrite (panel [row].greenLED, HIGH);
    }  
  }
  digitalWrite (RELAY, (panelSum == 4) ? HIGH : LOW);
}

(compiled, untested )

The answer you gave is correct. Thank you very much. I haven't been able to solve it for a week... Thanks to your reply, it's over. Looking at your coding, it seems that I am not good enough. I'll have to work a little harder. Thank you.

I just noticed I forgot to turn off the greenLED, but that will come out in the testing.

led.pdf (197.8 KB)

The terms you suggested are too difficult for me to understand. The behavior seems a bit strange. Please review it again based on the attached file.

It looks like I made it for four floors, not three.
Oops