Unable to make two RF modules to communicate

I've been trying to make an RF transmitter and RF receiver (both OOK) communicate, but I've been unable to do so. The transmitter seems to be working fine, as I can connect my receiver to the oscilloscope and see that the transmitter is sending the correct code (an 8-bit wave to sensitize the receiver's auto-amplifier+ wait 10ms + Manchester encoding). The problem is the reciever code. The code works like this:

Basically I first write the message I know i will recieve (manchesterDecoded) and I manchester encode it; then I look for a wave that is HIGH for more than 70 ms (the 8 bit wave ); when this wave is found I wait 10ms and then take the values of the code sent using a debouncing method and store all the values in an array; lastly i compare this array with manchesterDecoded (written as codeChecker which is the same array but every value is repeated for 10 times) and if the number of equal values is more than 160 i will mark the signal as recieved (this as the 70ms wave are to prevent not recieved messages due to noise).

Here is the code:

const int RX = 3;
int RXValue[180];
int manchesterDecoded[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int codeChecker[180];
int manchesterEncoded[18];
int s = 0;

void setup() {
  // Manchester encoding
  for (int i = 0; i < 9; i++) {
    if (manchesterDecoded[i] == 0) {
      manchesterEncoded[s] = 1;
      s++;
      manchesterEncoded[s] = 0;
      s++;
    }
    if (manchesterDecoded[i] == 1) {
      manchesterEncoded[s] = 0;
      s++;
      manchesterEncoded[s] = 1;
      s++;
    }
  }
  // Writing codeChecker
  for (int i = 0; i < 18; i++) {
    int indicePartenza = i * 10;
    for (int j = 0; j < 10; j++) {
      codeChecker[indicePartenza + j] = manchesterEncoded[i];
    }
  }

  pinMode(RX, INPUT);
  Serial.begin(9600);
}

void loop() {
  // find 8 bit wave
  unsigned long carrierDuration = pulseIn(RX, HIGH);
  if (carrierDuration > 70000) {
    Serial.println(carrierDuration);
    int bitChecked = 0;
    for (int i = 0; i < 180; i++) {
      RXValue[i] = 0;
    }
    // read code
    delay(10);
    for (int i = 0; i < 180; i++) {
      RXValue[i] = digitalRead(RX);
      Serial.print(RXValue[i]);
      delay(1);
    }

    // Check
    for (int i = 0; i < 180; i++) {
      if (RXValue[i] == codeChecker[i]) {
        bitChecked++;
      }
    }
    if (bitChecked >= 130) {
      Serial.println(" ");
      Serial.println("Signal");
      Serial.print("Bit Checked: ");
      Serial.println(bitChecked);
    }
  }
}

111111111100000000011111111100000000001111111110000000000111111111000000000111111111100000000011111111110000000001111111110000000000111111111000000000111111111100000000000000000000
Which is similar to the code checker but also different enough 111111111100000000001111111111000000000011111111110000000000111111111100000000001111111111000000000011111111110000000000111111111100000000001111111111000000000011111111110000000000
but the equal values are about 90 which is to little since if i lower 160 to 90 i will get a lot of fake messages. How can i make this work?

Unless you are for some reason required to use Manchester encoding, the simple OOK/ASK examples in the VirtualWire or RadioHead packet radio libraries should work out of the box.

Both do packet error checking and are very reliable. No reason to reinvent the wheel.

I'm actually using different transmitters to a single receiver. My project is a bit long to explain but I guess you can think of it as multiple keys opening a gate using RF signal. I know what code I want to receive but it is sent at random times by various sources at random places. From my understanding both this libraries work by sending some bit periodically so that auto gain is fixed but I cannot do that because I have various sources

which seems not at all correct, but carry on!

Hi, @pietrofarag

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Please post links to data/specs of your tx/rx units?
OR have you designed and built the tx/rx?
If so, please post schematics.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Also if you whant to know on which part is the problem you can remove the two wireless circuit and connect directly the 'transmitter arduino' to the 'receiver arduino' ( the two gnd also ) and check if everything works as expected.

That's what I'm doing right now. They both work well, it's not a hardware problem but a software problem