Hi,
i need help to program this:
I have two switches on 2 inputs, 3 relays for outputs (2 lamps, one in bath, one in WC and one relay for fan for both places).
Logic would be:
- when i turn switch on I turn on lamp in bath and turn on a fan.
- when turn off switch turns off lamp in that place, and fan lets say turns off with delay after 5 minutes.
- with other button turn on lamp in WC and turn on a fan too, when turn off switch the fan turns off with delay after 5 minutes.
I Started with this code:
const int LightWCPin = 2;
const int LightBathPin = 4;
const int LightWCOut = 7;
const int LightBathOut = 8;
const int FanOut = 12;
int buttonState = 0; // current state of the button
int buttonState2 = 0;
void setup() {
// initialize the button pin as a input:
pinMode(LightWCPin, INPUT);
pinMode(LightBathPin, INPUT);
// initialize outputs:
pinMode(LightWCOut, OUTPUT);
pinMode(LightBathOut, OUTPUT);
pinMode(FanOut, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(LightWCPin);
buttonState2 = digitalRead(LightBathPin);
if (buttonState == LOW) {
// turn WC on:
digitalWrite(LightWCOut, HIGH);
digitalWrite(FanOut, HIGH);
}
else {
// turn off:
digitalWrite(LightWCOut, LOW);
digitalWrite(FanOut, LOW);
}
if (buttonState2 == LOW) {
// turn on Bath:
digitalWrite(LightBathOut, HIGH);
digitalWrite(FanOut, HIGH);
}
else {
// turn off:
digitalWrite(LightBathOut, LOW);
digitalWrite(FanOut, LOW);
}
}