But the problem comes when i try to use my Arduino Leonardo device, thus it receives the signal from the PI device, it does not send the signal correctly.
That example simply calls the device "Arduino". Without a specific type that usually means "Arduino UNO" and on that type interrupt #0 is on pin 2 but on the Leonardo interrupt #0 is on pin 3.
Is it possible that you assumed some other stuff from a description meant for the UNO and therefor did it wrong for the Leonardo?
Post the code you actually use (don't forget the code tags!) and provide a wiring diagram of your setup.
The wiring is as follows at the attachment (the power is set to bath using an Y).
Working receive code:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #3
Serial.print("Boot ok ");
}
void loop() {
Serial.println("Listen ok ");
delay(500);
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
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();
}
}
}
Sample output (transmitted from pi 1 time protol 1 ):
Listen ok
Received 123 / 24bit Protocol: 5
Listen ok
Received 123 / 24bit Protocol: 5
Listen ok
Received 123 / 24bit Protocol: 5
Listen ok
Do I interpret your wiring diagrams correctly? You want to establish a two-way communication using these 433MHz modules? These are thought for a strict one way communication where the code is repeated as long as some remote control button is pressed. I don't know if you get this reliable enough to be used as as serial radio communication device.
If you look at the code it explicitly depends on getting the code repeatedly. Only under perfect circumstances where no noise is on the air you get each transmitted byte correctly.