What is the nRF24L01 module and how it works with Arduino?

What is the nRF24L01 module and how it works with Arduino?

Hello and welcome back. In this tutorial, we will learn what is the nRF24L01 module and how to communicate between two Arduino boards using this module. For that, I used two nRF24L01 modules and two Arduino boards. If you also have these components, this tutorial will be especially important for you. This knowledge can also be used to build robots, drones, airplanes, RC cars, and RC boats. OK, let’s ahead.

What is the nRF24L01 module and how it works with Arduino?

What is the NRF24L01 module?

This is simply called a wireless communication module. Also, using this module we can communicate between two or more Arduino boards. Therefore, we can use this module to build things like robots, drones, airplanes, RC cars, RC boats. If you find a low-cost wireless communication module, I recommend this module. It can transmit and receive data within 100 meters of an open area.

How this module works

It operates on radio frequencies. Also, these modules are designed using the 2.4GHz frequency and use the SPI communication method to transmit and receive data between the Arduino board and the module.

Whis is SPI?

SPI is Serial Peripheral Interface. This is also a data transmission method that can transmit data at a maximum speed of 10MBps. Also, we used the I2C communication method in previous projects and only two Arduino PINs were required. But this SPI method requires 4 Arduino PINs.

The PIN diagram of this module

Okay, we will learn how this module works using the following example. For that, I used a project to control a servo motor using a potentiometer.

Let’s do this project step by step. The required components are given below.

Transmitter circuit

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, solder the capacitor to the module as shown below.

Step 3

Thirdly, attach the Arduino board and potentiometer to the breadboard as you like.

Step 4

Then, let’s connect these components. For that, use the circuit diagram below.

What is the nRF24L01 module and how it works with Arduino?

Step 5

Now, connect it to the computer.

Step 6

OK, now let’s creates the program for that. It is as follows.

RF24 library — Download

  • The program of this transmitter — Download
/*Transmitter program
 * https://srituhobby.com
 */
//Include libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//Include CE and CSN pins respectively
RF24 radio(9, 8);
//Create an address to identify the receiver
const byte address[6] = "00001";

void setup() {
//Begin the serial monitor and RF24 library
  Serial.begin(9600);
  radio.begin();
//set the adress
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
//Set that module as transmitter
  radio.stopListening();
}

void loop() {
//  const char text[] = "Hello World";
//  radio.write(&text, sizeof(text));
//  delay(1000);

    delay(5);
//Get the values from the potentiometer
    int value = analogRead(A0);
//Convert these values from 0 to 180
    value = map(value, 0, 1024, 0, 180);
//Print these values on the serial monitor
    Serial.println(value);
//Send these values to the receiver
    radio.write(&value, sizeof(value));
}

Step 7

Now, select the board and port. Then, upload this code to the Arduino board.

Receiver circuit

Step 1

Firstly, identify these components.

Step 2

Secondly, solder the capacitor to the module as shown below.

Step 3

Thirdly, connect these components to the Arduino board. For that, use the circuit diagram below.

What is the nRF24L01 module and how it works with Arduino?

Step 4

Now, connect it to the computer.

Step 5

Ok, let’s create the program for the receiver. It is as follows.

RF24 library — Download

  • The program of this transmitter — Download
/*Receiver program
 * https://srituhobby.com
 */
//Include libraries
#include <Servo.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//Create an object for the RF library and enter the CE and CSN pins, respectively
RF24 radio(9, 8);
//Create an object for the servo library
Servo servo;
//Create an address to identify the transmitter
const byte address[6] = "00001";

void setup() {
//Begin the serial monitor and RF24 library
  Serial.begin(9600);
  radio.begin();
//Include the servo motor pin
  servo.attach(3);
//Set the address
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_LOW);
//Set that module as a receiver
  radio.startListening();
}
void loop() {
  
  //  if (radio.available()) {
  //    char text[32] = "";
  //    radio.read(&text, sizeof(text));
  //    Serial.println(text);
  //  }

  delay(5);
//Check the transmit data using the IF condition
  if (radio.available()) {
    while (radio.available()) {
      int value = 0;
//Get the transmit values
      radio.read(&value, sizeof(value));
//Write these values on the servo
      servo.write(value);
//Print these values on the serial monitor
      Serial.println(value);
    }
  }
}

Step 6

Now, select board and port. After, upload this code to the Arduino board.

Ok, fine. Now we have a transmitter and a receiver. Then, power up both circuits and enjoy this project. The full video guide is below. We will meet in the next project.

What is the nRF24L01 module and how it works with Arduino?

Similar Posts

Leave a Reply

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