this is what i have done yet. 4 relay with separate pin consuming LED turns ON/OFF by separate switch. IR function and master switch function is remaining. help me out. please keep in mind i am beginner and learning here from like you and my other brothers on this site.
CODE
/*
home automation with switch as well as remote
*/
boolean latch = false;
define relay1 2 // this is the pin used to switch the relay1
define relay2 3 // this is the pin used to switch the relay2
define relay3 4 // this is the pin used to switch the relay3
define relay4 5 // this is the pin used to switch the relay4
define Switch1 6 // this is the switch1 output
define Switch2 7 // this is the switch1 output
define Switch3 8 // this is the switch1 output
define Switch4 9 // this is the switch1 output
//# define Switch5 10 // this is the Master switch output
define Vcc 11 // this is the pin used to act as +5v for the switch
define LED1 A0 // LED1
define LED2 A1 // LED2
define LED3 A2 // LED3
define LED4 A3 // LED4
//# define LED4 A4 // Master LED
//# define IR A5 // IR Sensor input
define Vcc 11 // this is the pin used to act as +5v for the switch
void setup() {
Serial.begin(9600); // used for debugging
pinMode(relay1, OUTPUT);
digitalWrite(relay1,LOW); // turn OFF the relay1
pinMode(Switch1, INPUT);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW); // turn LED1 off
pinMode(relay2, OUTPUT);
digitalWrite(relay2,LOW); // turn OFF the relay2
pinMode(Switch2, INPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED2, LOW); // turn LED2 off
pinMode(relay3, OUTPUT);
digitalWrite(relay3,LOW); // turn OFF the relay3
pinMode(Switch3, INPUT);
pinMode(LED3, OUTPUT);
digitalWrite(LED3, LOW); // turn LED3 off
pinMode(relay4, OUTPUT);
digitalWrite(relay4,LOW); // turn OFF the relay4
pinMode(Switch4, INPUT);
pinMode(LED4, OUTPUT);
digitalWrite(LED4, LOW); // turn LED4 off
pinMode(Vcc, OUTPUT);
digitalWrite(Vcc,HIGH);// this pin will supply 5 volts
}
void loop() {
// turn switch1 ON on first touch
if ((digitalRead(Switch1) == HIGH) && (latch == false)) {
digitalWrite(relay1, HIGH); // relay1 ON
Serial.println("relay1 ON");
digitalWrite(LED1, HIGH); // turn LED1 ON
latch = true;
// wait here until the Switch1 is no longer touched
while ((digitalRead(Switch1) == HIGH)){
digitalWrite(LED1, LOW); // turn LED1 OFF
delay(500); // try to stop debounce
}
}
// turn switch2 ON on first touch
if ((digitalRead(Switch2) == HIGH) && (latch == false)) {
digitalWrite(relay2, HIGH); // relay2 ON
Serial.println("relay2 ON");
digitalWrite(LED2, HIGH); // turn LED2 ON
latch = true;
// wait here until the Switch2 is no longer touched
while ((digitalRead(Switch2) == HIGH)){
digitalWrite(LED2, LOW); // turn LED2 OFF
delay(500); // try to stop debounce
}
}
// turn switch3 ON on first touch
if ((digitalRead(Switch3) == HIGH) && (latch == false)) {
digitalWrite(relay3, HIGH); // relay3 ON
Serial.println("relay3 ON");
digitalWrite(LED3, HIGH); // turn LED3 ON
latch = true;
// wait here until the Switch3 is no longer touched
while ((digitalRead(Switch3) == HIGH)){
digitalWrite(LED3, LOW); // turn LED3 OFF
delay(500); // try to stop debounce
}
}
// turn switch4 ON on first touch
if ((digitalRead(Switch4) == HIGH) && (latch == false)) {
digitalWrite(relay4, HIGH); // relay4 ON
Serial.println("relay4 ON");
digitalWrite(LED4, HIGH); // turn LED4 ON
latch = true;
// wait here until the Switch4 is no longer touched
while ((digitalRead(Switch4) == HIGH)){
digitalWrite(LED4, LOW); // turn LED4 OFF
delay(500); // try to stop debounce
}
}
// turn relay1 OFF on second touch
if ((digitalRead(Switch1) == HIGH) && (latch == true)) {
digitalWrite(relay1, LOW); // relay1 OFF
Serial.println("Relay1 OFF");
digitalWrite(LED1, HIGH); // turn LED1 ON
latch = false;
// wait here until the Switch1 is no longer touched
while ((digitalRead(Switch1) == HIGH)){
digitalWrite(LED1, LOW); // turn LED1 OFF
delay(500); // try to stop debounce
}
}
// turn relay2 OFF on second touch
if ((digitalRead(Switch2) == HIGH) && (latch == true)) {
digitalWrite(relay2, LOW); // relay2 OFF
Serial.println("Relay2 OFF");
digitalWrite(LED2, HIGH); // turn LED2 ON
latch = false;
// wait here until the Switch2 is no longer touched
while ((digitalRead(Switch2) == HIGH)){
digitalWrite(LED2, LOW); // turn LED2 OFF
delay(500); // try to stop debounce
}
}
// turn relay3 OFF on second touch
if ((digitalRead(Switch3) == HIGH) && (latch == true)) {
digitalWrite(relay3, LOW); // relay3 OFF
Serial.println("Relay3 OFF");
digitalWrite(LED3, HIGH); // turn LED3 ON
latch = false;
// wait here until the Switch3 is no longer touched
while ((digitalRead(Switch3) == HIGH)){
digitalWrite(LED3, LOW); // turn LED3 OFF
delay(500); // try to stop debounce
}
}
// turn relay4 OFF on second touch
if ((digitalRead(Switch4) == HIGH) && (latch == true)) {
digitalWrite(relay4, LOW); // relay4 OFF
Serial.println("Relay4 OFF");
digitalWrite(LED4, HIGH); // turn LED4 ON
latch = false;
// wait here until the Switch4 is no longer touched
while ((digitalRead(Switch4) == HIGH)){
digitalWrite(LED4, LOW); // turn LED4 OFF
delay(500); // try to stop debounce
}
}
}