RF WITH RCSWITCH

Hi,

I have a module of 433 MHz and I send data wireless with it to another arduino. My question is this: when I use this library rcswitch it always send the data four times! Always. I am using the default code provided by the library. Does anybody knows why does it happen?

My code to send is this:

#include <RCSwitch.h>
RCSwitch serial_rf = RCSwitch();

void setup() {

	Serial.begin(115200);
	
	serial_rf.enableTransmit(2);
 
}

void loop() {

     for (int i=1;i<2000;i++) {

    
	serial_rf.send(i,16);
        delay(1000);
 

     }

}

My code in the receiver is this:

#include <RCSwitch.h>
RCSwitch serial_rf = RCSwitch();

void setup() {

	Serial.begin(115200);

	serial_rf.enableReceive(1);

}

void loop() {
	
	if (serial_rf.available()) {
	
		int resposta_rf = serial_rf.getReceivedValue();
		
		Serial.println(resposta_rf);
		
		serial_rf.resetAvailable();
	
	}

}

Does anybody has any idea what is causing this problem?

The RCSwitch uses the 2272 / 2262 protocol.
In most cases the message is transmitted about 10 times.
That protocol requires that the message is transmitted a few times, because the pause between messages is used to determine the timing of the bits.

The function "setRepeatTransmit" sets the number of repetitions.

Or is this not what you mean ?
It has been a while since I used the RCSwitch library. Perhaps I can find a sketch how I used it.

I prefer the fuzzillogic library.
https://bitbucket.org/fuzzillogic/433mhzforarduino/wiki/Home

As far as I can remember, protocol 1 and 2 have small differences. Both really need a few data packets to be send.
Do you have an antenna connected ? Just a piece of wire of 17cm will do.
The RCSwitch and fuzzillogic are needed when an existing device (transmitter or receiver) is used.

When nothing is received, the RCSwitch library is still receiving interrupts from the noise from the receiver. That can be more than 1000 times a second. It means that the Arduino is busy, no matter what.

For reliable communication between two Arduino boards, the VirtualWire or RadioHead is used. That is a highly optimized protocol for reliable transfer, and data needs to be send only once.
Google for : mikem virtualwire
Or : mikem radiohead

I think there are three things you can do :
1 ) Stick with RCSwitch, adjust your code to ignore the extra repeated messages. When you sketch does not allow to compare a few message there is a design problem. Do you use any delays ?
2 ) Use VirtualWire. You might need an extra Arduino board to receive the VirtualWire for maximum reliability. That is what I did: a dedicated Arduino for receiving data with VirtualWire.
3 ) Use a transceiver. The RCSwitch, fuzzillogic and VirtualWire/RadioHead use software for the protocol. The transceiver modules have a chip that handles the protocol. That is much better, and the Arduino can do other things.
For a list of possibilities, google for : sparkfun wireless buying guide.

No, I never used tried sending 0. I can imagine that it will go wrong, since that protocol is used for a few buttons or a few commands. The VirtualWire is used to send any data, and the VirtualWire even adds a checksum to it.

When the Arduino has other things to do with interrupts, that might influence the timing and the reliability of the VirtualWire library.