nrf24l01 wireless help..

I am working on getting an uno(transmitter) to send multiple button states to a mega(reciever) to activate relays. This is my first time messing with any arduino so I have been scratching along trying to get this working. This is what i have come up with so far. The loop on the uno(transmitter) wont run unless I quote out 2 of the radio.write functions and leave just one remaining but when I do that and jump the pin to make it high the mega changes all 3 states to high instead of just one.. Any help would be appreciated...

Transmitter code

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

#define bin1 2
#define bin2 3
#define bin3 4

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
boolean bin1state = 0;
boolean bin2state = 0;
boolean bin3state = 0;

void setup() {
 pinMode(bin1, INPUT);
 pinMode(bin2, INPUT);
 pinMode(bin3, INPUT);
 radio.begin();
 radio.setChannel(120);
 radio.openWritingPipe(addresses[0]); // 00002
 radio.openReadingPipe(1, addresses[1]); // 00001
 radio.setPALevel(RF24_PA_MIN);
 Serial.begin(9600);
 radio.stopListening();
 Serial.println("setup finished");
}

void loop() {
 delay(500);
 Serial.println("loop begun");
   bin1state = digitalRead(bin1);
   radio.write(&bin1state, sizeof(bin1state));
   bin2state = digitalRead(bin2);
   radio.write(&bin2state, sizeof(bin2state));   <------If i quoute out this
   bin3state = digitalRead(bin3);
   radio.write(&bin3state, sizeof(bin3state));   <------ and this the code will loop like it should but i need
   Serial.println("Loop finish");                                  these states sent also.
 }

Reciever Code

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

#define bin1led 22
#define bin2led 23
#define bin3led 24

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

boolean bin1state = 0;
boolean bin2state = 0;
boolean bin3state = 0;

void setup() {
 pinMode(bin1led, OUTPUT);
 radio.begin();
 radio.setChannel(120);
 radio.openWritingPipe(addresses[1]); // 00001
 radio.openReadingPipe(1, addresses[0]); // 00002
 radio.setPALevel(RF24_PA_MIN);
 Serial.begin(9600);
}

void loop() {
 delay(5);
 radio.startListening();
 while (!radio.available());
 radio.read(&bin1state, sizeof(bin1state));
 if (bin1state == HIGH) {
   digitalWrite(bin1led, HIGH);
   Serial.println("bin1 high");
 }
 else {
   digitalWrite(bin1led, LOW);
   Serial.println("bin1 low");
 }
 while (!radio.available());
 radio.read(&bin2state, sizeof(bin2state));
 if (bin2state == HIGH) {
   digitalWrite(bin2led, HIGH);
   Serial.println("bin2 high");
 }
 else {
   digitalWrite(bin2led, LOW);
   Serial.println("bin2 low");
 }
 while (!radio.available());
 radio.read(&bin3state, sizeof(bin3state));
 if (bin3state == HIGH) {
   digitalWrite(bin3led, HIGH);
   Serial.println("bin3 high");
 }
 else {
   digitalWrite(bin3led, LOW);
   Serial.println("bin3 low");
 }
 Serial.println("loop finished");
}

Have a look at this Simple nRF24L01+ Tutorial - the examples do work.

And, to make it easier for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R

I think I read around and looked at enough examples to figured it out. i Have it running now. There is a bit of delay but thats not a big deal. This is what I ended up with.

Reciever

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

int bins[3] = {0,0,0};


#define bin1led 22
#define bin2led 23
#define bin3led 24

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

void setup() {
 
 
  pinMode(bin1led, OUTPUT);
  pinMode(bin2led, OUTPUT);
  pinMode(bin3led, OUTPUT);
  radio.begin();
  radio.setChannel(120);
  radio.openWritingPipe(addresses[1]); // 00001
  radio.openReadingPipe(1, addresses[0]); // 00002
  radio.setPALevel(RF24_PA_MIN);
  Serial.begin(9600);
  Serial.println("setup finished");
}

void loop() {
  delay(5);
  radio.startListening();
  while (!radio.available());
  radio.read(bins, sizeof(bins));
  if (bins[0] == 1)  {
    digitalWrite(bin1led, HIGH);
    Serial.println("bin1 high");
  }
  else {
    digitalWrite(bin1led, LOW);
    Serial.println("bin1 low");
  }
  if (bins[1] == 1) {
    digitalWrite(bin2led, HIGH);
    Serial.println("bin2 high");
  }
  else {
    digitalWrite(bin2led, LOW);
    Serial.println("bin2 low");
  }
  if (bins[2] == 1) {
    digitalWrite(bin3led, HIGH);
    Serial.println("bin3 high");
  }
  else {
    digitalWrite(bin3led, LOW);
    Serial.println("bin3 low");
  }
  Serial.println("loop finished");
}

Transmitter

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

#define bin1 2
#define bin2 3
#define bin3 4

int bins[3] = {0,0,0};

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

void setup() {
  pinMode (bin1, INPUT);
  pinMode (bin2, INPUT);
  pinMode (bin3, INPUT);
  radio.begin();
  radio.setChannel(120);
  radio.openWritingPipe(addresses[0]); // 00002
  radio.openReadingPipe(1, addresses[1]); // 00001
  radio.setPALevel(RF24_PA_MIN);
  Serial.begin(9600);
  Serial.println("setup finished");
  radio.stopListening();
}

void loop() {
  delay(500);
  if (digitalRead(bin1) == HIGH){
    bins[0] = 1;
  }
  else {
    bins[0] = 0;
  }
  if (digitalRead(bin2) == HIGH){
    bins[1] = 1;
  }
  else {
    bins[1] = 0;
  }
  if (digitalRead(bin3) == HIGH){
    bins[2] = 1;
  }
  else {
    bins[2] = 0;
  }
  
  radio.write(bins, sizeof(bins));
   
    Serial.println("Data Sent");
  }

I think it will work better like this

Rx

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

const byte bin1led = 22;
const byte bin2led = 23;
const byte bin3led = 24;
byte addresses[][6] = {"00001", "00002"};

RF24 radio(7, 8); // CE, CSN

byte bins[3];

void setup() {
  pinMode(bin1led, OUTPUT);
  pinMode(bin2led, OUTPUT);
  pinMode(bin3led, OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.setChannel(120);
  radio.openWritingPipe(addresses[1]);
  radio.openReadingPipe(1, addresses[0]);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Serial.println(F("setup finished"));
}

void loop() {
  if (radio.available()) {
    radio.read(bins, sizeof(bins));
    if (bins[0] == 1)  {
      digitalWrite(bin1led, HIGH);
      Serial.println(F("bin1 high"));
    }
    else {
      digitalWrite(bin1led, LOW);
      Serial.println(F("bin1 low"));
    }
    if (bins[1] == 1) {
      digitalWrite(bin2led, HIGH);
      Serial.println(F("bin2 high"));
    }
    else {
      digitalWrite(bin2led, LOW);
      Serial.println(F("bin2 low"));
    }
    if (bins[2] == 1) {
      digitalWrite(bin3led, HIGH);
      Serial.println(F("bin3 high"));
    }
    else {
      digitalWrite(bin3led, LOW);
      Serial.println(F("bin3 low"));
    }
    Serial.println(F("loop finished"));
  }
}

Tx

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

const byte bin1 = 2;
const byte bin2 = 3;
const byte bin3 = 4;

byte bins[3];
byte oldBins[3];

RF24 radio(7, 8); // CE, CSN
byte addresses[][6] = {"00001", "00002"};

unsigned long lastSend;
bool sendAMessage = true;

void setup() {
  pinMode (bin1, INPUT);
  pinMode (bin2, INPUT);
  pinMode (bin3, INPUT);
  radio.begin();
  radio.setChannel(120);
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1, addresses[1]);
  radio.setPALevel(RF24_PA_MIN);
  Serial.begin(9600);
  Serial.println(F("setup finished"));
}

void loop() {
  bins[0] = digitalRead(bin1) ? 1 : 0;
  bins[1] = digitalRead(bin2) ? 1 : 0;
  bins[2] = digitalRead(bin3) ? 1 : 0;
  if (millis() - lastSend >= 500) {
    sendAMessage = true;
  }
  if (!memcmp(bins, oldBins, sizeof(bins))) {
    memcpy(oldBins, bins, sizeof(bins));
    sendAMessage = true;
  }
  if (sendAMessage) {
    sendAMessage = false;
    lastSend = millis();
    radio.write(bins, sizeof(bins));
    Serial.println(F("Data Sent"));
  }
}

You should avoid delay and other blocking code when programming any type of communication.
There is no need to use ints for bins, bytes work just the same.
You could even use bits and transmit a single byte with 5 unused bits.

My version sends a new packet when any button changes, or each 500 ms.