Nano + 433MHz Chinese Modules + RCSwitch problems

Hi all,

I use a pair of cheap Chinese 433MHz modules (with spiral antennas, distance is ~5cm - see picture below) and the RCSwitch library to experiment with 433MHz transmission. While in principle everything works fine, the two Nanos transmit and receive something, there are two annoyances I'd like to resolve if possibe:

(1) A value of 0 will never transmit. This is an absolute no-go. See code. If I set variable i to 0, or use i++ to count between -5 and +5, when the counter (i) reaches 0, no value is received. All other values except 0 are received. If I set i to 0 and send i in and infinite loop (1000ms delay), nothing is ever received, no matter how long I let it run. So it's not a random glitch, the devices simply cannot transfer a value of 0.

(2) per default, every sent message appears multiple times at the receiver. The first message after powering the sender does appear 5 times, all subsequent messages are received 4 times. I tried to experiment with setRepeatTransmit (which seems to be initialized to 10 by default). If I set it to a value below 3, nothing is received. if I set it to 3 or 4, I get a single message. if set to 5 or 6, I get two, 7 or 8 I get three, and so forth. The first message after power up of the sender is always repeated one more time than all others.

Is this normal behaviour for those modules, or should I suspect and file a bug in the RFSwitch library?

Thnx, Armin

Receiver code

#include <RCSwitch.h>

#define ProgName "433MHz Remote Control Programmer"
#define ProgVers "V1.0"

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  Serial.print(ProgName);Serial.print(" "); Serial.println(ProgVers);
 
  mySwitch.enableReceive(0);
}

void loop() {
  if (mySwitch.available()) {
    digitalWrite(LED_BUILTIN,HIGH);
    Serial.print("Value:");    
    Serial.print(mySwitch.getReceivedValue());
    Serial.print(" Bits:");
    Serial.print(mySwitch.getReceivedBitlength());
    Serial.print(" Delay:");    
    Serial.print(mySwitch.getReceivedDelay());    
    Serial.print(" Protocol:");    
    Serial.print(mySwitch.getReceivedProtocol());    
    Serial.println();
    mySwitch.resetAvailable();
    digitalWrite(LED_BUILTIN,LOW);    
  }

}

Sender code


#define ProgName "433MHz Remote Control Programmer"
#define ProgVers "V1.0"

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  Serial.print(ProgName);Serial.print(" "); Serial.println(ProgVers);
    
  mySwitch.enableTransmit(10);
  mySwitch.setRepeatTransmit(4);  // By trial and error: minimum value = 3
}

unsigned long i = -5;

void loop() {
  // i = millis();
  // i = 0;  // This is never sent
  i++;  
  Serial.print(i);
  mySwitch.send(i, 32);
  Serial.println();
  digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
  delay(1000);
}

I don't know the RCSwitch library, but have used the manchester encoding library for using the same cheap RF modules with succes.

download at: GitHub - mchr3k/arduino-libs-manchester

documentation at: Home - Arduino Manchester Encoding - Mchr3k

You may be able to use it to confirm that you have no hardware problem.

I'll give it a try. Meanwhile I filed a bug with RC_SWITCH.

https://github.com/sui77/rc-switch/issues/447