0% found this document useful (0 votes)
37 views13 pages

Interfacing 433MHz RF Module With Arduino

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

How 433MHz RF Tx-Rx Modules Work

& Interface with Arduino

Interested in making your next Arduino project wireless for the price of a cup
of coffee? Then go with a 433MHz RF Transmitter and Receiver Module!

It is available online for less than two dollars, making it one of the most
affordable data communication options available. And, best of all, this module
is so small that you can incorporate it into almost any project.

Hardware Overview
Let’s take a closer look at the 433MHz RF Transmitter and Receiver Modules.

The Transmitter
This tiny module serves as the transmitter. It is as simple as it appears. At the
core of the module is a SAW resonator tuned to operate at 433.xx MHz. Apart
from that, it has a switching transistor and some passive components.

When the DATA input is high, the oscillator generates a constant RF output
carrier wave at 433.xx MHz, and when the DATA input is low, the oscillator
ceases operation; resulting in an amplitude modulated wave. This technique is
known as Amplitude Shift Keying, which we will go over in detail shortly.

The Receiver

This particular module is a receiver. It is as simple as the transmitter module,


despite its appearance. It consists of an RF tuned circuit and a couple of
operational amplifiers (OP Amps) that amplify the received carrier wave. The
amplified signal is then fed into a PLL (Phase Lock Loop), which allows the
decoder to “lock” onto a stream of digital bits, resulting in improved decoded
output and noise immunity.

ASK – Amplitude Shift Keying


As mentioned previously, these modules use a technique known as Amplitude
Shift Keying, or ASK, to transmit digital data over the radio. In amplitude shift
keying, the amplitude of the carrier wave (433 MHz signal in our case) is
modified in response to an incoming data signal.

It’s a lot like the Amplitude Modulation technique used in AM radio. Because it
only has two levels, it is sometimes referred to as Binary Amplitude Shift
Keying.

You can think of it as an ON/OFF switch.

• For logic 1 – the carrier wave is transmitted.

• For logic 0 – no signal is transmitted.


Here is an illustration of Amplitude modulation:

The advantage of Amplitude Shift keying is that it is very simple to implement.


The decoder circuitry is quite simple to design. Furthermore, ASK requires less
bandwidth than other modulation techniques such as FSK (Frequency Shift
Keying). This is one of the reasons why it is cost effective.

The disadvantage of ASK is that it is susceptible to interference from other


radio equipment and ambient noise. However, as long as you transmit data at
a relatively slow rate, it can work reliably in most environments.
433MHz RF Transmitter & Receiver Pinout
Let’s take a look at the pinout of 433MHz RF Transmitter and Receiver
Modules.

DATA pin accepts digital data to be transmitted.

VCC provides power to the transmitter. Any positive DC voltage between 3.5V
and 12V can be used. It should be noted that the RF output is proportional to
the supply voltage, so the higher the voltage, the greater the range.

GND is the ground pin.

Antenna is a pin that connects to the external antenna. To improve the range,
you should solder a 17.3-centimeter-long solid wire to this pin. It is discussed
in detail later.
VCC provides power to the receiver. Unlike the transmitter, the receiver
requires a 5V supply voltage.

DATA pins output the received digital data. Both pins are internally linked, so
you can use either one for data out.

GND is the ground pin.

Antenna is a pin that connects to the external antenna. To improve the range,
you should solder a 17.3-centimeter-long solid wire to this pin.

Wiring the 433MHz RF Transmitter and Receiver


Modules to the Arduino
Now that we have a complete understanding of these modules, it’s time to put
them to use!

Because we’ll be sending data between two Arduino boards, we’ll need two
Arduino boards, two breadboards, and a few jumper wires.

Wiring for the Transmitter

It is simple to wire up the transmitter, as it only has three connections.

Connect the module’s VCC pin to the Arduino’s 5V pin and GND to Ground.
The Data-in pin should be connected to digital pin #12 on the Arduino. Try to
use only digital pin #12 for data input, as the library we are using uses this pin
by default.

The following table lists the pin connections:


Transmitter Arduino
VCC 5V
Data 12
GND GND

The wiring is shown in the image below.

Wiring for the Receiver

After you’ve wired the transmitter, you can proceed to the receiver. The
receiver’s wiring is as simple as the transmitter’s.

Once again, there are only three connections to make. Connect the module’s
VCC pin to the Arduino’s 5V pin and GND to Ground. Connect any of the
middle two data-out pins to the Arduino’s digital pin #11, as they are
internally connected.

The following table lists the pin connections:

Receiver Arduino
VCC 5V
Data 11
GND GND
The wiring is shown in the image below.

RadioHead Library – a Swiss Army Knife for wireless


modules
Unlike advanced RF modules such as the nRF24L01, the 433MHz RF module is
a basic RF module with no data transmission error detection built in.
Therefore, it is our responsibility to incorporate CRC (Cyclic Redundancy
Check) into our code.

This is where the well-known RadioHead library comes in handy. It handles


CRC computations, which makes communication more reliable. The library is
so versatile that it can be used with any type of RF module, not just 433MHz
RF modules.

At the transmitter end, the RadioHead library takes the data, encapsulates it
into a data packet (known as a RadioHead Packet) with a CRC checksum, and
then sends it to another Arduino with the necessary preamble and header. At
the receiver end, if the data is correctly received, the receiving Arduino is
notified that data is available.

The RadioHead Packet

The RadioHead Packet is constructed as follows: At the start of each


transmission, a 36 bit stream of “1” and “0” bit pairs known as a “Training
Preamble” is sent. These bits are required for the receiver to adjust its gain
before receiving actual data. Then a 12 bit “Start Symbol” is added, followed
by the actual data (payload).
At the end of the packet, a Frame Check Sequence or CRC is added, which is
recalculated by RadioHead at the receiver end, and if the CRC check is correct,
the receiving device is alerted. If the CRC check fails, the packet is discarded.

This is what the RadioHead packet looks like:

Download the Library

You can get the library from airspayce.com or by clicking the following link:

RadioHead.zip

To install the library, launch the Arduino IDE, navigate to Sketch > Include
Library > Add.ZIP Library, and then choose the RadioHead file you just
downloaded. For more information on installing a library, see the Installing an
Arduino Library tutorial.

Arduino Example Code


In this simple experiment, we will try to send a short text message from the
transmitter to the receiver and see if it can be decoded. It will be useful in
learning how to use the modules and can serve as the foundation for more
practical experiments and projects.

Code for the Transmitter

Here is the sketch we will use for our transmitter:


// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object


RH_ASK rf_driver;

void setup()
{
// Initialize ASK Object
rf_driver.init();
}

void loop()
{
const char *msg = "Hello World";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
delay(1000);
}

Code Explanation:

It’s a short sketch, but that’s all you need to send a message.

The sketch begins by including the RadioHead ASK library. The Arduino SPI
Library must also be included because the RadioHead library is dependent on
it.

#include <RH_ASK.h>
#include <SPI.h>

To access special functions related to the RadioHead ASK library, we must first
create an ASK object.

// Create Amplitude Shift Keying Object


RH_ASK rf_driver;

In the setup function, we initialize the ASK object.

// Initialize ASK Object


rf_driver.init();
We begin the loop function by preparing a message. It’s just a text string
that’s stored in a character pointer called msg. Keep in mind that your
message can be anything you want, but it should not be longer than 27
characters for optimal performance. Also, keep track of the number of
characters in it because you’ll need it in the receiver code. We have 11
characters in our case.

// Preparing a message
const char *msg = "Hello World";

The message is then sent using the send() function. This function takes two
parameters: an array of data and the number of bytes (data length) to send.

Typically, the send() function is followed by the waitPacketSent() function,


which waits until transmission is complete. Finally, the sketch pauses for a
second to allow our receiver to process everything.

rf_driver.send((uint8_t *)msg, strlen(msg));


rf_driver.waitPacketSent();
delay(1000);

Code for the Receiver

Here is the code for our receiver. Connect the receiver circuit to the computer
and load the following code.
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object


RH_ASK rf_driver;

void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
}

void loop()
{
// Set buffer to size of expected message
uint8_t buf[11];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
{

// Message received with valid checksum


Serial.print("Message Received: ");
Serial.println((char*)buf);
}
}

After loading the sketch, open your serial monitor. If everything is fine, you
should be able to see your message.

433MHz Wireless RF Module Output on Serial Monitor – Receiver

Code Explanation:

The receiver code, like the transmitter code, begins by loading both the
RadioHead and SPI libraries and creating an ASK object.

#include <RH_ASK.h>
#include <SPI.h>
RH_ASK rf_driver;
In the setup function, we initialize the ASK object and configure the serial
monitor to display the received message.

rf_driver.init();
Serial.begin(9600);

In the loop function, we create a buffer of the same size as the transmitted
message. Remember, it’s 11 in our case? This will need to be adjusted to
match the length of your message. Include any spaces and punctuation
because they all count as characters.

uint8_t buf[11];
uint8_t buflen = sizeof(buf);

Then we call the recv() function. This activates the receiver. When a valid
message is available, it copies it to its first parameter buffer and returns true. If
the function returns true, the received message is printed on the serial
monitor.

if (rf_driver.recv(buf, &buflen))
{
Serial.print("Message Received: ");
Serial.println((char*)buf);
}

Then we return to the beginning of the loop and repeat the process.

Improving 433MHz RF module range with an


antenna
The antenna you use for both the transmitter and receiver can have a
significant impact on the range you can achieve. In fact, without an antenna,
you’d be lucky to communicate over a meter. With the right antenna design,
you’ll be able to communicate over a distance of 50 meters.

The antenna does not have to be complicated. A single core wire can be used
to make an excellent antenna for both the transmitter and receiver.

The length of the most effective antenna is equal to the wavelength of a


transmission frequency. In practice, however, half or a quarter of that length is
sufficient.
The wavelength of a frequency is calculated as:

Wavelength of frequency = Speed of the transmission (v)


Transmission frequency (f)

The speed of transmission in air is equal to the speed of light, which is


299,792,458 m/s to be precise. So, for the 433 MHz band the wavelength is:

Wavelength of frequency = 299,792,458 m/s


433,000,000 Hz
= 0.6924 meters
= 69.24 cm

A 69.24 cm antenna is quite long and inconvenient to use. That is why we will
use a quarter wave antenna, which measures 17.3 cm or 6.8 inches.

Coiling the antenna to make it more compact will severely reduce its range. A
straight antenna is always preferable!

You might also like