Linking arduinos through RF

Greets everybody this is my first post on the forum and first project with the arduino. In the end I'm looking to create a simple txt messaging network with 2-5 (phones) but so far I am unable to do even the simplest communication.

Hardware:
RF Link 4800bps Receiver - 315MHz
RF Link Transmitter - 315MHz

Transmitter Code:

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3

int val = 0;            // variable to store the value

SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);   //using softwareserial

void setup() {
   
 rfSerial.begin(9600);       //initialize softwareserial
 Serial.begin(9600);         // begin serial communication over USB to the computer for debugging purposes
}
void loop(){
     val = 1020;
     
     Serial.print(val);               // send data to computer
     rfSerial.print(val, DEC);    // send data out tx
     //PreVal = val;
     delay(100);
 }

Receiver Code:

#include <SoftwareSerial.h>                    
#define rxPin 2
#define txPin 3
SoftwareSerial rfSerial =  SoftwareSerial(rxPin, txPin);
int val = 0;


void setup() {
 pinMode(rxPin, INPUT);              // set up pin for serial comm. with RF receiver
 rfSerial.begin(9600);                 // begin serial connection with RF Link unit
 Serial.begin(9600);                   // begin serial communication over USB to the computer  
}
void loop(){
 
               val = rfSerial.read();           //Read a Byte?? from the RX
               if ( val == 1020 ) {
               Serial.print(val, DEC);         // send data to computer in Decimal
             }
}

If it's a 4800bps RF link, why are you running it at 9600?

 rfSerial.print(val, DEC);    // send data out tx
val = rfSerial.read();           //Read a Byte?? from the RX
               if ( val == 1020 ) {
               Serial.print(val, DEC);

You're sending the value as an ASCII decimal string - that's how you should receive it too.

Thank you for the fast reply, I have changed the rates to 4800 on both transmitter and receiver code not sure how I overlooked that.

You're sending the value as an ASCII decimal string - that's how you should receive it too.

how would I go about doing this?

once again thank you for the support I hope to contribute as soon as I learn my way around the arduino.

OK, you're transmitting the characters '1' '0' '2' '0'.
In hex, these characters are represented by the byte values 0x31, 0x30, 0x32, 0x30.
So four bytes.
You need to collect all four characters, and then convert the collection to decimal.
Search for "atoi".
You'll need to convert the four characters to a string first.

hi,

i trying the exact same thing :slight_smile:
but just want to send one byte(0 or 1) from one board to another also using seperate transmitter/receiver modules...it should act like an on/off switch, found any solution yet?????
my boards operate with 868 mhz do u know how to find out the baud rate? here is the link to my boards:
http://www2.produktinfo.conrad.com/datenblaetter/175000-199999/190939-an-01-ml-Sende_Empfaenger_ModulSet_868MHz_de-en.pdf
thx
akira

Well, my German's not great (all but non-existant), but "Bandbreite" has to translate as "Bandwidth" (Band-breadth, literally, I guess), so at 2kHz, I wouldn't expect to be able to push the bit-rate much past 1200 bps.

hi,

thx for the answer, but even with the changed baud rate i'm only getting
a zero as an output on both the receiver and transmitter even by putting them on one board??????? maybe there is a prob with the type of value i'm transmitting(byte, dec, int)....i'm getting nuts already!!!!!
thx
akira

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3


int val = 0;            // variable to store the value coming from the sensor


SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);   //using softwareserial

void setup() {
 pinMode(rxPin, INPUT);      //set recieve as an input
 pinMode(txPin, OUTPUT);     //set transmit as an output 
 rfSerial.begin(1200);       //initialize softwareserial
 Serial.begin(9600);         // begin serial communication over USB to the computer for debugging purposes
}
void loop(){
 
     val = 1;
     
     Serial.println(val, DEC);     // send data to computer
     rfSerial.print(val);    // send data out tx
     val = rfSerial.read();
     Serial.print("reader: ");
     Serial.println(val, DEC);
     delay(100);
 //}
}

Aren't these

    rfSerial.print(val);    // send data out tx
     val = rfSerial.read();

synchronous?
If they are, then I wouldn't expect to receive anything.

hi,

i thought the print command always goes to the tx and the read checks the rx or am i mistaking something???

Yes, but if you take a look at the software serial library, you'll see that everything takes place syncrhonously.
First, the "rfSerial.print ()" clocks out to the Tx pin all the data it has been given, then the "rfSerial.read()" looks for a start bit on the Rx.
But the start bit has already disappeared into the ether, via the Tx pin, as has all the data and the stop bit.

okay, so what would be the solution, a delay perhaps or would it work by just sticking it on two boards one for the receiver and one for the transmitter?
thx again and many more times :slight_smile:

a delay perhaps or would it work by just sticking it on two boards one for the receiver and one for the transmitter

A delay can't work, so yes, try putting tx and rx on different boards.

been there done that...here is my code 4 the two boards...still getting random values(mostly 0) on the receiver side

transmitter code:

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3

int val = 0;            // variable to store the value coming from the sensor


SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);   //using softwareserial

void setup() {
 pinMode(rxPin, INPUT);//set recieve as an input
 pinMode(txPin, OUTPUT);//set transmit as an output 
 rfSerial.begin(1200);       //initialize softwareserial
 Serial.begin(9600);         // begin serial communication over USB to the computer for debugging purposes
}
void loop(){
     //val = analogRead(potPin);    // read the value from the sensor
     val = 1;
     Serial.print(val);               // send data to computer
     rfSerial.print(val, DEC);    // send data out tx
     delay(100);
}

receiver code:

#include <SoftwareSerial.h>                    
#define rxPin 2
#define txPin 3
SoftwareSerial rfSerial =  SoftwareSerial(rxPin, txPin);
int val = 0;

void setup() {
 pinMode(rxPin, INPUT);                // set up pin for serial comm. with RF receiver
 pinMode(txPin, OUTPUT);               //set transmit as an output
 rfSerial.begin(1200);                 // begin serial connection with RF Link unit
 Serial.begin(9600);                   // begin serial communication over USB to the computer  
}
void loop(){
 
               val = rfSerial.read();           //Read a Byte?? from the RX
               Serial.print(val, DEC);         // send data to computer in Decimal
               delay(100);
}

WHY WON'T IT WORK!!!!!!!
thx for ur time

funny thing is when i comment out the delay on the receiver side i get values up th a**???

still getting random values(mostly 0)

What are the other values?

funny thing is when i comment out the delay on the receiver side i get values up th a**???

I don't understand this sentence.
The delay on the receiver should be much less than the delay on the transmitter.

I'd be inclined to drop the bit-rate as low as possible, say 300bps

pinMode(rxPin, INPUT);//set recieve as an input
 pinMode(txPin, OUTPUT);//set transmit as an output

These lines are irrelevant.

these are the values i get with 300bps and 100ms delay at the receiver:

0000003200000000000000320000000800000000000001200000000000000004000000020000000000000012800000400000000000000000000000000000000000000000000000000000000004810000000000024012800081665000000006400000000960000064000000000000001280-1000000000000004800000

and these i get with 300 baud and no delay at the receiver:
10000004096406408648140480016016080009900286580324032480032130289713403312800192000166500006443238644000161032138489740328008974060003266001281600448132800410161290003200320160432006403341620644-1000028448006412000012880016130032048650330326480016194281136169700088

Can you write a simple Rx sketch to simply copy the state of the rx pin to a LED?
Just a simple "loop()" with a "digitalWrite (ledPin, digitalread (rxPin));"
Now turn off the Tx completely - what do you see?

I used to have a similar problem, eventually traced to a wireless door bell...

hi,
here is the code

#include <SoftwareSerial.h>                    
#define rxPin 2
#define txPin 3
int ledPin = 13;
SoftwareSerial rfSerial =  SoftwareSerial(rxPin, txPin);
int val = 0;

void setup() {
 //pinMode(rxPin, INPUT);                // set up pin for serial comm. with RF receiver
 //pinMode(txPin, OUTPUT);               //set transmit as an output
 rfSerial.begin(300);                 // begin serial connection with RF Link unit
 Serial.begin(9600);                   // begin serial communication over USB to the computer  
}
void loop(){
 val = digitalRead(rxPin);
  digitalWrite (ledPin, val);
  
               //val = rfSerial.read();           //Read a Byte?? from the RX
               Serial.print(val, DEC);         // send data to computer in Decimal
               delay(100);
}

i disconnected the transmitter board from the usb so there should be nothing coming in, however the led flashes now and then at a seemingly constant rate
here is the output of the output window:
00000000000000001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001

What if you enable Rx pullup?

whats Pullup???