Wireless communication with NRF24L01+ not working

Hi all,
I am trying to make a program to wirelessly send data (joystick) from a nano to an uno using a pair of NRF24L01 chips. But the program I made does not work, and I don't know what the problem is, I am sure it is a problem with my code because other programs using this RF chip are working flawlessly. I looked for hours but I could not find the problem, so I tought it would be a good idea to ask it here.
Here are the programs I am using:

Transmitter:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int data[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

int JoyX = A0;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
}

void loop(void){
int Xvalue = map(analogRead(JoyX), 0, 1023, 0, 255);

Serial.println(Xvalue);
delay(200);

if ((Xvalue > 135) || (Xvalue < 126)){
  data[0] = Xvalue;
  radio.write(data, 1);
  Serial.println("\nData Sent!");
  }
}

Receiver:

#include<SPI.h>
#include<RF24.h>
#include <RF24.h>
int data[1];
RF24 radio (9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;


void setup() {
  Serial.begin(9600);

  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();
}

void loop() {
  if (radio.available())
  {
    Serial.println("Data received!");
    
    radio.read(data, sizeof(data));
    Serial.println(data[1]);
    Serial.println("\n");
    delay(200);  
  }
  else {
    Serial.println("No data");
    delay(200);
  }
}

Thanks to everyone willing to help me out with this!

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

int data[1];

  Serial.println(data[1]);

Printing a value behind the array is not very related to the received packet.

So if "does not work" means just unexpected output, the above could be the culprit.

BTW sending only the first byte of the int is at least confusing,
if your values exceed 256 you will start loosing data.

radio.write(data, 1);

You should use

radio.write(data, sizeof(data));

like you did on the receiving side.

P.S. there is absolutely no need (and place) for any delay() on the receiver side.

Thanks for your answer!
By not working in means it always shows "No data" on the monitor, wich means it does not receive any data from the RF module.
And I placed a delay so it would be asier to read the values on the monitor.

Here's a picture of the 2 serial monitors while the program is running:

Also I'm sure it's not hardware related because when I use another program, everything is working fine.

And here's the program that does work if this might help.
Transmitter:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}

void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 111;
radio.write(msg, 1);}}

Receiver:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}

void loop(void){
if (radio.available()) {
bool done = false;
while (!done) {
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111) {
  delay(10);digitalWrite(LED1, HIGH);
  }
else {
  digitalWrite(LED1, LOW);
  }
delay(10);
  }
}
else{Serial.println("No radio available");}}

RF24_PA_MAX can be problematic if the modules are near to each other.

Ian_99:
And I placed a delay so it would be asier to read the values on the monitor.

That "no data" output is as useful as a doorbell that rings when nobody is there,
printing a message when there was no packet in the last second would make more sense.

Why don't you care what the sending stations radio.write() returncode is?

Whandall:
Why don't you care what the sending stations radio.write() returncode is?

What do you mean by "returncode"? The command that shows "data sent" on the monitor? I know, I still have to learn a lot about programming.

And for the "no data" output, I know it is quite useless, but it shouldn't be causing this program to stop working.

Read the fine manual.

http://tmrh20.github.io/RF24/classRF24.html#a4cd4c198a47704db20b6b5cf0731cd58

This is from the library I use and recommend.

The format of addresses you use could mean that you are using an outdated library.

Ian_99:
By not working in means it always shows "No data" on the monitor,

Have you studied my tutorial and tried its examples?

...R

If you are going to work with a pair of transceivers you need to make things easy for yourself.

This means start from a known working example.

If that doesnt work check that the transmit side is transmitting (this is easy, just monitor
the supply current - it will jump up during a packet transmit). Use a low baud rate for
this testing so the transmit time is reasonably long.

Check antennas are right sort, actually connected, etc.

Check the two units are not too close to each other, separate by several feet. Too close can
fail just as much as too far. Use minimum transmit power setting if both units sat on same bench.

That should get you to a working state, if the hardware is working and the example code isn't bogus.

Then you only ever make one change at a time and re-test before moving on...

Using a source code versioning system is useful, you can then go back easily to working versions, but
really if you made several changes without re-testing, you already made things hard for yourself.