How to make bluetooth control relays system at home | DIY

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น •

  • @GADGETPODDAofficial
    @GADGETPODDAofficial  2 ปีที่แล้ว

    /*
    Gadget Podda
    Bluetooth 5 relays control
    */
    char val;
    int relay1 = 2;
    int relay2 = 3;
    int relay3 = 4;
    int relay4 = 5;
    int relay5 = 6;
    void setup() {
    pinMode(relay1, OUTPUT);
    pinMode(relay2, OUTPUT);
    pinMode(relay3, OUTPUT);
    pinMode(relay4, OUTPUT);
    pinMode(relay5, OUTPUT);
    Serial.begin(9600);
    }
    void loop() {
    if (Serial.available()) {
    val = Serial.read();
    Serial.println(val);
    }
    if (val == '0') {
    digitalWrite(relay1, HIGH);
    } else if (val == '1') {
    digitalWrite(relay1, LOW);
    }
    if (val == '2') {
    digitalWrite(relay2, HIGH);
    } else if (val == '3') {
    digitalWrite(relay2, LOW);
    }
    if (val == '4') {
    digitalWrite(relay3, HIGH);
    } else if (val == '5') {
    digitalWrite(relay3, LOW);
    }
    if (val == '6') {
    digitalWrite(relay4, HIGH);
    } else if (val == '7') {
    digitalWrite(relay4, LOW);
    }
    if (val == '8') {
    digitalWrite(relay4, HIGH);
    } else if (val == '9') {
    digitalWrite(relay4, LOW);
    }
    if (val == 'a') {
    digitalWrite(relay5, HIGH);
    } else if (val == 'b') {
    digitalWrite(relay5, LOW);
    }
    if (val == 'c') {
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, HIGH);
    digitalWrite(relay3, HIGH);
    digitalWrite(relay4, HIGH);
    digitalWrite(relay5, HIGH);
    } else if (val == 'd') {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
    digitalWrite(relay3, LOW);
    digitalWrite(relay4, LOW);
    digitalWrite(relay5, LOW);
    }
    }