NRF24L01 Issues

I have tried several projects with the NRF24L01, and none have been successful. I tested them with Arduino, and the test showed that the devices themselves work. The connections are all good, but I cannot say without a shadow of a doubt it isn't the circuit. I recently replaced the "RF24" library that was installed with the TMRh20 one off GitHub. The code to one of the projects is below. It is a simple circuit to turn on a LED, that i got off Instructables. The transmitter circuit is on an Arduino Mega, and the receiver circuit is on an Arduino Uno. Hoping someone can point me in the right direction to figure out what and where the problem is.

Here is the transmitter code:

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

#define buttonPin1 3

int buttonState1 = 0;
RF24 radio(9, 8); // CE, CSN

const byte address[6] = "00002";

void setup() {
  pinMode(buttonPin1, INPUT_PULLUP);
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  buttonState1 = digitalRead(buttonPin1);

  if (buttonState1 == 1)
  {
    buttonState1 = 1;
  }
  else  if (buttonState1 == 0)
  {
    buttonState1 = 0;
  }

  Serial.print(buttonState1);
  radio.write(&buttonState1, sizeof(buttonState1));
}

And the receiver code:

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

#define led1 3


int buttonState = 0;

RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00002";

void setup() {
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  digitalWrite(led1, HIGH); 
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  delay(100);
}
void loop() {
  radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));
  Serial.println(buttonState);
  delay (100);

  if (buttonState == 1) {
    digitalWrite(led1, LOW);
  }
  else  if (buttonState == 0) {
    digitalWrite(led1, HIGH);
  }
}

In my experience and reading of problems on the forum, most failures when using these modules comes down to a lack of power

How are your RF modules powered ?

For example sketches that are known to work and a diagnostic connection test sketch take a look at

Simple nRF24L01+ 2.4GHz transceiver demo

1 Like

They are powered by the 3.3V pin on the Arduino

No wonder you have problems

Consider using an external source of power for the RF modules, not forgetting to provide a common GND connection

Note the use of a shield in the page that you linked to. The purpose of the shield is to ensure that the RF modules are powered correctly

hmm, i will give that a go and see how it works. oh, and i did include a 10uf capacitor with the power connections to the RF module. good thing i have a bench power supply lol. thank you

and thank you for the link!

You are sending the packets much too fast, ten per second should be enough.

What is this nonsense good for?

Why do you force loop to block?
Why do you use delay?

Oh, I forgot, the source is Destructables.

Hi, @archergal1285

Can you please post some images of your project?
So we can see your component layout and NRF units.

Thanks... Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.