Communicating between two arduinos using nrf24lo1 radio modules

I am using the NRF24L01 modules compatible with arduino and following a tutorial on how to communicate using them between two distinct arduinos, a transmitter and a receiver. I have programmed both a transmitter and a receiver as instructed and have all the wiring correct. However, the message "hello world" is not reaching the receiver, either because it isn't being sent or it isn't being seen. These modules are right next to eachother, so connection shouldn't be a problem.

Here is the code for the transmitter:

//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//create an RF24 object
RF24 radio(9, 8);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";
int led = 50; 
int swit = 0; 
int t = 0; 
void setup()
{
  radio.begin();
  
  //set the address
  radio.openWritingPipe(address);
  
  //Set module as transmitter
  radio.stopListening();
  pinMode(led,OUTPUT);
  t = millis();
  Serial.begin(9600);
}
void loop()
{
 
    //Send message to receiver
    flash();
    const char text[] = "Hello World";
    radio.write(&text, sizeof(text));
    
    t = millis(); 
    Serial.print("Message transmitted: " + String(text)+"\n");
    delay(1000);
  
  
}
void flash(){
  if(swit==0){
    digitalWrite(led,HIGH);
    swit+=1;
    swit%=2;
  }else{
    digitalWrite(led,LOW);
    swit+=1;
    swit%=2;
  }
}

Here is the code for the reciever:

//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//create an RF24 object
RF24 radio(9, 8);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";
int t = 0; 
int led = 50; 
int swit = 0; 
void setup()
{
  while (!Serial);
    Serial.begin(9600);
  
  radio.begin();
  pinMode(led,OUTPUT); 
  //set the address
  radio.openReadingPipe(0, address);
  
  //Set module as receiver
  radio.startListening();
  t=millis();
}

void loop()
{
 
  if(millis()-t>1000){
    flash();
    t = millis(); 
  }
  //Read the data if available in buffer
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.println(text);
    
   
  }
}
void flash(){

  if(swit==0){
    digitalWrite(led,HIGH);
    swit+=1;
    swit%=2;

  }else{
    digitalWrite(led,LOW);
    swit+=1;
    swit%=2;

  }
}

If you are having problems with nRF24L01 modules, then your starting point is this forum discussion:

Once you have your modules wired up, run the checkconnection sketch in post #30 of the above discussion.

+1 for Robin2's simple rf24 tutorial recommended by @markd833. It helped me a lot. It was the best of all the tutorials that i tried when first working with those units.

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