443MHz RF module with Arduino

 Here we will show how to use the 443MHz RF module with Arduino. We will show RF communication between two Arduino each of which are connected to the transmitter and receiver. Here Arduino Nano and Arduino Uno are used but one can use any of the Arduino Board. In order to simplify the coding part we will use a RF communication library for Arduino called Readhead. This library is freely available below it is explained how to install it and where to download the library. This tutorial is useful for any wireless communication projects. With the 433MHz RF wireless module one can create wireless remote control application such as in controlling robotics, RC cars, to make wireless industrial automation and control, wireless security system, for wireless communication, Internet of Things(IoT) and many more.

433MHz RF module

The 443MHz is a popular and easy to use wireless RF module. It comes in pairs with transmitter and receiver. Below picture shows one such RF module.

433MHz RF module
 The following shows the transmitter part of the RF module which has three pins VCC,DATA and GND.

The VCC is the positive supply pin which is +5V, GND is the ground pin and the DATA is the transmitter pin which is connected to microcontroller or Arduino pin.

The following shows the 433MHz RF receiver module.

The receiver module has four pins- VCC, DATA, DATA and the GND. The VCC is for positive supply voltage which is +5V, the second and the third is for received data which is connected to microcontroller or Arduino board and the GND pin which is for the ground.

Interfacing 433MHz RF module with Arduino

The schematic diagram shown below shows how to connect the 433MHz transmitter to Arduino Nano and 433MHz receiver to Arduino Uno. 

433MHz RF module communication using Arduino

 The RF transmitter consist of the 433MHz transmitter and Arduino Nano. The transmitter module Vcc is connected to +5V and the ground pin is connected to the Arduino Nano ground pin. The DATA pin of the transmitter module is connected to the digital pin 12 of the Arduino Nano. It is connected to digital pin 12 because the RF communication library that we will be using in the program uses pin 12 as default pin for transmitter.

The RF receiver consist of the 433MHz receiver and Arduino Uno. The Vcc and ground pin of the RF receiver module are connected to +5V and ground of the Arduino Uno. The DATA pin of the RF module is connected to pin 11 of the Arduino Uno. 

RF communication library

In this tutorial RF communication library called Radiohead is used. You can download the library from the following link:

https://www.airspayce.com/mikem/arduino/RadioHead/

Once you have downloaded the zip file you can install it in Arduino IDE by going to Sketch > Include Library > Add .ZIP library as shown below.

 

 Then browse to the folder where you saved the RadioHead zip file and select it.

You can check whether the library was installed, close and re-open the Arduino IDE. Then go to the Sketch > Include Library and check for RadioHead as shown below.

Program & Source Code

The program code consist for transmitter and receiver. The transmitter code is to be loaded into the Arduino Nano and the receiver code is to be loaded into the Arduino Uno.

The transmitter code is below(rf_tx.ino).


// RF 433MHz Modules Transmitter Program
// Module Data pin connected to Arduino digital pin #12 which is used by the library default

#include <RH_ASK.h>
// Serial Peripheral Interface (SPI)
#include <SPI.h>               // Required to compile

RH_ASK driver;

void setup () {
  Serial.begin (9600);         // For debugging only
  if (!driver.init ())
    Serial.println ("Initialization Failed!");
}

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

The receiver code is below(rf_rx.ino).


// RF 433MHz Module Receiver Program
// Module Data pin connected to Arduino digital pin #11 which is used by the library default

#include <RH_ASK.h>
// Serial Peripheral Interface (SPI)
#include <SPI.h>               // Required to compile

RH_ASK driver;

void setup () {
  Serial.begin (9600);         // For debugging only
  if (!driver.init ())
    Serial.println ("Initialization Failed!");
}

void loop () {
  uint8_t buff [6];
  uint8_t bufflen = sizeof (buff);
  
  if (driver.recv (buff, &bufflen)) {        // Non-blocking
    int i;
    // Message with a good cheksum received, dump it
    Serial.print ("Received Message: ");
    Serial.println ((char*) buff);
  }
}


In both the transmitter code and receiver code we have used the RadioHead library. The spi header is required to compile the library so it is also included both the transmitter and receiver library. To use the radiohead library we have created the driver object. Then both the transmitter and receiver code setup() function we have used the init() method along with the driver object to check for any error in the initialization code of the library. If there is any error then Initialization Failed! message will be displayed on the serial monitor. In the transmitter code in the loop() function we create a string message Hello! and use the send() method of the object driver to send the message string. The method waitPacketSent() is used to create delay that is required by the library to encapsulate the string message into radio packet and send out to the antenna. A further 1 second delay is also used at the end just to create some time space between each message sent. At the receiver code, in the loop() function, a buffer array called buff[] is created which is used to hold the message. The length of this array is 6 which is the number of character sent by the transmitter which is Hello! with 6 character. The bufflen is just the buffer length which evaluates to 6. Then using if statement we check whether there is any message received using the recv() method along with the driver object. If there is character available then we print out the received message and sent to the serial monitor.

Once the codes are loaded we can see at the receiver serial monitor the message sent by the transmitter displayed on the receiver serial monitor.

Video Demonstration

The following video shows how the 443MHz RF Wireless Communication with Arduino works. 



Post a Comment

Previous Post Next Post