Iterating an array of relays Bear with me as I'm fairly adept at C# but I am having a problem understanding how to get an array iterated.

I am writing a program to test relay boards, it will eventually have an input mechanism to select the number of relays on the board. For now, i just need to get an array iterated to move on with the code.

The biggest relay board I've seen has 16 relays, so....

#define Relay1  2  // Arduino Digital I/O pin numbers for UNO R3
#define Relay2  3
#define Relay3  4
#define Relay4  5
#define Relay5  7  
#define Relay6  8
#define Relay7  9
#define Relay8  10
#define Relay9  11  
#define Relay10  12
#define Relay11  13
#define Relay12  A0
#define Relay13  A1 
#define Relay14  A2
#define Relay15  A3
#define Relay16  A4

int relays[]{ Relay1,Relay2,Relay3,Relay4,
    Relay5,Relay6,Relay7,Relay8 };
int maxRelayCount = 8;
char rx_byte = 0;

void setup()   //Initializes all variables and settings
{
  Serial.begin(9600);
 // create an input for the amount of relays on the board
//hardcoded for now

//Set pins to OFF &amp; declare pins as OUTPUTS
 for(int i = 0; i &lt; maxRelayCount; i++)
 {
   digitalWrite(relays[i], RELAY_OFF);
   pinMode(relays[i], OUTPUT);
   //How to convert i to a string in c++?
   //Serial.print("Relay " +[i] + " set HIGH and as OUTPUTS");
 }

 //Check that all relays are inactive at Reset
 delay(4000); 

}


So there are two issues. If I remove the loop and just hard code 8 times to set HIGH and OUTPUT it works fine, but the loop does not and won't upload to the Arduino, thus the reason I believe it is wrong. Secondary question is how to convert the counter i to a string to concatenate the message
the loop does not and won't upload to the Arduino


Most likely because RELAY_OFF has never been defined anywhere. Change that to HIGH (if that is what your relays need to turn off), or define it somewhere.

Also there is no loop() function - is that just you being economical with the paste?


  Secondary question is how to convert the counter i to a string to concatenate the message.


Simple: don't.  There's no need.

Serial.print("Relay ");
Serial.print(i);
Serial.println(" set HIGH and as OUTPUT");