1

I have a 433Mhz Superheterodyne receiver and a hand set remote of similar frequency, I'm using the RC-Switch library and I couldn't find a better way than using the "numbers" that I'm receiving like this:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

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

void loop() {
  if (mySwitch.getReceivedValue() == 7264305) {
    digitalWrite(13, LOW);
  }
  if (mySwitch.getReceivedValue() == 7264308) {
    digitalWrite(13, HIGH);
  }
  if (mySwitch.getReceivedValue() == 7264306) {
    mySwitch.resetAvailable();
  }
}

Is there any other (better?) way than just using the "numbers" simply like that or everyone are using their remote commands like I'm using?

  • 1
    all data is just numbers ... your transmission data appear to be 24 bits long ... for example decimal 7264305 translates to 24 bit binary 011011101101100000110001, which can be described in hexadecimal as 6ED831 .... some of the bits are the switch states and the rest are probably a predetermined filler that could be used to check the validity of the transmission or they may be the address of the transmitter – jsotola Jun 22 at 20:43
  • 1
    for the received values of 7264305, 7264306 and 7264308, the last 4 bits of the received data are 0001, 0010 and 0100 respectively – jsotola Jun 22 at 21:08
1

Credits for this answer are mainly for jsotola (see his remarks above). But I want to show an alternative to the if statements, and a way to get the last 4 bits:

  1. In case you want to check for the least significant bits, use ((mySwitch.getReceivedValue() & 0xFFFFF0)
  2. TO check for the least significant four bits (the data you want to act upon), use ((mySwitch.getReceivedValue() & 0xF)
  3. Use a switch statement instead of the if statement; also in theory (I don't know the code of mySwitch.getReceivedValue() does not need to be executed multiple times.

So you get something like this:

void loop() 
{
  unsigned long receivedValue = mySwitch.getReceivedValue(); // Call function only once

  if ((receivedValue & 0xFFFF0) == 0x6ED830)
  {
    // Process action
    switch (receivedValue & 0xF)
    {
    case 0x5:
      digitalWrite(13, LOW);
      break;

    case 0x8:
      digitalWrite(13, HIGH);
      break;

    case 0x6:
      mySwitch.resetAvailable();
      break;

    default: // All other values
      break; // Ignore
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.