NRF24L01 and Serial Port

I am trying to use an arduino uno with 1 NRF24L01 module to send what is received through the serial port to a seperate arduino uno with a second NRF24L01. What happens with the following code is that RelaySwitch[0] is correct with the corresponding 48 or 49. Now when I serial.println the RelaySwitch[1] it prints 2569 and only 2569. On the receiver it just prints no radio available. I can’t figure this out. The end objective is to create a UI with C# and on the other end I want to change the state of a Relay.

Transmit Code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10
int incomingByte;

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe


/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int RelaySwitch[1];  // 1 element array holding Joystick readings

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if (Serial.available() > 0){
  incomingByte = Serial.read();
  RelaySwitch[0] = incomingByte;

  radio.write( RelaySwitch, sizeof(RelaySwitch) );
    Serial.println(RelaySwitch[1]);
  }
}//--(end main loop )---

Receive code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe


/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int RelaySwitch[1];  // 1 element array holding Joystick readings

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( RelaySwitch, sizeof(RelaySwitch) );
      Serial.println(RelaySwitch[0]);
    }
  }
  else
  {    
      Serial.println("No radio available");
  }

}//--(end main loop )---
int RelaySwitch[1];  // 1 element array holding Joystick readings

A one element array just looks stupid. You do NOT need an array to hold one element.

    Serial.println(RelaySwitch[1]);

Why are you printing beyond the end of the array?

I was using the Serial.println to see what was being sent to the other radio. It was my attempt to troubleshoot.

pickel98:
I was using the Serial.println to see what was being sent to the other radio. It was my attempt to troubleshoot.

You send one thing (the value in [ 0 ]). You print something else (the value in the non-existant location [ 1 ]).

That doesn't seem like it is of much value in trouble shooting.

How far apart are your radios? I have solved similar problems by reducing transmitter power,
if they are close together (< 20 ft.) the receiver can be swamped.
Insert in setup().

void setup ()
{
if(!nrf24.setRF(RH_NRF24::DataRate250kbps,RH_NRF24::TransmitPowerm18dBm))
    Serial.println("setRF failed");

This sets power to minimum, the dataRate on receiver must match:
DataRate250kbps, DataRate1000Mbps or DataRate2000Mbps

so in the receiver setup I would use something like this? Or can I use the same code as yours?

void setup(){
if(!nrf24.setRF(RH_NRF24::DataRate250kbps,RH_NRF24::ReceivePowerm18dBm))
    Serial.println("setRF failed");
}

OOPS! Sorry for delay in replying.
No you only need to reduce power on transmitter but make sure the data rate is the same on both ends, which ever you choose from 250kbps or 1Mbps or 2Mbps.
Leave your receiver code as is.

I think I gave you code from the wrong library, put your code back to original and make your transmitter setup code like this:

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  radio.setPALevel( RF24_PA_MIN );
}//--(end setup )---

Transmitter end only!

That would be the first time I have ever seen someone complain about the power of their radio.

As for the OP's problem:

if ( radio.available() )
{
// Read the data payload until we've received everything
bool done = false;
while (!done)
{
// Fetch the data payload
done = radio.read( RelaySwitch, sizeof(RelaySwitch) );
Serial.println(RelaySwitch[0]);
}
}
else
{
Serial.println("No radio available");
}

There are several problems with this.

It is likely that sizeof is not doing what you expect here. There are a lot of issues with sizeof, I manage to get by not using it, I don't know why they teach beginners to use it, with all the mistakes they make.

The other problem is that your loop( ) function is going to be running thousands of times a minute, and even if your radio communication is actually working, most of the time there will be no radio transmission and your serial monitor will be swamped with more messages that "no radio available", than it will be able to handle.