You are on page 1of 9

Add Project Sign In

(/login#login)
(/) Platforms (/explore) Projects
(/projects) Contest (/contest2020)
Docs (/arduino/basics) Codes (/arduino/codes)

Platforms (/explore) Interfaces (/arduino/interfaces) nRF24L01 Interfacing with Arduino UNO (/arduino/nrf24l01-
interfacing-with-arduino-uno)

nRF24L01 Interfacing with Arduino UNO

Introduction

NRF24L01 is a wireless transceiver module which operates in the 2.4GHz ISM frequency band.

It is used to communicate data wirelessly which is specially designed for ultra-low power applications.

It can be con gured and operated through SPI Protocol.

It can transmit data at a rate up to 2 Mbps.

This module can use 125 different channels which makes possible to have network of 125 independently working modems
in one place.

Each channel has up to 6 addresses that means it can communicate with 6 other devices simultaneously.

The communication range is up to 100 meters and it specially designed for ultra-low power applications.

It operates on 1.9V to 3.6V power supply range, it takes 12mA of current during transmission mode which is even less than
a single LED.

 
Add Project Sign In
(/login#login)
(/) Platforms (/explore) Projects
(/projects) Contest (/contest2020)

The multi-receiver capacity of nRF24L01 is having up to 6 channels (pipes) of radio communication open in a receiving or
read mode simultaneously. This takes the form of a hub receiver (PRX - primary receiver) and up to six transmitter nodes
(PTX1 - PTX6 primary transmitters). In the above diagram, six reading (Data) pipes are opened in the primary receiver hub
(PRX). Each PTX node links to one of these pipes to use both in transmitting and receiving (TX toward the hub being the
primary direction of data ow, but the PTX nodes are RX capable as well).

Note: that the hub can also stop listening and act as a transmitter, transmitting (or writing) to the PTX nodes but this can
only be done one pipe or node at a time.

The addresses or pipes must have a distinct pattern of bytes, only the fth byte is entirely unique among all the pipes and
is known as the Least Signi cant Byte (LSB). Pipe 0 is assigned all ve bytes independently. Pipe 1 is also assigned all ve
bytes independently, but then the rst four bytes (MSBs) of pipe 1 also become the rst four bytes of pipes 2 - 5 if they
exist.

Pin diagram of nRF24L01

nRf24L01 module

Interfacing Diagram
Transmitter
Add Project Sign In
(/login#login)
(/) Platforms (/explore) Projects
(/projects) Contest (/contest2020)

Transmitter interfacing circuit

nRF24l01 Connections to Arduino UNO

nRF24L01 Arduino UNO

VCC 3.3V

GND GND

SCK D13

MISO D12

MOSI D11

CSN D7

CE D8

Receiver
Add Project Sign In
(/login#login)
(/) Platforms (/explore) Projects
(/projects) Contest (/contest2020)

Receiver interfacing circuit

nRF24l01 Connection to the Arduino UNO

nRF24L01 Arduino UNO

VCC 3.3V

GND GND

SCK D13

MISO D12

MOSI D11

CSN D7

CE D8

In this tutorial, we are going to control the brightness of LED connected to receiver Arduino using POT connected to
transmitter Arduino.

Example

Here, we will be using TMRh20’s RF24.h and Paul Stoffregen’s SPI.h library from GitHub.

Download RF24 library from here. (http://downloads.arduino.cc/libraries/github.com/TMRh20/RF24-1.2.0.zip)


Download SPI library from here. (https://github.com/PaulStoffregen/SPI)
Add Project Sign In
Extract these libraries and add it to the libraries folder path of Arduino IDE.
(/login#login)
(/) Platforms (/explore) Projects
For information about how to add a custom library to the Arduino IDE and use examples from it, refer Adding Library To Arduino IDE
(/projects) Contest (/contest2020)
(http://www.electronicwings.com/arduino/adding-a-new-library-to-arduino-ide-and-using-it) in the Basics section.

Once the library has been added to the Arduino IDE, open the IDE and open the example sketch you want from the list of examples
from the library added.

Code

Sketch for Transmitter 

//Adding Libraries

#include <SPI.h> /* to handle the communication interface with the modem*/


#include <nRF24L01.h> /* to handle this particular modem driver*/
#include <RF24.h> /* the library which helps us to control the radio modem*/

#de ne pot_pin A0 /*Variable pin of POT is to be connected to analog pin 0 i.e.A0*/


RF24 radio(7,8); /* Creating instance 'radio' ( CE , CSN ) CE -> D7 | CSN -> D8 */
const byte Address[6] = " 00009 " ; /* Address to which data to be transmitted*/

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(pot_pin,INPUT); /* Setting A0 (POT pin) as input*/
radio.begin (); /* Activate the modem*/
radio.openWritingPipe (Address); /* Sets the address of transmitter to which program will send the data *
}
void loop() {
// put your main code here, to run repeatedly:
radio.stopListening (); /* Setting modem in transmission mode*/
int value = analogRead(pot_pin); /*Reading analog value at pin A0 and storing in varible 'value'*/
int data = map( value , 0 , 1023 , 0 , 255 ); /* Convering the 10 bit value to 8 bit */
radio.write(&data, sizeof(data)); /* Sending data over NRF 24L01*/
Serial.print("Transmitting Data : ");
Serial.println(data); /* Printing POT value on serial monitor*/
}

Sketch for Receiver


//// Adding Libraries Add Project Sign In
#include <SPI.h> /* to handle the communication interface with the modem*/ (/login#login)
#include
(/) <nRF24L01.h> (/explore)
Platforms /* to handle Projects
this particular modem driver*/
(/projects)
#include <RF24.h> Contest (/contest2020)
/* the library which helps us to control the radio modem*/
#de ne led_pin 3 /* Connect LED anode to D3 (PWM pin) */

RF24 radio(7,8); /* Creating instance 'radio' ( CE , CSN ) CE -> D7 | CSN -> D8 */


const byte Address[6] = "00009"; /* Address from which data to be received */

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); /*Setting baudrate of Serial Port to 9600*/
radio.begin(); /* Activate the modem*/
radio.openReadingPipe(1, Address); /* Sets the address of receiver from which program will receive the data
}

void loop() {
// put your main code here, to run repeatedly:
radio.startListening(); /*Setting modem in Receiver mode*/
if (radio.available())
{
while (radio.available()) /* Loop until receiving valid data*/
{
int rx_data = 0 ; /* Variable to store received data */
radio.read(&rx_data, sizeof(rx_data));/* Read the received data and store in ' rx_data ' */
Serial.print("Received Data : ");
Serial.println(rx_data); /* Print received value on Serial Monitor */
analogWrite(led_pin , rx_data);/* Write received value to PWM pin 3 to which LED is connected */
}
}

else
{
Serial.println("Not Receiving !!!"); /* If not receiving valid data print " Not Receiving !!! " on Serial Mon
}
///// END OF LOOP //////
}

Functions Used in Accelerometer Sketch

1.      RF24 radio(7,8)

This function is used to set the CE and CSN pin connection for nRF24l01.
It connected CE pin to D7 and CSN pin to D8 of Arduino UNO.

2.      const byte Address[6] = " 00009 "

This function is used to de ne the address of nRF24l01.

3.      radio.begin ()

This function activates the modem.

4.      radio.write(&data, sizeof(data))  


This function is used to write or transmit the data.
Add Project Sign In
&data transmit the data presents at the address location of “data”.
sizeof(rx_data) automatically calculates the number of bytes in a “rx_data” string. (/login#login)
(/) Platforms (/explore) Projects
(/projects)
5.      radio.read(&rx_data, Contest (/contest2020)
sizeof(rx_data));

This function is used to read the received data.


&rx_data receive and store the data at the address location of “rx_data”.
sizeof(rx_data) automatically calculates the number of bytes in a “rx_data” string.

Serial Monitor Output

Transmitter

Receiver
Add Project Sign In
(/login#login)
(/) Platforms (/explore) Projects
(/projects) Contest (/contest2020)

Supporting Files

Source Code
nRF24L01 Library  Download    1001 (/download/attachment=Fri-07-18-12-47-37.RF24-1.2.0.zip)

Arduino SPI Library  Download    666 (/download/attachment=Fri-07-18-12-47-56.SPI-master.zip)

nRF24l01 Transmitter code  Download    930 (/download/attachment=Fri-07-18-12-49-58.nRF24l01_transmitter.zip)

nRF24l01 receiver code  Download    867 (/download/attachment=Fri-07-18-12-50-26.nRF24l01_receiver.zip)

Attached File
nRF24l01 datasheet  Download    1030 (/download/attachment=Fri-07-18-12-52-34.nRF24L01_datasheet.pdf)

Comments

Please login/signup to comment and reply.

ratnasravyaguntuku
(/users/ratnasravyaguntuku/profile)
2019-10-30 17:54:17

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
http://bigbelectronics.in/product.php?product=nrf2401-wireless-transceiver-module-arduino
Reply Like

sarvjitpatil009
(/users/sarvjitpatil009/profile)
2019-11-20 17:31:40

Hi, if you want to control heavy loads you need to use triac , scr or diac and provide ring pulse according to the data
received by nrf. You need to fund out suitable component among scr diac or triac.
Reply Like
elleko88
(/users/elleko88/profile) Add Project Sign In
2019-12-21 08:40:06
(/login#login)
I copied the Platforms
(/) code exactly.(/explore)
In the transmitter serial monitor I can see the analog sensor data perfectly. In the receiver serial
Projects
monitor, it is not receiving. Anything
(/projects) Contestin(/contest2020)
particular to check to troubleshoot this?
Reply Like

About Us (/about) Connect On:


Business Offering (/business-services) Facebook
Host Platform (/launch-platform)
(https://www.facebook.com/electronicwings)
Contact Us (/contactus)
LinkedIn
(https://www.linkedin.com/company/electronicwings/)
Youtube
(https://www.youtube.com/channel/UCNdqkukBtk4WhaBq
Instagram
(https://www.instagram.com/electronicwingscommunity/
hl=en)

Terms of Service (/terms-of-service)


ElectronicWings
Cookies Policy (/cookie-policy)
© 2020
Privacy Policy (/privacy-policy)

You might also like