Connect RF module to SPI TX RX pins

Searching the internet I found this old topic: http://forum.arduino.cc/index.php?topic=9350.15
I think it is very much related to my problem but I cannot comment further.
My goal is to connect two Arduino via serial communication.
When they are hard wired everything works fine but if I replace the wired connection with RF modules it doesn't.
What I do is simply connect the TX pin 1 to the RF transmitter and the RX pin 0 to the RF reciver and try to estabilish a connnection between the two Arduino but it does not work.
I tried a pull down resistor on transmitter and reciver side to reduce noise and I tried to set the serial speed down to 300, but it did not help.
These are the RF modules that I use:
RF Link Transmitter - 434MHz - WRL-10534 - SparkFun Electronics
RF Link Receiver - 4800bps (434MHz) - WRL-10532 - SparkFun Electronics
They have 4800bps data rate, maybe this is the cause?
Or what I have in mind it's just not possible?
The purpose is to press a button to send a char and when the char is received an led willbe turned on, sometimes when the Arduino are "connected" via RF link I see led coming on but apparently not in relation to the input sent.
I hope someone can help.

I did tried this connection and it was working!
You better check whether you are connecting antenna? 17.3cm?
as by connecting to rx and tx it is working so your program is working!
even thought I got success it has been advised that dont use rf communication on serial line as it has poor encoding and dont give 1/0 balance and clk synch so if the problem is that then you can check using virtual wire library you will also get this link on that receiver link you share in arduino libraries! if it works fine then switch to it!
which arduino you are using?

The purpose is to press a button to send a char and when the char is received an led will be turned on, sometimes when the arduino are “connected” via RF link I see led coming on but apparently not in relation to the input sent.

When your transmitter dont send any on rf tx your RF RX will receive noise and as there is no signal (high power i/p) it amplify that noise by considering it is as signal with weak strength, and if the noise generated made a similar i/p to your caracter that you want to transmit your receiver detect it and arduino think it is the character that your TX is sending and so make our led on!
To avoid this put some prefix and post-fix to your message that your transmitter sending and modify receiver to check for that entire string instead of only message!

Thank you yatin, I am not using antennas as I keep everything on the desk few cm apart.
If I understand correctly your suggestion is to send a string and parse it to filter out noise, is it correct?
About virtualwire, my purpose was to use rf links without virtualwire as it conflicts with servo library.
I built a primitive rc car controlled using rf links using virtualwite and servotimer two for the steering, but I wanted to try a different option.

send a string and parse it to filter out noise, is it correct?

Yes you are right!
here is example code what i want to tell
RECEIVER

int check;
void setup() {

  // initialize the serial communications:
  Serial.begin(1200);
}

void loop() {
  int cnt;
  unsigned char ch=0, input_query[30];
  int query_recd=0;
  int query_started=0;
  volatile unsigned long count=0;
  static unsigned char j=0;
  // when characters arrive over the serial port...
 
    // read all the available characters
    while (Serial.available() > 0) {
      ch=Serial.read();
      // display each character to the LCD
       if((ch=='#')&&(query_started==0))
      {  query_started = 1;
         return;                          //Return after receiving '#'.
      }
      if(query_started==1)
      {
/*------------------------------------------------------------------------------
 * Sometimes, junk characters are received at the serial port. If these characters
 * are put into the string variable, it unnecessarily inflates the variable which
 * causes the microcontroller's stack to overflow. To avoid this, if the string
 * length goes above 20 characters, it is discarded. It is observed that the
 * junk data appears in between two queries and not in the middle of a single
 * query.
------------------------------------------------------------------------------*/
         if(j<10)
         {  input_query[j] = ch;
            if(input_query[j]=='*')
            {
/*------------------------------------------------------------------------------
 * If the character received is '*', it indicates that the string has ended. Tell
 * the microcontroller that a valid string has been received by making the
 * query_recd variable TRUE.
------------------------------------------------------------------------------*/
               j = 0;
               query_recd = 1;
               query_started = 0;
               return;
            }
            j++;
         }
         else
         {  j = 0;
            query_started = 0;
         }
      //lcd.print(Serial.read());
      //check = Serial.read();
      //Serial.print("check");
    }
  
  {
    if( query_recd == 1 )
    {
      query_recd = 0; 
      Serial.write(ch);
    }
  }
}
}

TRANSMITTER

void setup(){
  Serial.begin(1200);
}

void loop(){
  Serial.write("AA55#AA001*"); // send a byte with the value 45
Serial.print("\n");
delay (5000);
Serial.write("AA55#AA002*"); // send a byte with the value 45
Serial.print("\n");
delay (5000);
Serial.write("AA55#AA003*"); // send a byte with the value 45

delay (5000);
 //  string bytesSent = Serial.write(“hello”); //send the string “hello” and return the length of the string.
}

try with this logic!

Thank you yatin,
looks like I also have problem with my rf links as vw works if I hardwire the two Arduinos but not with rf links...
I will try your code when new Rf modules arrive :slight_smile:

For an antenna, on all RF units, use a 51R resistor but do not cut the leads off. Let the resistor stand up on the board.

When the receiver gets a signal it activates it's automatic gain control circuit, AGC. For a short time thereafter, the receiver will not pick up any noise and falsely interpret it as data. You need to send often enough for the AGC circuit to remain active. Try sending dummy data, or no button press, continuously and inject button presses when available.

Hello Arctic,

You need to send often enough for the AGC circuit to remain active. Try sending dummy data, or no button press, continuously and inject button presses when available.

You are right about AGC and how to keep it tuned, but I have different opinion on your style of keeping it tuned continuously!
If you send data continuously you will have to spend lots of power in doing this and many time its observed that these modules are used with battery so it will drain battery too rapidly!
Instead what I did is I use a #&* to indicate my message signal and differentiate them from noise at same time I also sending 'AA55' to make my receiver get synchronize and keep AGC tune before sending original data!
It saves your power means keep your battery life longer that's all!
still on trials or testing purpose your method is correct!

You need the VirtualWire library. When a message is sent, it contains a few byte for the receiver to sync up with, encodes the message so there is a good mix of 1s & 0s, and the data is decoded & checked when received.
http://www.airspayce.com/mikem/arduino/RadioHead/classRH__ASK.html
See explanatio, and examples about 3/4 down the page.
Serial 0 & 1 are not used, they can be kept for use with the Serial Monitor.

"Does not use the Arduino UART. Messages are sent with a training preamble, message length and checksum. Messages are sent with 4-to-6 bit encoding for good DC balance, and a CRC checksum for message integrity.
But why not just use a UART connected directly to the transmitter/receiver? As discussed in the RFM documentation, ASK receivers require a burst of training pulses to synchronize the transmitter and receiver, and also requires good balance between 0s and 1s in the message stream in order to maintain the DC balance of the message. UARTs do not provide these. They work a bit with ASK wireless, but not as well as this code."