Earn Maker Points on Every Order! Learn More!

NRF24L01 RF Transceiver Module Communication – Arduino

Back to Blog
NRF24L01 RF Transceiver Module Communication - Arduino - NRF24L01 RF Transceiver Module Communication - Arduino - NRF24L01 RF Transceiver Module Communication - Arduino - NRF24L01 RF Transceiver Module Communication - Arduino

NRF24L01 RF Transceiver Module Communication – Arduino

NRF24L01 is a Low power 2.4 GHz wireless RF Module from Nordic Semiconductors. It can operate with baud rates from 250 kbps up to 2 Mbps. If it is operated in an open space with a lower baud rate, it can reach up to 300 feet. So it is used in short range applications like Home Automation, Toys, Gaming Controllers and more.

The NRF24L01 Module can able to both transmit and as well as receive the data. It uses SPI protocol for communicating with Microcontrollers. Hence you can use the Module with Arduino on SPI Communication pins. We will see how to interface this module with an Arduino and control an LED from another Arduino.

With a 1 Mhz spacing on 2400 Mhz – 2525 Mhz operating range (2.40Ghz – 2.525 GHz), it can give a possibility to have a network of 125 independently working modems in the same area.

Each channel can have up to 6 addresses and can communicate with up to 6 other units at the same time.

Features:

  • Operating Voltage:9V to 3.6V
  • Supply Voltage:3V
  • Pin Voltage: 5V Tolerant (no need for Level Converters)
  • Low-cost single-chip 2.4GHz GFSK RF transceiver IC
  • Operating Range (open space): 300 feet (can increase up to 3000 feet using an external antenna)

In this tutorial, we will send and receive data using two NRF24L01 Module setup. One setup is for Transmitter side and another for Receiver side. We send commands as string “ON” (whatever message you want to send) on the transmitter side, The Receiver side we will print the same message on Serial Monitor that was sent from the other side.

Components Required:

  • Arduino Uno – 2 Nos. (can also use Nano)
  • NRF24L01 Wireless RF Module – 2 Nos.
  • Jumper Wires

Libraries:

RF24 Library – https://github.com/tmrh20/RF24/

Pin Details of NRF24L01 Module:

nRF240l

  1. GND – Ground
  2. VCC – Power Supply 3.3V (1.9V to 3.6V)
  3. CE – Chip Enable
  4. CSN – Chip Select Not
  5. SCK – Serial Clock for SPI Bus
  6. MOSI – Master Out Slave In
  7. MISO – Master in Slave Out
  8. IRQ – Interrupt Pin (active low)

Only the Module consumes 1.9V to 3.6 V, But the Pins can handle up to 5V tolerant.

Circuit Diagram:

If you are using Arduino Uno, Pro Mini, Nano or Pro Micro, then the SPI Pins are the same as the following circuit diagram. If you are using Arduino Mega then check the SPI pins that are mapped differently as per its hardware design. Check the SPI Library reference page for different SPI Pins on different board types here. Additionally, the Arduino boards have a separate ICSP header for compatible with Sheilds.

Transmitter Side:

The circuit for the transmitter side and receiver side are the same for this example.

NRF Transmitter_bb

Code – Transmitter Side:

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>



RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";



void setup() {

radio.begin();

radio.openWritingPipe(address);

radio.setPALevel(RF24_PA_MIN);

       radio.stopListening();

}



void loop() {

const char text[] = "ON";

radio.write(&text, sizeof(text));

delay(500);

}

Receiver Side:

The circuit diagram is the same for the receiver side also. We will be printing the data sent from the Transmitter to the Reciever on the Serial Monitor.

Code – Receiver Side:

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>



RF24 radio(7, 8); // CE, CSN



const byte address[6] = "00001";



void setup() {

  Serial.begin(9600);

  pinMode(4,OUTPUT);

  radio.begin();

  radio.openReadingPipe(0, address);

  radio.setPALevel(RF24_PA_MIN);

  radio.startListening();

}



void loop() {

  if (radio.available()) {

    char text[32] = "";

    radio.read(&text, sizeof(text));

    Serial.println(text);

}

Description:

The NRF24l01 can act as a transmitter and receiver.  In the above code on the transmitter side, we send ‘ON’ text and the same will be displayed on the receiver side via Serial Monitor and Turns ON the LED Connected at Pin 4.

The NRF24l01 can be identified by its address. It is mentioned in a number string. We used

const byte address[6] = "00001";

We used ‘00001’ as the address here. You can assign any number string to set the address.

The data is sent via a read/write pipe on the NRF24l01. It is a temporary buffer that holds the data to be sent or received.

Transmitter – Writing data to the Pipe

radio.openWritingPipe(address);

Receiver – Reading data from the Pipe

radio.openReadingPipe(0, address);

This is the simple transmitting and receiving setup for the NRF module. Alternatively, you can send sensor data from the transmitter side and according to the sensor values, you can perform some actions on the receiver side.

 

Baby Monitoring System using NRF24L01

We will do a small project using the NRF24L01 Modules. In this project, we connect a sound sensor on the Transmitter side. On the receiver side, the mom has a watch which has a vibration motor. She can wear that watch and go back to her other daily activities on home. Whenever the baby starts crying, the mom gets an alert on his watch (The Receiver Side). So that she will come back and takes care of her child.

The circuit will be more similar to our previous example. Additionally, we will connect a sound sensor on the transmitter side and a vibration motor on the receiver side.

Transmitter side:

The sound sensor will get turned on whenever it detects a high pitch sound. This remains for just a fraction of second. We need a delay to hold the value at least for 500ms. So that you can send there will be stability on the receiver side.

Circuit Diagram – Transmitter:

 

Baby Transmitter_bb

Code – Transmitter side:

#include <SPI.h>                            //SPI Library
#include "nRF24L01.h"
#include "RF24.h"                          //RF24 Library

RF24 radio(7,8);            //(CE,CSN)Creating an object

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

unsigned long Command ;

void setup()

   {

    Serial.begin(57600);

    pinMode(A2,INPUT);

    radio.begin();                       

    radio.setRetries(15,15);             

    radio.openReadingPipe(1,pipes[1]);

    radio.startListening();

    radio.printDetails();

    radio.openWritingPipe(pipes[0]);    

    radio.openReadingPipe(1,pipes[1]);

    radio.stopListening();               //switch the modem to data transmission mode

   }


  void loop(void)

   {

    radio.stopListening();

    int soundSense = analogRead(A2);   //Reading Sound Sensor Data

    Serial.println(soundSense);        //Printing Sound data on serial monitor.

    if (soundSense <800){              //If value is less than 800 set command as 1

    Command=1;

    delay(1000);      //Delay to hold the trigger for at least 1 Sec

    Serial.println("Data Sent");    //For our reference

   }

    else

      {

        Command=2;                //Command 2 in Idle

        //delay(500);

      }

    radio.write( &Command, sizeof(unsigned long) );

    radio.startListening();

    delay(100);

  }

 

Receiver Side:

In the receiver side, we connected the vibration motor on Pin 3. Using an If else loop we will trigger the motor for 3 seconds when sound detected on the transmitter side. You can increase the vibration time by increasing delay in the if loop.

Circuit Diagram – Receiver:

 

Baby Receiver_bbCode – Receiver Side:

#include <SPI.h>                         

#include "nRF24L01.h"

#include "RF24.h"                        

RF24 radio(7,8);    // CE, CSN                     

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

typedef enum { role_ping_out = 1, role_pong_back } role_e;

const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};

role_e role = role_pong_back;

void setup(void)

   {

    Serial.begin(57600);

    pinMode(3,OUTPUT);

    radio.begin();                    

    radio.setRetries(15,15);

    radio.openReadingPipe(1,pipes[1]);

    radio.startListening();            //Starts Listening

    radio.printDetails();

    radio.openWritingPipe(pipes[1]);

    radio.openReadingPipe(1,pipes[0]);

    radio.startListening();

   }


 void loop(void)

   {

    if ( radio.available() )               //check data received

       {

          unsigned long data = 0;

          radio.read( &data, sizeof(unsigned long) );    //Read data

          Serial.println(data);

             if (data==1)                     //Compare data

                  {

                    digitalWrite(3,HIGH);     //Turn ON Vibration Motor if 1

                    Serial.println("It's High");

                    delay(3000);

                  }

            else if (data == 2)

                  {

                    digitalWrite(3,LOW);      //Turn OFF Vibration motor

                    Serial.println("It's Low");

                    //delay(1000);

                  }

  delay(20);

       }

    }

 

Share this post

Comments (3)

  • Tharindu

    Thanks man thank a lot……..

    June 29, 2019 at 8:06 AM
  • sravya

    I interface the NRF module to Arduino to control wireless light intensity control for cluster control led light i connected only one light but i don’t know how to control heavy load (16 Amps) lights through arduino and NRF module please give some idea to implement this project Thank you

    October 30, 2019 at 6:17 PM
  • satya

    I try to communicate with two NRF module tx mode and rx mode and i established connections and upload the code in tx side i connected switch and rx side led was connected but it was not working what’s the problem i dont know….

    November 29, 2019 at 12:49 PM

Leave a Reply

Back to Blog