const int buttonPin = 2; // smokedetector 1
const int buttonPin2 = 3; // smokedetector 2
const int ledPin = 10; // relay1
const int ledPin2 = 11; // relay2
// variables will change:
int buttonState = 0;
void setup() {
// initialize relay 1 pin as an output:
pinMode(ledPin, OUTPUT);
// initialize relay 2 pin as an output:
pinMode(ledPin2, OUTPUT);
// initialize the smokedetector 1 pin as an input:
pinMode(buttonPin, INPUT);
// initialize the smokedetector 2 pin as an input:
pinMode(buttonPin2, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
button2State = digitalRead(buttonPin2); // <-------------------------------this overrides what you did on the previous statement.
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) { // <------------THIS MAY NOT NECESSARILY BE TRUE. YOU DON'T HAVE BUTTONS IN YOUR SCHEMATIC.
// turn LED on:
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
}
else {
// turn relays off:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
}
}
Do you want to turn the pumps when both detectors are true, or when either of them are true? That condition isn't in your program as it is now.