Establishing a Wireless Connection with Arduino and NRF24l01

Overview

Nowadaysestablishing a wireless connection and creating a wireless network is very important in communication and IOT projects. In this tutorial, you’ll learn how to establish a wireless connection between two Arduino boards and create a network using the NRF24L01 module. 

What You Will Learn

  • What NRF24L01 module is and how it works 
  • Connecting two Arduino boards to create a wireless connection 
  • Create a network of NRF modules 

What Is the NRF24L01 Module and How Does It Work?

There are different ways for wireless communication such as Bluetooth, WiFi, and etc. Using the NRF24L01 module is one of the most affordable, simple, and practical ways. 

NRF24L01 Module is a transceiver module, which means it can both send and receive data. NRF24L01 works in 2.4 GHz frequency and uses GFSK modulation. The maximum speed of data transmission of this module is up to 2Mbps and the maximum board is 100 meters (for models with an external antenna the board can be 1 km) in free space. 

parameter ResponseTypical value
Working voltage 3.3 v
Current usage in send mode 11.3 mA
Current usage in receive mode 12.3 mA
Current usage in sleep mode 900 nA
Temareture range-40 to +85 C
price2.5 $

Capability to create a network is one of the NRF module advantages; each NRF module can be connected to 6 other modules. 

Therefore, the affordable price, being easy to use, small size, networking capabilities, high board and suitable data transfer speeds make the NRF24l01 module a great option for wireless and IOT projects. 

NRF24L01 module interface microcontrollers in SPI protocol and has 8 pins: 

PinOperation
GNDCircuit ground
VccCircuit supply voltage(3.3V)
CEChip Enable
CSNSPI Chip Select
SCKConnection CLK
MOSIReceiving data from Master
MISOSending data to Master
IRQIntrupt pin

Required Materials

Hardware Components

Arduino UNO R3×2
NRF24L01×2

Software Apps

Arduino IDE

Connecting Two Arduino Boards to Establish a Wireless Connection

In order to connect two Arduino boards, you need two NRF24L01 modules, one as master and another as slave. In this example, using a volume on the master side, we control the servo motor on the slave side. 

Circuit

Tip
You can connect CSN and CE to any digital pins. 

Tip
Connect SPI pins of the module to SPI pins on board. 

Code

You need the RF24 library to use NRF24L01 module. Download the library from the following link:

Rf24 Library Download 

Tip
You need two different codes for slave and master to establish a connection. 

Master 

Upload the following code on your master board.

Slave 

Upload the following code on your slave board.


Let’s take a closer look to the code: 


Create the required object for module by specifing CS and CSN pins. 


Specify the address for the nodes. Be careful, the sender and receiver addresses must be the same in order to communicate. 


Determine the receiver for transmitter. 


Determine the transmitter for receiver.


Determine the amount of power consumption for the module, this value must be determined according to the transmitter and receiver distance.


Set the module in transmitter mode. 


Set the module in receiver mode.


Sends the data by specifying its size. 


If the receiver receives a data, ireturns the value of 1  


Receives the data by specifying its size, and stores it in data variable.

Create a Network of NRF Modules

Using the NRF24L01 module, you can create a wireless connection and transfer data in your network. 

In this example, we want to create a network with three slaves and perform a specific operation in the slaves based on the temperature data, the volume value and the key status sent from the master. 

There are two ways to build the network, the simpler way is to act as in the previous example and to have a maximum of 6 separate addresses to send information to the master through 6 slaves. 

In the second way, the tree method is used for networking. As a result, the main master is only associated with its subset, and each subset is expanded as a tree. Consequently, we can construct a network containing a maximum of 3125 NRF24L01 modules, so this method is more effective from the first one. 

Circuit

Code

To use this method, you need the RF Network library. You can download it from the following link: 

RF24Network Library Download

Master 


Node01 


Node02


Node03

What's Next?

  • Try to make a two-way connection with two NRF24L01 modules, which means that each module has the ability to send and receive data. 

Share this post

Comments (3)

  • El Mik Reply

    Awesome simple great and rich article. Thank you!!!

    October 15, 2019 at 9:09 pm
    • Saeed Hosseini Reply

      We always try to do our best

      October 21, 2019 at 5:41 am
  • Kiran Mahapatra Reply

    Great project .. Thank You ……..
    Please help me
    in case of 3 transmitter & 1 receiver what to do. I want to make a project …………….. 3 nos transmitter with a push button on each & 1 receiver which have a LED bulb & a LCD display. When push button pressed from any transmitter the led on for a certain time & LCD display will show from which transmitter the switch is pressed . If I want to increase transmitter no what to do?

    January 8, 2020 at 2:40 am

Leave a Reply

Your email address will not be published. Required fields are marked *