Help to get two Arduino communicate through RF

Hello Guys,

In fact; I'm new in this field and this website as well. I do not have that much experience about programming, but I can learn and understand the things fast.

I get interesting to deal with electronic and programming especially with Arduino, since my discipline is purely Electrical. I'm looking for you help for my project. I explain below:

In fact, I'm working on Arduion board called Seeeduino ATMEGA 168. I would like to setup a code for transmitting and receiving signal wirelessly by using transmitter RTFQ2 and receiver RRFQ2 Hybrid Module. I would like to connect the transmitter in Arduino board and the receiver in another Arduino board . Then transmitting an analog signal using potentiometer joystick and receive it by printing the transmitted and received signals into the Serial Monitor to observe the function.

In fact; I'm working on a project with other colleague to design a control system for sailboat to be used by a disabled person.

Therefore; we would like initially from you guys if you could provide us with some basic codes for transmitting and receiving signals through two Arduino boards using Radio control circuits and 2-Axis joystick. Or if you could advise....

Your hard work is appreciated.

I hope you guys understand my explanation and needs.

I'm looking for your kindly support on this soon as possible.

Looking forward to hear from you positively.

All the best.

Cheers.

I don't think there are many people who would write code for you. If you are a fast learner then I'm sure these links will help you:

I can't find anything on that RF link though so you might be on your own for that.

Mowcius

Thank you very much for you kindly support.

In fact; I can write some code to defines the inputs and outputs, but I do not know how to convert the analog singnal to digital. Because we cannot send an analog signal having 0-5v range. Therefore; I'm looking for how can I do this or otherwise to use one of Arduino board function called ADC (analog to digital converter).

The arduino automatically turns it into a digital value of 0-1023 when you do an analogRead command from the analog pins:
http://www.arduino.cc/en/Reference/AnalogRead

Then you can send that value via the RF link.

Mowcius

okay, I got you..

One more think if you do ot mind, how can I let the microcontroller understand I wnat to transimtt this analog singal through the tx?
I mean which command I have to write to let the microcontroller to understand my needs!

Cheers..

to transmit serial commands through the tx pin all you have to do is:

Serial.print(joyval);

joyval being the value that was taken from the analogRead of the joystick pin.

You might also want to look into NewSoftSerial (NewSoftSerial | Arduiniana) which allows you to use any digital pin as a 'virtual' serial port so that you are not using the hardware serial pins (they are used when uploading code through the USB port so you would need to disconnect anything from them before uploading new code)

Mowcius

Thanks mate,

What do you mean by joyval? do you mean the 0-1023 val!

I will setup new code now and I will follow the information that you provided for me. Then I will test it and post it shortly.. :wink:

Thank you mate for your prompt concern.

See you shortly. :slight_smile:

All the best

What do you mean by joyval? do you mean the 0-1023 val!

Yes, I just assigned it a variable name (joyval). When you read the analog value, you save it as a variable and then send that variable via serial.

I will setup new code now and I will follow the information that you provided for me. Then I will test it and post it shortly.. Wink

Thank you mate for your prompt concern.

No problem.

Mowcius

Thanks mate.

Cheers.. :slight_smile:

What about the receiver Serial? I mean once I transmitt the signal using Serial.print(joyval) command, which command I have to write to let the receiver to read the signal transmitted?
Is it going to be Serial.Read(joyval)?
Or Serial.Write(joyval)?

Cheers. :slight_smile:

TX code:
int ledPin = 13;
int potPin1 = 0;
int potPin2 = 1;
int val1 = 0;
int val2 = 0;
int rx = 0;
int tx = 1;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(rx, INPUT);
pinMode(tx, OUTPUT);
Serial.begin(4800);
}

void loop() {
val1 = analogRead(potPin1);
val1 = map(val1, 0, 1023, 0, 255);
delay(100);
Serial.println(val1);
val2 =analogRead(potPin2);
val2 = map(val2, 0, 1023, 0, 255);
Serial.println(val1);
}

Could anyone give an advise about this code to transmit an analog signal from 2-axis potentiometer from one Arduino board to be received by another Arduino board!?

Thanks guys.. :slight_smile:

int ledPin = 13;
int potPin1 = 0;
int potPin2 = 1;
int val1 = 0;
int val2 = 0;

void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(rx, INPUT);
 pinMode(tx, OUTPUT);
 Serial.begin(4800);
}

void loop() {
 val1 = analogRead(potPin1);
 val1 = map(val1, 0, 1023, 0, 255);
 delay(100);
 Serial.println(val1);
 val2 =analogRead(potPin2);
 val2 = map(val2, 0, 1023, 0, 255);
 Serial.println(val2);
}

The other arduino needs to wait for serial. It cannot tell if it is val1 or val2 but as one will be after the other there shouldn't be a problem.

Download the newsoftserial library that I linked and put it into the arduino libraries folder on your hard drive then look at this code...
If you use this code on the other arduino then it will take any values that it receives and send them to the serial monitor (if the usb cable is plugged in):

#include <NewSoftSerial.h>

NewSoftSerial RFSerial(2, 3); //'virtual' rx pin, 'virtual' tx pin

void setup()  
{
  Serial.begin(9600);
  RFSerial.begin(9600);
}

void loop()                     // run over and over again
{
  if (RFSerial.available()) {
      Serial.print((char)RFSerial.read());
  }
}

Experiment with that and see where you get. You could plug the RF module into the receiving arduino's hardware serial ports and then it would send it to both the arduino and computer without any code.

There are lots of possible reasons why that might not work out quite according to plan but it should give you an idea.

Mowcius

Thanks mate.

Is it possible to attach the RF modules (transmitter and receiver) in oneArduino board? I mean, transmit an anlog signal and receive it through the same Arduino board? And then print the outcomes into the Serial Monitor.

Please Advise.

Cheers. :slight_smile:

Yes, by using the newsoftserial library mentioned above you can send from a virtual pin to an RF module and the receive through the hardware serial pins (0 & 1) which will send it to the serial monitor (assuming baud rate is set correctly)

Mowcius

Okay mate..

I will try this now.

Because the other Arduino board is with my friend right now.
And I would like to safe some time and keep working.

Anyhow I will do it and send some feedback.

Cheers. :slight_smile:

Hello again,,

I ran it as shown below:
tx & rx code:
#include <NewSoftSerial.h>

int ledPin = 13;
int potPin1 = 0;
int potPin2 = 1;
int val1 = 0;
int val2 = 0;
int rx = 0;
int tx = 1;
NewSoftSerial RFSerial(0, 1);

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(rx, INPUT);
pinMode(tx, OUTPUT);
Serial.begin(4800);
RFSerial.begin(4800);
}

void loop() {
val1 = analogRead(potPin1);
val1 = map(val1, 0, 1023, 0, 255);
delay(100);
Serial.println(val1);
val2 =analogRead(potPin2);
val2 = map(val2, 0, 1023, 0, 255);
Serial.println(val2);
if (RFSerial.available()) {
Serial.print((char)RFSerial.read());
}
}

I think the data shown in Serial monitor refer to the transmitter side. I do see changes in accordance to the potentiometer, but there is no receiving signal at all. I check that by using Multimeter and I measured the voltage in transmitter when the joystick was in neutral.
It gives me 2.35v, once I moved forward gives me 1.50 v but when moved backward remains the same as neutral voltage (2.3v).
I tested only one axis.
Also, I measured the voltage in receiver side I found the voltage around 4.15v.

could you please Guys advise the outcomes I got and even the code I wrote. Am I in right truck? Or do I need to modify things? Or do I need do something else.

Your comments are really appreciated.

Cheers.. :slight_smile:

Yousuf

#include <NewSoftSerial.h>

int ledPin = 13;
int potPin1 = 0;
int potPin2 = 1;
int val1 = 0;
int val2 = 0;
NewSoftSerial RFSerial(2, 3);

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(4800);
RFSerial.begin(4800);
}

void loop() {
val1 = analogRead(potPin1);
val1 = map(val1, 0, 1023, 0, 255);
delay(100);
RFSerial.print(val1);
val2 =analogRead(potPin2);
val2 = map(val2, 0, 1023, 0, 255);
RFSerial.print(val2);
delay(1);
if (RFSerial.available()) {
Serial.println((char)RFSerial.read());
}
}

Right... Plug the transmitter one into 2,3 and the receiver into 1,2 respectively and then you should see the values from the potentiometers mapped from 0-255 in the serial monitor. The code is taking the pot values, mapping them 0-255 then sending them to the software serial port (2,3 - rx,tx) to the RF module. This then sends it via RF to the receiver module (plugged into 0,1) where it then displays on the serial monitor.

Take a look at what I changed on the code and that might also give you a better idea of what it's all doing.

I may be misunderstanding what RF units you are using but I think it should be fine.

could you please Guys advise the outcomes

To be honest, I think it's just me reading this thread...

Mowcius

Thanks mate,

I really appreciate your hard comments toward my concern.

I will re-test it now and send some feedback.

Sorry for any inconvenience mate.

All the best.

Cheers :slight_smile:

I'm using FM transmitter and receiver Hybrid Modules (FM-RTFQ2 & FM-RRFQ2) with 433 MHZ.

Plug the transmitter one into 2,3 and the receiver into 1,2 respectively

What do mean by that? Do you mean the pins number 2,3 & 1,2.

In transmitter I have 5 pins :
two for ground.
one for vcc.
one for data input.//I plugged this into the Arduino board as tx pin (1).
one for external antenna.

In receiver I have 7 pins:
two for ground.
one for vcc.
one for AF output.
one for received signal strenght output.
one for data output.// I plugged this into the Arduino borad as rx pin (0).
one for data in (antenna).

Please advise.

Cheers