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?