Arduino Mega with ESP6288 more then 10 Relais need help

Hi my Name is Achim from Bonn in Germany.

I have find a Progamm Code in the Inet and i change them. It works very fine now, but i want conrol 16 Relay but by this my knowledge at the end.

Can someone help me , or is it impossible?

This is my first post vergive me for my english please.

Thanks for help Achim

ArduinoMegaESP8266_10Relais_mit_Stati_2_ZeilighoheKaesten.ino (29.6 KB)

const int relay1 =  22;
const int relay2 =  23;
const int relay3 =  24;
const int relay4 =  25;
const int relay5 =  26;
const int relay6 =  27;
const int relay7 =  28;
const int relay8 =  29;
const int relay9 =  30;
const int relay0 =  31;
const int relay11 =  32;
const int relay12 =  33;
const int relay13 =  34;
const int relay14 =  35;
const int relay15 =  36;
const int relay16 =  37;

Using an array would mean one line of code, not 16.

int val1 = 0;  //Relay1 abfragen
int val2 = 0;  //Relay2 abfragen
int val3 = 0;  //Relay3 abfragen
int val4 = 0;  //Relay4 abfragen
int val5 = 0;  //Relay5 abfragen
int val6 = 0;  //Relay6 abfragen
int val7 = 0;  //Relay7 abfragen
int val8 = 0;  //Relay8 abfragen
int val9 = 0;  //Relay9 abfragen
int val0 = 0;  //Relay10 abfragen
int val11 = 0;  //Relay11 abfragen
int val12 = 0;  //Relay12 abfragen
int val13 = 0;  //Relay13 abfragen
int val14 = 0;  //Relay14 abfragen
int val15 = 0;  //Relay15 abfragen
int val16 = 0;  //Relay16 abfragen

Same here.

  pinMode(relay1, OUTPUT); 
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(relay5, OUTPUT); 
  pinMode(relay6, OUTPUT);
  pinMode(relay7, OUTPUT);
  pinMode(relay8, OUTPUT);
  pinMode(relay9, OUTPUT);
  pinMode(relay0, OUTPUT);
  pinMode(relay11, OUTPUT); 
  pinMode(relay12, OUTPUT);
  pinMode(relay13, OUTPUT);
  pinMode(relay14, OUTPUT);
  pinMode(relay15, OUTPUT);
  pinMode(relay16, OUTPUT);

4 lines, using a for loop, not 16.

  digitalWrite(relay1,LOW);
  digitalWrite(relay2,LOW);
  digitalWrite(relay3,LOW);
  digitalWrite(relay4,LOW);
  digitalWrite(relay5,LOW);
  digitalWrite(relay6,LOW);
  digitalWrite(relay7,LOW);
  digitalWrite(relay8,LOW);
  digitalWrite(relay9,LOW);
  digitalWrite(relay0,LOW);
  digitalWrite(relay11,LOW);
  digitalWrite(relay12,LOW);
  digitalWrite(relay13,LOW);
  digitalWrite(relay14,LOW);
  digitalWrite(relay15,LOW);
  digitalWrite(relay16,LOW);

One more line in the for loop, not 16.

  SET_MODE:
      esp_serial.println("AT+CWMODE=1");                // Set Mode  
      monitor.print("\nAT+CWMODE=1");
  
      result = CheckResponse();                         // Check "OK" 
      if(result == OK){
        Serial.print(" OK");
        delay(200);
      }
      else{
        Serial.print(" ERROR");
        delay(1000);
        goto SET_MODE;
      }

Use a do/while statement, not a damned label and goto.

but i want conroll 16 Relay but by this my knowledge at the end.

The code does something. You want it to do something. If those two things were the same thing, it is unlikely that you would have posted. So, what is the code not doing that you want, or doing that you don't want?

Thank You for the answer.
Right i didnt wrote the Code i find them for 4 Relay and changed them but i want controll 16 Relay by 10 is want i can.
My english is not the best.

My projekt is that i want use 16 Relais with this code.
But when I erase the **/ then is the code to large for 16 Button.
By 10 Buttons is it possible more not.

Can somewhere help me with an example please?

Thanks Achim

But when I erase the **/ then is the code to large for 16 Button.
By 10 Buttons is it possible more not.

The reason is that you are uselessly pissing away resources on the String class.

Using a style sheet should significantly reduce the amount of data on your web page.