Can anyone help me ... i am trying to connect ultrasonic and nfr24l01..

Transmit

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN   7
#define CSN_PIN  8


const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
int msg[1];
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);

void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input

Serial.begin(9600); // Starts the serial communication
  radio.begin();
  radio.openWritingPipe(pipe);
}
void loop() {
 
  
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
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;
// Prints the distance on the Serial Monitor

  radio.write(&distance,sizeof(distance));

}

Receive

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN   9
#define CSN_PIN 10
                         // Göndereceğimiz data değişkenini oluşturduk.
       
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}

void loop() {
  // put your main code here, to run repeatedly:
 if ( radio.available() )
  {
     int distance; // Fetch the data payload
      radio.read(&distance,sizeof(distance));
            Serial.print("X = ");
      Serial.println(distance);
    
    }
  }

You have not told us what the problem is so it is rather hard to help.

...R
Simple nRF24L01+ Tutorial

it doesn't send the distance and i dont know why . So i need your opinion about my code

I was rather hoping you would give a more extensive and detailed explanation including information on what does happen.

And when you use the word "distance" do you mean the distance between the two nRF24s or the distance measured by the ultrasonic device?

Is the Arduino that the ultrasonic device is connected to producing the correct distance measurement?

And I'm sure there is a lot more that you can tell us that will help to pinpoint the problem?

For example, what testing have you carried out?

Did you try my examples?

...R