RF Transmitter and Receiver Module Interfacing with Arduino

RF Transmitter and Receiver Module Interfacing with Arduino: In this article you will learn how to interface RF transmitter and receiver module with Arduino and how to send data from RF transmitter to RF receiver. It has many application in embedded system projects. So lets get start with introduction to these modules. A radio frequency (RF) signal refers to a wireless electromagnetic signal used as a form of communication. Radio waves are a form of electromagnetic radiation with radio frequencies that range from 3Hz to 300 GHz. Frequency refers to the rate of oscillation. RF propagation occurs at the speed of light and does not need a medium like air in order to travel. RF waves occur naturally from sun flares, lightning, and from stars in space that radiate RF waves as they age. Humankind communicates with artificially created radio waves that oscillate at various chosen frequencies. RF communication is used in many industries including television broadcasting, radar systems, computer and mobile platform networks, remote control, remote metering/monitoring, and many more.RF Transmitter and Receiver Module Interfacing with Arduino

Working of RF Transmitter and Receiver:

Imagine holding out your hand and catching words, pictures, and information passing by. That’s more or less what an antenna does. It’s the metal rod or dish that catches radio waves and turns them into electrical signals feeding into something like a radio or television or a telephone system. Antennas like this are sometimes called receivers. A transmitter is a different kind of antenna that does the opposite job to a receiver. It turns electrical signals into radio waves so they can travel sometimes thousands of kilometers around the Earth or even into space and back. Antennas and transmitters are the key to virtually all forms of modern telecommunication.

To receive radio signals an antenna must be used. However, since the antenna will pick up thousands of radio signals at a time so a radio tuner is necessary to tune into a particular frequency. This is typically done via a resonator which is a circuit with a capacitor and an inductor form a tuned circuit. The resonator amplifies oscillations within a particular frequency band, while reducing oscillations at other frequencies outside the band. Another method to isolate a particular radio frequency is by oversampling which gets a wide range of frequencies and picking out the frequencies of interest, as done in software defined radio. The distance over which radio communications is useful depends significantly on things other than wavelength, such as transmitter power, receiver quality, type, size, and height of antenna, mode of transmission, noise, and interfering signals. Ground waves, tropospheric scatter and sky waves can all achieve greater ranges than line-of-sight propagation.

RF transmitter module:

Transmitter module consists of following Pin outs:

  1. ATAD i.e. DATA it is signal pin which is used to send data for receiver.
  2. Vcc for power supply
  3. GND for power supply ground

RF Receiver Module:

It consists of following pins:

  1. Vcc for power supply
  2. DATA for receiving data from transmitter
  3. DATA for receiving data from transmitter
  4. GND for power supply ground

Connections of RF Transmitter:

RF transmitter interfacing with Arduino

Following are the connections of transmitter circuit

  1. Pin ATAD of module to Pin D12 of Arduino
  2. Pin VCC of module to Pin 5V of Arduino
  3. Pin GND of module to Pin GND of Arduino

Connections of RF Receiver:

RF receiver interfacing with Arduino

Following are the connections of receiver circuit

  1. Pin VCC of module to Pin 5V of Arduino
  2. Pin DATA of module to Pin D12 of Arduino
  3. Pin GND of module to Pin GND of Arduino
  4. Leave second data pin UN connected.

Explanation of Code:

Transmitter code

#include <VirtualWire.h>
const int ledPin = 13;
char *data;
void setup() 
{
 pinMode(ledPin,OUTPUT);
 vw_set_ptt_inverted(true);
 vw_set_tx_pin(12);
 vw_setup(2000);
}

void loop()
{
 data="1";
 vw_send((uint8_t *)data, strlen(data));
 vw_wait_tx();
 digitalWrite(ledPin,HIGH);
 delay(2000);
 data="0";
 vw_send((uint8_t *)data, strlen(data));
 vw_wait_tx();
 digitalWrite(ledPin,LOW);
 delay(2000);
}

Receiver Code

#include <VirtualWire.h>
const int ledPin = 13;
const int datain = 10;
void setup()
{
 Serial.begin(9600);
 vw_set_ptt_inverted(true);
 vw_set_rx_pin(datain);
 vw_setup(2000);
 pinMode(ledPin, OUTPUT);
 vw_rx_start();
}
 void loop()
{
 uint8_t buf[VW_MAX_MESSAGE_LEN];
 uint8_t buflen = VW_MAX_MESSAGE_LEN; 
 
 if (vw_get_message(buf, &buflen))
 {
 Serial.print(buf[0]);
 if(buf[0]=='1')
 { 
 digitalWrite(ledPin,HIGH);
 Serial.print(buf[0]);
 } 
 if(buf[0]=='0')
 {
 digitalWrite(ledPin,LOW);
 Serial.print(buf[0]);
 }
 }
}

#include <VirtualWire.h> Includes the virtual wire library in code

vw_set_tx_pin Selects the Transmitter Data Pin

vw_set_rx_pin Selects the receiver Data  Pin

vw_setup(uint16_t speed); Setup the speed of transmission , The speed of Tx must be as same as on Rx . The speed will be a Number of Bit Per Second between 0-9600 , for short distance you can use fast speed , For long distance “Up to 90m” you must use lower transmission speed as much as possible .

vw_rx_start();  Start the receiver PLL running ,You must do this before you can receive any messages

vw_rx_stop(); You must do this before you can receive any messages. When a message is available vw_have_message() will return true.

vw_wait_tx(); Block and wait until the transmitter is idle

vw_wait_rx(); Block and wait until a message is available from the receiver

vw_send(uint8_t* buf, uint8_t len); Send a message with the given length

vw_have_message(); Returns true if an unread message is available from the receiver.

7 thoughts on “RF Transmitter and Receiver Module Interfacing with Arduino”

  1. The pin connected for data receiving in receiver side and the one in receiver program is different. Make them same and the program runs effectively.

    Reply
  2. Hi. I have been trying to send a message between 2 Arduinos Unos using these instructions but all I am getting is gobbledygook where the message should be. I am using the Radiohead library and example sketch as Virtualwire is now obsolete and discontinued.
    Any thoughts please.
    Thank you in advance.
    Bob May.

    Reply

Leave a Comment