I'm having a problem with the communication between two NRF24L01..!

Hello guys!

So… I am making my final project for this year in school.
I’ve decided to do something using two NRF24L01 modules, but I am having a big problem with the communication between the two of them, it just won’t work!

Here’s what I am trying to do for now, make a led turn on when a push button is pressed, the schematic for the circuits I am using, are those:

The codes I am using are:

Transmiter:

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

#define buttonPin1 A0

int buttonState1 = 0;

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

void setup() {
  pinMode(buttonPin1, INPUT);
  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));
}

Receiver:

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

int LED = A1;
int buttonState = 0;

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

void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
}

void loop() {
  radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));
  Serial.println(buttonState);

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

Also, I want to mention that the NRF24L01 I am using, look like this:

I’ve tested the push button with the serial monitor, it’s working and the led is turning on.
But when I try to turn on the led with the button, it just doesn’t work, nothing happens… what could it possibly be?

Please help me!! :confused:

In your transmitter code

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

This is completely useless. If buttonState1 is 1 you set it to 1? It

You may be transmitting so quickly the receiver gets overwhelmed. You should only be transmitting when you detect a change in the button. Look at the State Change Detection example in the IDE (File->examples-02.Digital->State Change Detection) and then only send a signal when something is different.

To test this theory out, you could simply introduce a delay() into your transmit code such that is only sends something every second or two.

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

If you are using the high-power nRF24s (with the external antenna) make sure there is sufficient distance between the two nRF24s so that the signal does not overwhelm the receiver - try 3 metres separation. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.

...R

Robin2:
Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

If you are using the high-power nRF24s (with the external antenna) make sure there is sufficient distance between the two nRF24s so that the signal does not overwhelm the receiver - try 3 metres separation. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.

...R

Been trying everything from your post, nothing is working...

Here is what I got from the test of communication between the Arduino (I am using two Arduino UNO for the tests) and the NRF24L01:

First Arduino:

Second Arduino:

I see a bunch of 0x00 and 0xff...

I want to mention one thing also, I think that I've connected the NR14L01 modules to the 5V pin on the Arduino Nano once, could that possibly made the modules faulty?

And thanks for your help! :smiley:

Your second connection test seems to be working properly but the first one is not. The usual problem is incorrect connections or loose connections.

What happens if you use the nRF24 from the second test with the Uno from the first test?

If you are still having problems please make two pencil drawings showing how YOU have everything connected and post photos of the drawings. The business of making the drawing can often show up errors.

...R