// https://forum.arduino.cc/t/arduino-nano-serial-display-coding-help/1410954
int acval = 0, acvalold, actarget = 263;
int relayPin[] = {3, 4, 5, 6, 7};
void setup() {
Serial.begin(115200);
Serial.println("meaw");
for (int i = 0; i < 5; i++) {
pinMode(relayPin[i], OUTPUT);
digitalWrite(relayPin[i], HIGH);
delay(100);
}
}
void loop() {
acval = analogRead(A0); // read the value
if (acval != acvalold) { // only update if acval updates
acvalold = acval; // store old value
Serial.print("ACval ");
Serial.print(acval);
if (acval < actarget) {
Serial.print(" is less than ");
Serial.print(actarget);
Serial.println("V. Relays ON.");
for (int i = 0; i < 5; i++) {
digitalWrite(relayPin[i], HIGH); // relays ON
}
} else {
Serial.println(". Relays OFF.");
for (int i = 0; i < 5; i++) {
digitalWrite(relayPin[i], LOW); // relays OFF
}
}
}
}