Skip to content Skip to sidebar Skip to footer

nRF24L01 Arduino Tutorial Basic Code & Schematic

nRF24L01 Arduino Tutorial 

nRF24L01 Arduino Tutorial -  Various electronic devices are made as small as possible for portable needs. One such communication device is the nRF24L01. 

This device works on the ISM (Industrial, Scientific and Medical) 2.4 – 2.5 GHz frequency. The nRF24L01 chip made by Nordic Semiconductor has a data rate specification of 1 or 2Mbps. This means that by using this chip you can transmit data of 1 mega (1,000,000) or 2 mega (2,000,000) data bits per second.

This nRF24L01 chip can be used as a transceiver, receiver or bi-directional (transceiver and receiver simultaneously). This nRF24L01 wireless chip can communicate with 125 other nRF24L01 devices in one location.

nRF24L01 Arduino Tutorial Basic Code & Schematic

How can we make this nRF24L01 device able to communicate with that large number? does it not confer data with each other when sent? 

The answer is no, because each device must be given an Address (pipe) or an address first.

Based on the datasheet provided, this chip uses a power supply of 1.9 – 3.6 volts, but in addition to the power supply pins such as the data pin, a voltage of 5 volts can be given.

This chip requires a current of 11.3 mA when sending data and 12.3 mA when receiving data.

For Arduino nRF24L01 communication, this chip uses the SPI (Serial Peripheral Interface) protocol. The SPI data transmission speed on this chip is 0 to 8Mbps.



Arduino nRF24L01 Circuit

Now we will try this module by setting the module that is connected to our arduino set as the sender, while the arduino pro mini on the right is the receiver.

We will create a program that can send this word "Hello Word" for one second. If the receiver receives data from the sender, the receiver will display the data to the Arduino serial monitor.

nRF24L01 Arduino Tutorial Basic Code & Schematic

Arduino nRF24L01 Library

This program requires a library called RF24. Please download below.

Once downloaded, enter the library into the Arduino IDE and create two programs, namely the sender and receiver program with the following code: 


Arduino nRF24l01 Code 

Transmitter:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // 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[] = "Hello World";
radio.write(&text, sizeof(text));
delay(1000);
}


Receiver:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // 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[] = "Hello World";
radio.write(&text, sizeof(text));
delay(1000);
}

If you want to see more of this chip, please download the datasheet below.

Source: hamboelektronik.com

5 comments for "nRF24L01 Arduino Tutorial Basic Code & Schematic"

  1. i have use your coding to run in my two arduino mega (arduino mega 2560 - arduino mega 2560) and doesn't work

    i have set CE and CSN in Digital Pin 9 and 10

    ReplyDelete
    Replies
    1. Hi Hanif,

      Have you used the SPI connection correctly?
      At ATmega328 are MOSI (11), MISO (12), SCK (13).
      At ATmega2560 are MOSI (51), MISO (50), SCK (52).

      More information here: https://www.arduino.cc/en/reference/SPI

      Thanks.

      Delete
  2. izin tanya bang, di transmiter programnya "radio.openWritingPipe(address)" tapi pas di receiver "radio.openReadingPipe(0, address)" ada angka 0 nya sebelum adress, kenapa bang?

    ReplyDelete
    Replies
    1. Bisa baca disini bang : https://tmrh20.github.io/RF24/classRF24.html#a9edc910ccc1ffcff56814b08faca5535

      Delete
    2. Angka 0 itu urutan ke-1 alamat pipe nya bang. Karena kita hanya menentukan satu alamat pipe saja "00001".

      Misalnya kita ingin menerima data dari dua pipe, maka kita menggunakan alamat pipe yang berbeda:
      const byte address [ ][6] = {"00001", "00002"};

      Untuk membacanya:
      radio.openReadingPipe(0, address);
      radio.openReadingPipe(1, address);

      Jadi, 0 dan 1 sebelum address adalah urutan alamat pipe dalam array.
      Semoga ini bisa membantu.

      Delete