//final// pwede rin
#include <IRremote.h>
#include <LiquidCrystal_I2C.h>
#define relay1 0
#define relay2 19
#define relay3 18
#define relay4 5
#define recv 4
#define pushbutton1 23
#define pushbutton2 15
#define pushbutton3 2
#define pushbutton4 16
IRrecv recv_pin(recv);
LiquidCrystal_I2C lcd(0x27, 20, 4);
bool led1State = false;
bool led2State = false;
bool led3State = false;
bool led4State = false;
void setup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(pushbutton1, INPUT_PULLUP);
pinMode(pushbutton2, INPUT_PULLUP);
pinMode(pushbutton3, INPUT_PULLUP);
pinMode(pushbutton4, INPUT_PULLUP);
lcd.init();
lcd.clear();
lcd.backlight();
recv_pin.enableIRIn();
recv_pin.blink13(true);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("Status:");
lcd.setCursor(8, 0);
lcd.print("LED1 ");
lcd.setCursor(8, 1);
lcd.print("LED2 ");
lcd.setCursor(8, 2);
lcd.print("LED3 ");
lcd.setCursor(8, 3);
lcd.print("LED4 ");
if(recv_pin.decode()){
String response = String(recv_pin.decodedIRData.command);
if(response == "48") { // NUM 1 BUTTON
led1State = !led1State;
digitalWrite(relay1, led1State ? HIGH : LOW);
lcd.setCursor(13, 0);
lcd.print(led1State ? "ON " : "OFF");
}
if(response == "24") { //NUM 2 BUTTON
led2State = !led2State;
digitalWrite(relay2, led2State ? HIGH : LOW);
lcd.setCursor(13, 1);
lcd.print(led2State ? "ON " : "OFF");
}
if(response == "122"){ // NUM 3 BUTTON
led3State = !led3State;
digitalWrite(relay3, led3State ? HIGH : LOW);
lcd.setCursor(13, 2);
lcd.print(led3State ? "ON " : "OFF");
}
if(response == "16"){ // NUM 4 BUTTON
led4State = !led4State;
digitalWrite(relay4, led4State ? HIGH : LOW);
lcd.setCursor(13, 3);
lcd.print(led4State ? "ON " : "OFF");
}
if(response == "162"){ //POWER OFF BUTTON
led1State = !led1State;
led2State = !led2State;
led3State = !led3State;
led4State = !led4State;
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
lcd.setCursor(13,0);
lcd.print("OFF");
lcd.setCursor(13,1);
lcd.print("OFF");
lcd.setCursor(13,2);
lcd.print("OFF");
lcd.setCursor(13,3);
lcd.print("OFF");
}
if(response == "34"){ //TEST BUTTON
led1State = !led1State;
led2State = !led2State;
led3State = !led3State;
led4State = !led4State;
digitalWrite(relay1, led1State ? HIGH : LOW);
digitalWrite(relay2, led2State ? HIGH : LOW);
digitalWrite(relay3, led3State ? HIGH : LOW);
digitalWrite(relay4, led4State ? HIGH : LOW);
lcd.setCursor(13,0);
lcd.print(led1State ? "ON " : "OFF");
lcd.setCursor(13,1);
lcd.print(led2State ? "ON " : "OFF");
lcd.setCursor(13,2);
lcd.print(led3State ? "ON " : "OFF");
lcd.setCursor(13,3);
lcd.print(led4State ? "ON " : "OFF");
}
recv_pin.resume();
}
if (digitalRead(pushbutton1) == LOW) {
led1State = !led1State;
digitalWrite(relay1, led1State ? HIGH : LOW);
lcd.setCursor(13, 0);
lcd.print(led1State ? "ON " : "OFF");
delay(500); // Add a small delay to debounce the button
}
// Check pushbutton2 state
if (digitalRead(pushbutton2) == LOW) {
led2State = !led2State;
digitalWrite(relay2, led2State ? HIGH : LOW);
lcd.setCursor(13, 1);
lcd.print(led2State ? "ON " : "OFF");
delay(500); // Add a small delay to debounce the button
}
// Check pushbutton3 state
if (digitalRead(pushbutton3) == LOW) {
led3State = !led3State;
digitalWrite(relay3, led3State ? HIGH : LOW);
lcd.setCursor(13, 2);
lcd.print(led3State ? "ON " : "OFF");
delay(500); // Add a small delay to debounce the button
}
// Check pushbutton4 state
if (digitalRead(pushbutton4) == LOW) {
led4State = !led4State;
digitalWrite(relay4, led4State ? HIGH : LOW);
lcd.setCursor(13, 3);
lcd.print(led4State ? "ON " : "OFF");
delay(500); // Add a small delay to debounce the button
}
}