NRF24 Modules Not Working

I needed to get wireless communication for a project, so I tried to use the NRF24L01 and NRF24L01+PA+LNA modules. I connected them according to the schematic in this project hub article: https://projecthub.arduino.cc/tmekinyan/how-to-use-the-nrf24l01-module-with-arduino-813957

I also uploaded the code provided in the article

This is the code for the transmitter (NRF24L01+PA+LNA):

#include "SPI.h" 
#include "RF24.h" 
#include "nRF24L01.h" 
#define CE_PIN 9 
#define CSN_PIN 10 
#define INTERVAL_MS_TRANSMISSION 250 
RF24 radio(CE_PIN, CSN_PIN); 
const byte address[6] = "00001"; 
//NRF24L01 buffer limit is 32 bytes (max struct size) 
struct payload { 
	 byte data1; 
	 char data2; 
}; 
payload payload; 
void setup() 
{ 
	 Serial.begin(115200); 
	 radio.begin(); 
	 //Append ACK packet from the receiving radio back to the transmitting radio 
	 radio.setAutoAck(false); //(true|false) 
	 //Set the transmission datarate 
	 radio.setDataRate(RF24_250KBPS); //(RF24_250KBPS|RF24_1MBPS|RF24_2MBPS) 
	 //Greater level = more consumption = longer distance 
	 radio.setPALevel(RF24_PA_MAX); //(RF24_PA_MIN|RF24_PA_LOW|RF24_PA_HIGH|RF24_PA_MAX) 
	 //Default value is the maximum 32 bytes 
	 radio.setPayloadSize(sizeof(payload)); 
	 //Act as transmitter 
	 radio.openWritingPipe(address); 
	 radio.stopListening(); 
} 
void loop() 
{ 
	 payload.data1 = 123; 
	 payload.data2 = 'x'; 
	 radio.write(&payload, sizeof(payload)); 
	 Serial.print("Data1:"); 
	 Serial.println(payload.data1); 
	 Serial.print("Data2:"); 
	 Serial.println(payload.data2); 
	 Serial.println("Sent"); 
	 delay(INTERVAL_MS_TRANSMISSION); 
}

And this is the code for the receiver (NRF24L01):

#include "SPI.h" 
#include "RF24.h" 
#include "nRF24L01.h" 
#define CE_PIN 9 
#define CSN_PIN 10 
#define INTERVAL_MS_SIGNAL_LOST 1000 
#define INTERVAL_MS_SIGNAL_RETRY 250 
RF24 radio(CE_PIN, CSN_PIN); 
const byte address[6] = "00001"; 
//NRF24L01 buffer limit is 32 bytes (max struct size) 
struct payload { 
	 byte data1; 
	 char data2; 
}; 
payload payload; 
unsigned long lastSignalMillis = 0; 
void setup() 
{ 
	 Serial.begin(115200); 
	 radio.begin(); 
	 //Append ACK packet from the receiving radio back to the transmitting radio 
	 radio.setAutoAck(false); //(true|false) 
	 //Set the transmission datarate 
	 radio.setDataRate(RF24_250KBPS); //(RF24_250KBPS|RF24_1MBPS|RF24_2MBPS) 
	 //Greater level = more consumption = longer distance 
	 radio.setPALevel(RF24_PA_MIN); //(RF24_PA_MIN|RF24_PA_LOW|RF24_PA_HIGH|RF24_PA_MAX) 
	 //Default value is the maximum 32 bytes1 
	 radio.setPayloadSize(sizeof(payload)); 
	 //Act as receiver 
	 radio.openReadingPipe(0, address); 
	 radio.startListening(); 
} 
void loop() 
{ 
	 unsigned long currentMillis = millis(); 
	 if (radio.available() > 0) { 
	   radio.read(&payload, sizeof(payload)); 
	   Serial.println("Received"); 
	   Serial.print("Data1:"); 
	   Serial.println(payload.data1); 
	   Serial.print("Data2:"); 
	   Serial.println(payload.data2); 
	   lastSignalMillis = currentMillis; 
	 } 
	 if (currentMillis - lastSignalMillis > INTERVAL_MS_SIGNAL_LOST) { 
	   lostConnection(); 
	 } 
} 
void lostConnection() 
{ 
	 Serial.println("We have lost connection, preventing unwanted behavior"); 
	 delay(INTERVAL_MS_SIGNAL_RETRY); 
}

When it's working, the receiver code should be able to print the data values '123' and 'x' to the serial monitor. However, when I upload the codes and turn on the serial monitor, it either says that the connection has been lost or it prints the data values as '0' and some sort of square symbol.

Has anyone encountered a similar issue to this and have an idea of how to get this transmitter/receiver system to work?

I had success getting rf24 radios to work by carefully following Robin2's simple rf24 tutorial.

After Radio.begin() check the SPI connection, e.g.

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("Nano > NRF24L01 Receive text");
  radio.begin();
  if (radio.isChipConnected())
    Serial.println("Receiver NF24 connected to SPI");
  else {
    Serial.println("NF24 is NOT connected to SPI");
    while (1)
      ;

what host microcontrollers are you using?
what serial monitor output do you get?

Post an annotated schematic showing exactly how you have wired it. Be sure to show all connections and note any leads over 10"/25cm. The radios need to be at least 1 meter apart, preferable two or more.

Sorry for the late response, I haven't been able to test with my setup until today. I used your code to check the SPI connection and the serial monitor said that the NF24 is connected to SPI. I am using Nano boards for both the transmitter and the receiver.

Here is the schematic from the original article that I used to wire the modules:


None of the leads exceed 10". I also tried retesting my setup with the radios over 2 meters apart, but that did not seem to fix the issue.

I tried following the tutorial and even tried using its test code. I keep getting "TX failed" on the serial monitor for the transmitter module.

My Nanos do not look like your picture. I will look for the annotated schematic.

I also followed the excellent tutorial by Robin. What I found is that I get "tx failed", but the receiving radio still receives the data and successfully prints out to the terminal. You may want to check that. I'm still looking for a solid understanding of why the auto-ack isn't triggering.

There could be a number of reasons why the RF24 modules aren't working but are usually related to power supply issues. See Common Issues

Specifically see
here
and
here

You can also try calling radio.setPALevel(RF24_MIN,0); with the PA+LNA modules to lower the PA level and disable the LNA.

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