Panel Remote Transmitter 3 Buttons

@gurues this is the 1st part: transmission

/***************** Library ESP and Blynk *****************/
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>

/***************** Library for real-time clock *****************/
#include <TimeLib.h>
#include <WidgetRTC.h>

BlynkTimer timer;
WidgetRTC rtc;

/*************** Server *********************/
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxx";
char server[] = "192, 168, 0, 1";
IPAddress arduino_ip ( 192,  168,   0,  56);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,  168,   0,   254);
IPAddress subnet_mask(255, 255, 255,   0);
bool isFirstConnect = true;

/*************** LEDS *********************/
WidgetLED led1(10); //virtual led button A
WidgetLED led2(11);//virtual led button A
WidgetLED led3(12);//virtual led button B
WidgetLED led4(13);//virtual led button B
WidgetLED led5(14);//virtual led button C
WidgetLED led6(15);//virtual led button C
WidgetLED led7(16);//virtual led button D
WidgetLED led8(17);//virtual led button D
WidgetLED led9(18);//virtual led button E
WidgetLED led10(19);//virtual led button E
WidgetLED blinkled(22); //virtual blink led

/*************** 433Mhz Settings ***************/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();

#define PACKET_LENGTH 24 //length

#define SWITCH_1_ON   1361 // decimal code
#define SWITCH_1_OFF  1364

#define SWITCH_2_ON   4433
#define SWITCH_2_OFF  4436

#define SWITCH_3_ON   5201
#define SWITCH_3_OFF  5204

#define SWITCH_4_ON   5393
#define SWITCH_4_OFF  5396

#define SWITCH_5_ON   5441
#define SWITCH_5_OFF  5444

/*************** buttons ***************/
int BTNA, BTNB, BTNC, BTND, BTNE;

/*************** Setup *********************/
void setup()
{
  Serial.begin(115200);
  WiFi.config(arduino_ip, gateway_ip, subnet_mask);
  Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 0, 1), 8088);


  /*************** Transmitter is connected to Arduino Pin #10 ***************/
  mySwitch.enableTransmit(15);//that is pin D8 nodemcu
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin D3 nodemcu
  //pinMode(0, INPUT_PULLUP);
  //attachInterrupt(digitalPinToInterrupt(0), receiver, CHANGE);

  // Optional set protocol (default is 1, will work for most outlets)
  // mySwitch.setProtocol(2);

  // Optional set pulse length.
  mySwitch.setPulseLength(320);

  // Optional set number of transmission repetitions.
  mySwitch.setRepeatTransmit(15);


  /*************** intialisation ***************/
  timer.setInterval(500, worktime); // flash led
  timer.setInterval(350L, receiver); // receiver to learn code
}

//-----------------------------------------------

/*************** buttons *********************/
BLYNK_WRITE(V0) {
  BTNA = param.asInt();
  if (BTNA == true) {
    Serial.println("BT A on");
    mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
    led1.on();
    led2.off();
  }
  else {
    Serial.println("BT A off");
    mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
    led1.off();
    led2.on();
  }
}

BLYNK_WRITE(V1) {
  BTNB = param.asInt();
  if (BTNB == true) {
    Serial.println("BT B on");
    mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
    led3.on();
    led4.off();
  }
  else {
    Serial.println("BT B off");
    mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
    led3.off();
    led4.on();
  }
}

BLYNK_WRITE(V2) {
  BTNC = param.asInt();
  if (BTNC == true) {
    Serial.println("BT C on");
    mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
    led5.on();
    led6.off();
  }
  else {
    Serial.println("BT C off");
    mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
    led5.off();
    led6.on();
  }
}

BLYNK_WRITE(V3) {
  BTND = param.asInt();
  if (BTND == true) {
    Serial.println("BT D on");
    mySwitch.send(SWITCH_4_ON, PACKET_LENGTH);
    led7.on();
    led8.off();
  }
  else {
    Serial.println("BT D off");
    mySwitch.send(SWITCH_4_OFF, PACKET_LENGTH);
    led7.off();
    led8.on();
  }
}

BLYNK_WRITE(V4) {
  BTNE = param.asInt();
  if (BTNE == true) {
    Serial.println("BT E on");
    mySwitch.send(SWITCH_5_ON, PACKET_LENGTH);
    led9.on();
    led10.off();
  }
  else {
    Serial.println("BT E off");
    mySwitch.send(SWITCH_5_OFF, PACKET_LENGTH);
    led9.off();
    led10.on();
  }
}



void worktime() {
  if (blinkled.getValue()) {
    blinkled.off();
  } else {
    blinkled.on();
  }
}



void loop() {
  Blynk.run();
  timer.run();

}

void receiver() {

  if (mySwitch.available()) {

    int value = mySwitch.getReceivedValue();
    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
      Serial.print("Received ");
      Serial.print( value );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );
}
2 Likes