Arnov Sharma
Published © MIT

NRF24 Hookup Guide

"how to hook NRF24 Modules with an Arduino Correctly without killing the module"

BeginnerFull instructions provided36 minutes18,480
NRF24 Hookup Guide

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×2
nRF24 Module (Generic)
×2
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

TRANSMITTER

the Button can be removed or added for level 2 part!

Reciever

LED can be added or Removed for level 2 part!

Code

CODE FOR TRANSMITTER Level1

C/C++
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


RF24 radio(7, 8);  // CE, CSN


const byte address[6] = "00001";

void setup()
{
  radio.begin();
  

  radio.openWritingPipe(address);
  

  radio.stopListening();
}
void loop()
{
  
  const char text[] = "HOW YOU DOIN"; //message
  radio.write(&text, sizeof(text));
  
  delay(1000);
}

CODE FOR RECIEVER Level2

C/C++
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


RF24 radio(7, 8);  // CE, CSN


const byte address[6] = "00001";

void setup()
{
  while (!Serial);
    Serial.begin(9600);
  
  radio.begin();
  
  
  radio.openReadingPipe(0, address);
  
  
  radio.startListening();
}

void loop()
{
  
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

Transmitter Level2

C/C++
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led 2
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
boolean buttonState = 0;
void setup() {
  pinMode(2, OUTPUT);
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00002
  radio.openReadingPipe(1, addresses[0]); // 00001
  radio.setPALevel(RF24_PA_MIN);
}
void loop() {
  delay(5);
  radio.stopListening();
  int potValue = analogRead(A0);
  int angleValue = map(potValue, 0, 1023, 0, 180);
  radio.write(&angleValue, sizeof(angleValue));
  delay(5);
  radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));
  if (buttonState == HIGH) {
    digitalWrite(led, HIGH);
  }
  else {
    digitalWrite(led, LOW);
  }
}

Receiver Level 2

C/C++
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define button 2
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
Servo myServo;
boolean buttonState = 0;
void setup() {
  pinMode(button, INPUT);
  myServo.attach(5);
  radio.begin();
  radio.openWritingPipe(addresses[0]); // 00001
  radio.openReadingPipe(1, addresses[1]); // 00002
  radio.setPALevel(RF24_PA_MIN);
}
void loop() {
  delay(5);
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {
      int angleV = 0;
      radio.read(&angleV, sizeof(angleV));
      myServo.write(angleV);
    }
    delay(5);
    radio.stopListening();
    buttonState = digitalRead(button);
    radio.write(&buttonState, sizeof(buttonState));
  }
}

Credits

Arnov Sharma

Arnov Sharma

305 projects β€’ 306 followers
Just your average MAKER

Comments