nRF24L01's not communicating (1 way comm.) between 2 Arduino UNOs

I've looked over both my wiring and code quite a bit, double-checking previous forum posts for answers, etc. but can't quite get these modules to communicate. I'm attempting to take the output from a UT sensor and display it on an LCD screen connected to a second UNO. Right now the LCD screen prints "No Communication", which I programmed it to do if the radio.available() function returns false.

I have the UT sensor and transmitter code labeled "Transmitter" and the LCD and receiver code labeled "Reciever".

Transmitter:

#define echoPin 6 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 7 //attach pin D3 Arduino to pin Trig of HC-SR04
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
int returnDis = 7;
int disOut = 0;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  radio.begin();                  //Starting the Wireless communication
  radio.openWritingPipe(address); //Setting the address where we will send the data
  radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
  radio.stopListening();          //This sets the module as transmitter
  Serial.begin(9600);
}

void loop() {
  trigClear();
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)

  radio.write(&distance, sizeof(distance));
  delay(1000);
}

void trigClear() {
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
}

Reciever:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <LiquidCrystal.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int distance0 = 0;
int distance = 0;
int velocity;

void setup() {
  radio.begin();
  radio.openReadingPipe(0, address);   //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
  radio.startListening();
  lcd.begin(16, 2);
  Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
}

void loop() {
  lcd.clear();
  if (radio.available()) {
    radio.read(&distance, sizeof(distance));

    //if object found, print out new distance and find the velocity
    if (distance <= 400) {
      lcd.print("Distance: ");
      lcd.print(distance);
      lcd.print("cm");

      //print out velocity
      velocity = (abs(distance - distance0));
      lcd.setCursor(0, 1);
      lcd.print("Velocity: ");
      lcd.print(velocity);
      lcd.print("Cm/s");

      Serial.println("Distance ");
      Serial.println(distance);

      //set initial distance to new distance and delay by one second
      distance0 = distance;
      delay(1000);

    }
    else {
      lcd.print("No Object Found");
    }
  }
  else {
    lcd.print("No Communication");
    delay(1000);
  }
}

Below are my wiring schematics(please let me know if there's anything I can do to make them more clear)

Transmitter:
Screenshot (34)

Reciever:
Screenshot (35)

I have also used a test program to find that both nRF24L01 modules are not functioning as intended at all. Here's the test programs serial output:

Screenshot (31)

If someone could explain this portion to me in better detail I would appreciate it greatly. I'm new to wireless communication and it's confusing at best.

first thing to do is to check if your wiring works with known good programs. There are many examples on line or in the forum

See the troubleshooting section within the following URL -

It recommends that you place a small capacitor between Vcc & Gnd pins of the nRF24L01 pins.
I'm using small 100uf 16v capacitors on my nRF24L01's
I've had them working OK without any issues on ESP2866's, ESP32's, Nano 33 IoT's, Nano Every & Teensy 4.0

In addition, try out their example code to verify that your nRF24L01's are working correctly.

HTH?

I connected a HCSR-04 to one Uno and a 16x2 LCD to a second with each Uno having a rf24 radio attached. I uploaded your send and receive codes and ran them. I get distance and velocity displayed on the LCD so the codes seem to be working. That leads me to conclude that there is a hardware problem. That conclusion is somewhat confirmed by the output from the test codes.

Here are the "usual suspects" that I discovered while getting my radios to work:

If you read and, closely, follow Robin2's simple rf24 tutorial you should be able to get them working. That tutorial sure helped me. Run the CheckConnection.ino (look in reply #30) to verify the physical wiring between the radio module and its processor (Arduino).

Make sure the rf24 power supply can provide enough current. This is especially true for the high power (external antenna) modules. I use homemade adapters like these. They are powered by 5V and have a 3.3V regulator on the board. Robin2 also has suggested trying with a 2 AA cell battery pack.

If using the high powered radios make sure to separate them by a few meters. They may not work too close together. Try the lower power settings.
radio.setPALevel(RF24_PA_MIN);

Reset the radios by cycling power to them after uploading new code. I have found that to help. They do not reset with the Arduino.

Switch to 1MB data rate to catch the not so cloned clones.
radio.setDataRate( RF24_1MBPS );

1 Like

Your test output shows that the NRF is not communicating with the UNO,
so you have bad wiring or bad module.

Your code contains delays, which is a very bad idea.
You should not output anything if no packet is available,
this will be the case 99.999% of all times.

I've deleted all of the delays and made it to where I scale up the velocity, but it doesn't look very good on the LCD screen when it has to refresh so frequently. Is there a way I could make the LCD refresh slower without delays or just look better? Maybe by increasing resistance or something. It's not really necessary but it has been getting on my nerves.

The adapters you linked worked great, thank you so much! Took a while to come in though(you can credit my late response to that lol).

There are times when the connection drops and it stops transmitting but I'm sure I can chalk that up to either my school's wifi or not having the modules far enough away.

I'm not sure what you mean by "not so cloned clones" though. Are there data packets I'm currently not collecting or something? Again, sorry for my inexperience, trying my best to learn as quickly as possible.

That refers to there being genuine and clones (copies) of the rf24 modules on the market. Some copies are more faithful to the reference design than others, hence not so cloned (not so well copied) clones. Apparently some of the not so good copies work better at 1MHz data rate.

Most everyone checks the data to be displayed to see if it is the same as the last time and only display if the data is different.

Non-blocking timing tutorials:
Blink without delay().
Beginner's guide to millis().
Several things at a time.

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