Receiving '0' value in NRF24l01 receiver, whereas transmitter sending different int values. Need urgent help please!

I am using an uno and a joystick shield on the transmitter side while mega and l298n motor driver on the receiver side.
The codes are as follows:

Transmitter code:

#include <SPI.h>
#include "RF24.h"

int x_axis = A1;
int y_axis = A2;
int xvalue;
int yvalue;
int data[2];

RF24 radio(9,10);
const uint64_t pipe=0xE8E8F0F0E1LL;

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

void loop() {{
xvalue=analogRead(x_axis);
xvalue=map(xvalue,0,1023,0,127);
data[0]=xvalue;
radio.write(data,1);
}
{
yvalue=analogRead(y_axis);
yvalue=map(yvalue,0,1023,128,255);
data[0]=yvalue;
radio.write(data,1);
}
Serial.println(xvalue);
Serial.println(yvalue);
}

Receiver code:

#include <SPI.h>
#include "RF24.h"

const int motorforward = A1;
const int motorbackward = A2;
const int motorleft = A3;
const int motorright = A4;

int data[2];
RF24 radio(9,10); // CE,CSN:
const uint64_t pipe=0xE8E8F0F0E1LL;

void setup() {
  pinMode (motorforward,OUTPUT);
  pinMode (motorbackward,OUTPUT);
  pinMode (motorleft,OUTPUT);
  pinMode (motorright,OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}

void loop() {
  if(radio.available())
    {
      Serial.println("RA");
    }
    else{
      Serial.println("NA");
    }
    delay(1000);
  if(radio.available()){
    radio.read(data,1);
    Serial.println("rcvd");
    Serial.println(data[0]);
     if(data[0]>1 && data[0]<51){
      digitalWrite(motorforward,LOW);
      digitalWrite(motorbackward,HIGH);
    }
      if(data[0]>77 && data[0]<128){
      digitalWrite(motorforward,HIGH);
      digitalWrite(motorbackward,LOW);
    }
        if(data[0]>52 && data[0]<76){
      digitalWrite(motorforward,LOW);
      digitalWrite(motorbackward,LOW);
    }
  
  
     if(data[0]>129 && data[0]<179){
      digitalWrite(motorleft,HIGH);
      digitalWrite(motorright,LOW);
    }
      if(data[0]>205 && data[0]<255){
      digitalWrite(motorleft,LOW);
      digitalWrite(motorright,HIGH);
    }
       if(data[0]>180 && data[0]<204){
      digitalWrite(motorleft,LOW);
      digitalWrite(motorright,LOW);
    }
   }
}

Transmitter Serial monitor img: https://postimg.cc/0bBM27QZ

Receiver Serial Monitor Img: https://postimg.cc/hJh7SfDV

I have tried changing the mega with uno, replaced the jumper/rainbow cables, but the problem still persists.

Please do not post images of code or program output. Copy and paste into a post. We do not like to have to go to other sites to get information.

Please post schematics of the radio connections, transmitter and receiver. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

The SPI pins are on different pin numbers on a Mega than an Uno.

If you read and, closely, follow Robin2's simple rf24 tutorial you should be able to get them working. That tutorial sure helped me. The code in the examples has been proven to work many many times. If it does not work for you, there is likely a hardware problem.

Run the CheckConnection.ino (look in reply #30 in the tutorial) to verify the physical wiring between the radio module and its processor (Arduino).

It is very important that you get the 3.3V supply to the radio modules to supply 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.

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 );

Also for some clones, change TMRh20's RF24.cpp line 44
_SPI.setClockDivider(SPI_CLOCK_DIV2);
Into
_SPI.setClockDivider(SPI_CLOCK_DIV4);

Have a look at the common problems page.

You may be having a 3V3 power problem.

Try a 10uF capacitor on the modules 3V3 to GND.

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