'NRF24L01 modules not connecting - hardware or coding issue?

I am trying to transmit data from an ultrasonic sensor to an LCD screen using two NRF24L01 modules connected to two separate Arduino UNOs for a distance sensor for a bike. As I am relatively new to Arduino and initially did not know how to use the NRF24L01 module, I followed a tutorial from https://www.electroniclinic.com/nrf24l01-multiple-transmitters-and-single-receiver-for-sensor-monitoring-using-arduino/ , implemented it into my code, and it is not working. I ensured on multiple occasions that the wiring for the NRF24L01 is correct for the Arduino UNOs and attempted to change radio channels, and no use. For others from the website it appeared to be working, but for me it is not. Both programs compile just fine. Is there an issue with my code or is it possible that my NRF24L01 is nonfunctional?

Here is my code:

Transmitter:

#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(5, 4); // radio module, pins 5,4 for (CE, CSN)
RF24Network network(radio);

const uint16_t this_node = 01; //address of arduino
const uint16_t node00 = 00;

//setting up pins for each device
const int buzzerPin = 10;
const int aheadTrigPin = 9;
const int aheadEchoPin = 8;

//initialize variables for ultrasonic sensor and data
unsigned long data[3];
unsigned long aheadDistance;
unsigned long aheadDuration;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  network.begin(69, this_node);
  radio.setDataRate(RF24_2MBPS);

  pinMode(buzzerPin, OUTPUT);
  pinMode(aheadTrigPin, OUTPUT);
  pinMode(aheadEchoPin, INPUT);
}

void loop() {
  //clears the "trig" condition for ultrasonic sensor
  digitalWrite(aheadTrigPin, LOW);
  delayMicroseconds(2);

  //releases sound waves from ultrasonic sensor for 10 microseconds
  digitalWrite(aheadTrigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(aheadTrigPin, LOW);

  //reads "echo" pin to return sound wave travel time in microseconds
  aheadDuration = pulseIn(aheadEchoPin, HIGH);

  //calculating distance of ultrasonic sensor, in inches (distance = velocity * time)
  aheadDistance = (aheadDuration * 0.034 / 2) * 2.54;
  Serial.println(aheadDistance);
  
  //activates buzzer to alert rider if danger values are met
  if(aheadDistance <= 100) {
    tone(buzzerPin, 255);
  }
  else {
    noTone(buzzerPin);
  }
  //send data to main component
  network.update();
  data[0] = aheadDistance; 
  
  RF24NetworkHeader header(node00);
  bool ok = network.write(header, &data, sizeof(data)); // send data
  Serial.println("sent to NRF24 server");
  delay(200);
  }
  

The reason I am sending an array as the data is because I am currently working on having another transmitter to send data to a single receiver.

Receiver:


    #include <LiquidCrystal_I2C.h>
    #include <Wire.h>
    #include <RF24Network.h>
    #include <RF24Network_config.h>
    #include <Sync.h>
    #include <RF24.h>
    #include <SPI.h>
    
    //sets up timer for the LCD display to constantly run
    
    //sets up OLED screen
    LiquidCrystal_I2C display(0x27,20,4);
    
    RF24 radio (10, 9); // CE, CSN, defines new RF24 radio
    RF24Network network(radio);
    
    const uint64_t this_node = 00;
    
    //data variables that will be collected from other arduinos
    unsigned long data[3];
    unsigned long aheadDistance;
    unsigned long groundDistance;
    unsigned long backAheadDistance;
    
    void setup()
    {
      Serial.begin(9600);
      display.init(); // intialize lcd
      display.backlight(); //open backlight of lcd
      display.clear();
    
      //initialize starting screen
      display.setCursor(0, 0);
    
      //set up radio module (reciever)
      SPI.begin();
      radio.begin();
      network.begin(69, this_node);
      radio.setDataRate(RF24_2MBPS);
    
    }
    
    //method to update screen with current data values
    void displayDistance() {
      display.setCursor(0, 0);
      display.print("Bike Sensor");
      display.setCursor(0, 1);
      display.print("Front: ");
      display.print(aheadDistance);
      display.print(" in");
      display.setCursor(0, 2);
      display.print("Ground: ");
      display.print(groundDistance);
      display.print(" in");
      display.setCursor(0, 3);
      display.print("Back: ");
      display.print(backAheadDistance);
      display.print(" in");
      display.display();
    }
    
    void connectionLost() // activates when main component is unable to connect to others
    {
      display.clear();
      display.setCursor(0, 1);
      display.print("Connection");
      display.setCursor(0, 2);
      display.print("Lost");
      display.display();
    }
    
    void loop()
    {
      network.update();
      while(network.available()) {
        RF24NetworkHeader header;
        Serial.println("connection found");
        network.read(header, &data, sizeof(data));
        Serial.println("data recieved");
    
        if(header.from_node == 01) {
          backAheadDistance = data[0];
        }
        if(header.from_node == 02) {
          aheadDistance = data[1];
          groundDistance = data[2];
        }
        displayDistance();
        delay(100);
      }
      connectionLost();
      Serial.println("no connection found");
      delay(200);
    }
      //updates OLED screen and actually displays it on the module



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source