Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868A-4 RF433MHz decoding.
#1
If I understood the meaning of the sample code. Once uploaded the code, opening the Serial monitoring to Arduino IDE I should see the code transmitted  from 433 MHz remote control.  I don't understand why to the monitor I don't see anything. I'm sure that the remote control and receiver module woks fine because to the receiver data pin, with a scope ,when I press one button to the remote control, I see the pulse train.
Below the Decoding sample code.
Code:
/*
  Simple example for receiving
 
  https://github.com/sui77/rc-switch/
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(115200);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {
   
    Serial.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( mySwitch.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( mySwitch.getReceivedProtocol() );

    mySwitch.resetAvailable();
  }
}
 
What can I do to see to the serial monitor, the remote control codes ?

Tank You
Reply
#2
your receiver pin define is wrong. it should be mySwitch.enableReceive(digitalPinToInterrupt(19)); //IO19
you can use this 433MHz receive arduino code for A4 board directly: https://www.kincony.com/forum/showthread.php?tid=1641
Reply
#3
(05-07-2024, 12:04 AM)admin Wrote: your receiver pin define is wrong.  it should be mySwitch.enableReceive(digitalPinToInterrupt(19));  //IO19
you can use this 433MHz receive arduino code for A4 board directly: https://www.kincony.com/forum/showthread.php?tid=1641

You Right,  the code is with interrupt (19). I make mistache coping the code.
Code:
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
   mySwitch.enableReceive(digitalPinToInterrupt(19)); //IO19
  Serial.print("begin test");
}

void loop() {
  if (mySwitch.available()) {
   
    Serial.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( mySwitch.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( mySwitch.getReceivedProtocol() );

    mySwitch.resetAvailable();
  }
}
 
Even with correct interrupt address (19) I don't see anything  to the serial monitor
The Arduino IDE is connnected to the KC868 via USB port (com5) I suppose we use same port to monitoring the Board activity.
Reply
#4
press remote's button, is code can be detected, will print by serial port.
Reply
#5
(05-07-2024, 12:12 PM)admin Wrote: press remote's button, is code can be detected, will print by serial port.
Hi Master,
I probably have a problem. I uploaded the belove  code. It's like a loop, I should read what i'm transmitting.
Code:
#include "BluetoothSerial.h"
#include <RCSwitch.h>
BluetoothSerial SerialBT;
RCSwitch mySwitch = RCSwitch();
#define Key1 36
#define Key2 39
#define Key3 27
#define Key4 14
#define RELAY1 2
#define RELAY2 15
#define RELAY3 5
#define RELAY4 4
int incoming;
void setup() {
     
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(Key1, INPUT);
  pinMode(Key2, INPUT);
  pinMode(Key3, INPUT);
  pinMode(Key4, INPUT);
Serial.begin(9600);   // Serial monitor
mySwitch.enableReceive(19);
mySwitch.enableTransmit(21);
SerialBT.begin(9600); // Bluetooth serial communication
Serial.print("Bluetooth Control for KC868-A4 Relays");
 
}
void loop() {
 
      mySwitch.send("000000000001010100010001");
       delay(1000);
      mySwitch.send("000000000001010100010100");
        delay(1000);
 //if (mySwitch.available())
    // Read the received data
    Serial.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( mySwitch.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( mySwitch.getReceivedProtocol() );
    mySwitch.resetAvailable();
      delay(1000);
   
  ScanKey1();
  ScanKey2();
  ScanKey3();
  ScanKey4();
if (SerialBT.available()) {
    char command = SerialBT.read();
   
    // Controlla il comando ricevuto e attiva o disattiva il relè corrispondente
    switch(command) {
      case '1':
        digitalWrite(RELAY1, HIGH);
        break;
      case '2':
        digitalWrite(RELAY1, LOW);
        break;
      case '3':
        digitalWrite(RELAY2, HIGH);
        break;
      case '4':
        digitalWrite(RELAY2, LOW);
        break;
      case '5':
        digitalWrite(RELAY3, HIGH);
        break;
      case '6':
        digitalWrite(RELAY3, LOW);
        break;
      case '7':
        digitalWrite(RELAY4, HIGH);
        break;
      case '8':
        digitalWrite(RELAY4, LOW);
        break;
      default:
        break;
    }
  }
}
int KEY_NUM1;
int KEY_NUM2;
int KEY_NUM3;
int KEY_NUM4;
void ScanKey1() {
  KEY_NUM1 = 1;
  if (digitalRead(Key1) == LOW) {
    delay(20);
    if (digitalRead(Key1) == LOW) {
      KEY_NUM1 = 0;
      digitalWrite(RELAY1, HIGH);
    } else {
      digitalWrite(RELAY1, LOW);
    }
  }
}
void ScanKey2() {
  KEY_NUM2 = 1;
  if (digitalRead(Key2) == LOW) {
    delay(20);
    if (digitalRead(Key2) == LOW) {
      KEY_NUM2 = 0;
      digitalWrite(RELAY2, HIGH);
    } else {
      digitalWrite(RELAY2, LOW);
    }
  }
}
void ScanKey3() {
  KEY_NUM3 = 1;
  if (digitalRead(Key3) == LOW) {
    delay(20);
    if (digitalRead(Key3) == LOW) {
      KEY_NUM3 = 0;
      digitalWrite(RELAY3, HIGH);
    } else {
      digitalWrite(RELAY3, LOW);
    }
  }
}
void ScanKey4() {
  KEY_NUM4 = 1;
  if (digitalRead(Key4) == LOW) {
    delay(20);
    if (digitalRead(Key4) == LOW) {
      KEY_NUM4 = 0;
      digitalWrite(RELAY4, HIGH);
    } else {
      digitalWrite(RELAY4, LOW);
    }
  }
}
With my oscilloscope, I made picture. The down CH, is what I'm sending (P4,Pin3). The upper CH is The out from U8, pin4 (RX Amplifier) That is connected straight to esp32 pin 31 (IO19).
As we can see from pictures There is not any output to the seial monitor.
Any suggestion to solve this issue ?


Attached Files Image(s)
           
Reply
#6
you need use two board, one for send , another for receive.
maybe your code send RF and receive RF signal can't at the same time.
Reply
#7
(05-10-2024, 03:21 AM)admin Wrote: you need use two board,  one for send , another for receive.
maybe your code send RF and receive RF signal can't at the same time.

As do you can see on the oscilloscope picture trasmitted signal and received signal are in the same fase. Anyway  with the code below (I enabled only the receiver) pressing one button to the remote control,  On U8 Pin 4 (strigth connected  with IO19)  We can see received signal very cleaned (see picture in attacment.) But there is not output to the serial monitor. 
Code:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(digitalPinToInterrupt(19));  //IO19
  Serial.print("begin test");
}
void loop() {
  if (mySwitch.available()) {
  
    Serial.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( mySwitch.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( mySwitch.getReceivedProtocol() );
    mySwitch.resetAvailable();
  }
}


Attached Files Image(s)
   
Reply
#8
you can test with a arduino recevie demo code whether can print the key code. (my means ONLY have receive function in code, and use press your remote's button send RF signal)
if it's ok, maybe you can check the RC SWITCH arduino library.
Reply
#9
(05-10-2024, 10:43 AM)admin Wrote: you can test with a arduino recevie demo code whether can print the key code. (my means ONLY have receive function in code, and use press your remote's button send RF signal)
if it's ok, maybe you can check the RC SWITCH arduino library.

The above code is  the arduino receiver demo code . At the power on print "begin test" Then if I press the remote butto doesn't print anything :I made test with some differentes remote control, nothing appen. It look like the ESP32 doesn't read the IO19. I suspect it defective
Reply
#10
A4 RF433M receiver pin is IO13, here is code:
Code:
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(digitalPinToInterrupt(13));
  Serial.print("begin test");
}

void loop() {
  if (mySwitch.available()) {
   
    Serial.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print(" / ");
    Serial.print( mySwitch.getReceivedBitlength() );
    Serial.print("bit ");
    Serial.print("Protocol: ");
    Serial.println( mySwitch.getReceivedProtocol() );

    mySwitch.resetAvailable();
  }
}
Reply


Forum Jump:


Users browsing this thread: