I made a sketch that receives an rgb code from a remote Arduino using nrf24l01 and while it works for the first receivings then it stops working. I placed a testing Serial.println in the loop to test if Arduino stops to work completely or it doesn't receive any other data. Finally, I understood that it continues to work but it doesnt receive more data. Bellow is my code:

#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>

#include  <TimerOne.h>
#include <SPI.h>
//#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(8,10);
RF24Network network(radio);
volatile int i=0; 
volatile int d=0;     // Variable to use as a counter
volatile boolean zero_cross=0;  // Boolean to store a "switch" to tell us if we have crossed zero
int AC_pin= 4;    // Output to Opto Triac pin
int dim = 0;  // Dimming level (0-128)  0 = ON, 128 = OFF
int freqStep = 65; 

struct payload_rgb
  unsigned int red;
  unsigned int green;
  unsigned int blue;
struct payload_lightuv
  unsigned int light;
  unsigned int uv;
RF24NetworkHeader header;
payload_rgb payloadrgb;
payload_lightuv payloadl;
void setup() {
  // put your setup code here, to run once:
  pinMode(AC_pin, OUTPUT);// Set AC Load pin as output
  pinMode(9, OUTPUT);// Set AC Load pin as output
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  attachInterrupt(0, zero_cross_detect, RISING);  // Choose the zero cross interrupt # from the table above
  Timer1.initialize(freqStep);                      // Initialize TimerOne library for the freq we need
  Timer1.attachInterrupt(dim_check, freqStep);    

void loop() {
  while ( network.available() )

Serial.println("!"); //this is the test println
void zero_cross_detect() {    
  zero_cross = true;               // set the boolean to true to tell our dimming function that a zero cross has occured
  digitalWrite(AC_pin, LOW);       // turn off TRIAC (and AC)
void dim_check() {                   
  if(zero_cross == true) {              
    if(i>=dim) {                     
      digitalWrite(AC_pin, HIGH); // turn on light       
      i=0;  // reset time step counter                         
      zero_cross = false; //reset zero cross detection
    else {
      i++; // increment time step counter                     

Additionally, this Arduino controls an ac dimmer. Bu I have not done it yet. How can I fix the problem without removing any feature?

  • Is it maybe running out of memory? I am not familiar with network.read but does this memory get free'd ?
    – Manatok
    Jun 3 '15 at 12:28
  • Why network.read should use memory? The only thing that uses memory are the variables and structures. And even if it used, shouldn't the arduino stop completely? Jun 3 '15 at 12:32
  • I think it would have to buffer that input and if it is allocating memory each time and not cleaning up, maybe its running out. But this is just a guess. ..."If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely"...arduino.cc/en/Tutorial/Memory
    – Manatok
    Jun 3 '15 at 12:54
  • 1
    Try resetting the nrfs with the below answer: arduino.stackexchange.com/a/54604/35167
    – paulplusx
    Jul 20 '18 at 6:29
  • 1
    See this. arduino.stackexchange.com/questions/55042/…
    – paulplusx
    Aug 5 '18 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.