Also, pins 0 and 1 are your serial connection via the USB port. You're not going to want to mess with those either.
btw, loops are your friend.
#define PIN_COUNT 5
int pins[PIN_COUNT] = {2,3,4,5,7};
for (int i = 0; i< PIN_COUNT; i++)
{
digitalWrite(pins[i], HIGH);
}
it's the same as putting digitalWrite 5 times.
For example, this disaster here:
if(response.indexOf("INACTIVE") > 0) {
//if(flag == 1) {
Serial.println("LIGHTS OFF");
digitalWrite(0, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(1, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(5, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(6, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(7, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(8, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
flag = 0;
//}
}
else {
//if(flag == 0) {
Serial.println("LIGHTS ON.");
digitalWrite(0, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(1, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(5, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(6, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(7, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(8, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
flag = 1;
//}
}
Can be re-written as:
#define PIN_COUNT 5
int pins[PIN_COUNT] = {2,3,4,5,7};
bool inactive = ( response.indexOf("INACTIVE") == -1);
for (int i = 0; i < PIN_COUNT; i++)
{
digitalWrite(pins[i], inactive);
}
Serial.print("LIGHTS ");
Serial.println(inactive ? "ON" : "OFF");
Disclaimer: Haven't tried to compile or test any of the above.