How to use the NRF24L01 2.4GHz wireless module with an Arduino

--Resource --
--Resource --

NRF24L01

The nRF24L01 is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the 2.4GHz ISM (Industrial, Scientific and Medical) band. With peak RX/TX currents lower than 14mA, a sub μA power down mode, advanced power management, and a 1.9 to 3.6V supply range, the nRF24L01 provides a true ULP solution enabling months to years of battery lifetime when running on coin cells or AA/AAA batteries .

nRF24L01 is a single chip radio transceiver for the world wide 2.4 - 2.5 GHz ISM band. The transceiver consists of a fully integrated frequency synthesizer, a power amplifier, a crystal oscillator, a demodulator, modulator and Enhanced ShockBurst™ protocol engine. Output power, frequency channels, and protocol setup are easily programmable through a SPI interface. Current consumption is very low, only 9.0mA at an output power of -6dBm and 12.3mA in RX mode. Built-in Power Down and Standby modes makes power saving easily realizable.

NRF24L01 Connections

Setup Library

For coding arduino first we need some library files so follow the steps given below :
1. Download the ZIP file (library file zip folder from attachments ).
3. Unpack the ZIP file.
4. Go to arduino library folder
5. And paste both the folders named " nFR24L01" and "RF24" into it.

Download Library - Click here

Code for Receiver



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

int msg[1];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void) {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  pinMode(LED1, OUTPUT);
}

void loop(void) {
  if (radio.available()) {
    bool done = false;
    while (!done) {
      done = radio.read(msg, 1);
      Serial.println(msg[0]);
      if (msg[0] == 111) {
        digitalWrite(LED1, HIGH);
      }
      else {
        digitalWrite(LED1, LOW);
      }
    }
  }
  else {
    Serial.println("No radio available");
  }
}

Code for Transmitter



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

int msg[1];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;
int flag_click = 0;
int indicator_led = 4;


void setup(void) {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(indicator_led, OUTPUT);
  digitalWrite(SW1, HIGH);
}

void loop(void) {
  bool rslt;

  if (digitalRead(SW1) == LOW) {
    if (flag_click == 0) {
      flag_click = 1;
    }
    else if (flag_click == 1) {
      flag_click = 0;

    }

    if (flag_click == 1) {
      msg[0] = 111;
      rslt = radio.write(msg, 1);
      rslt = radio.write(msg, 1);
      rslt = radio.write(msg, 1);
      delay(100);
      if (rslt) {
        digitalWrite(indicator_led, HIGH);
      }
    } else {
      msg[0] = 000;
      rslt = radio.write(msg, 1);
      rslt = radio.write(msg, 1);
      rslt = radio.write(msg, 1);
      delay(100);
      if (rslt) {
        digitalWrite(indicator_led, LOW);
      }
    }
  }
}