Hello~
I am learning about NRF24L01 and I tried making a simple project that I could communicate two Arduinos, one as a Transmitter and the other as a Receiver, sending and receiving information at the same time.
Its basically two Arduinos(UNO) with a Led and a Pushbutton connected in both. If I press the pushbutton, the Led at the other Arduino will turn ON.
It is working, but the Transmitter suddenly stops looping(I think). The program stops completly about 5 or 10 seconds after a turn on.
Im using a 100miliseconds delay, I realized that the faster the sketch goes the faster it stops looping. If I use 10miliseconds delay it stops in about 2 seconds.
I can see by the Serial monitor that only the transmitter arduino stops looping, while the other arduino(receiver) works fine and keep waiting for a signal from the transmitter(that is frozen).
Before the transmitter stops(5 to 10 seconds after turn on), everything works fine.
--> Here is the TRANSMITTER CODE:
// TRANSMITTER
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define button 3
#define led 2
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
boolean buttonState = 0;
boolean recbutton = 0;
unsigned long timer = 0;
void setup() {
 // put your setup code here, to run once:
 pinMode(led, OUTPUT);
 pinMode(button, INPUT_PULLUP);
Â
 radio.begin();
 radio.setPALevel(RF24_PA_MIN);
 radio.setDataRate(RF24_2MBPS);
 radio.setChannel(124);
 radio.openWritingPipe(addresses[1]); // 00002
 radio.openReadingPipe(1, addresses[0]); // 00001
Â
 Serial.begin(9600);
}
void loop() {
 buttonState = digitalRead(button);
Â
 radio.stopListening();
 if (!radio.write( &buttonState, sizeof(buttonState) )) {
  Serial.println("No acknowledgement of transmission - receiving radio device connected?"); Â
 } else{
  Serial.print("Sent button: ");
  Serial.println(buttonState);
 }
 delay(100);
 radio.startListening();
 timer = millis();
 while(!radio.available()){
  if(millis() - timer >= 200){
   Serial.println("No response received - timeout!");
   return;Â
  }
 }
 radio.read(&recbutton, sizeof(recbutton));
 if(recbutton == 1){
  digitalWrite(led, LOW);
 } else{
  digitalWrite(led, HIGH);
 }
 Serial.print("Received Button: ");
 Serial.println(recbutton);
 delay(100);
}
--> Here is the Receiver code:
// RECEIVER
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define button 3
#define led 2
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
boolean buttonState = 0;
boolean recbutton = 0;
void setup() {
 // put your setup code here, to run once:
 pinMode(led, OUTPUT);
 pinMode(button, INPUT_PULLUP);
Â
 radio.begin();
 radio.setPALevel(RF24_PA_MIN);
 radio.setDataRate(RF24_2MBPS);
 radio.setChannel(124);
 radio.openWritingPipe(addresses[0]); // 00002
 radio.openReadingPipe(1, addresses[1]); // 00001
 radio.startListening();
Â
 Serial.begin(9600);
}
void loop() {
 if(radio.available()){
  while(radio.available()){
   radio.read(&recbutton, sizeof(recbutton));
   Serial.print("Received Button: ");
   Serial.println(recbutton);
  }
  if(recbutton == 1){
   digitalWrite(led, LOW);
  } else{
   digitalWrite(led, HIGH);
  }
  delay(100);
  radio.stopListening();
  buttonState = digitalRead(button);
  if(radio.write(&buttonState, sizeof(buttonState))){
   Serial.print("Sent button state: ");
   Serial.println(buttonState);
  } else{
   Serial.println("Sent failed");
  }
  delay(100);
 Â
  radio.startListening();
 }
}
I tried to check the connections and the sketch, but everything looks fine, I really have no idea what is the problem.
Thank you!