nrf24l01 arduino

can anyone help me with bidirectional communication for my project,
task is that i have three sensors, first i have to transmitt their data to recieving side and then with some buttons, turn something on(led or fan) on the sensrs side. i am unable to understand the code, so plz help or provide me the example code. thanks


i tried this code, led is not turning on or off

rf24_twoway_led_test.ino (6.53 KB)

Attach OP posted code for easy reading…

Copyright (C) 2014 Nathan Sobieck <>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.


/ This Example uses the RF24 library written by J. Coliz @ , 
/ Write this same sketch to two different Nodes. upon power up it will place both nodes into receiving mode 
/ and await a button press. When a button press is detected it will switch to send mode, uppdate the leds on 
/ on other node and return to listening mode.
/ PINS:        NRF24l01         UNO/328p           Mega
/ CE              3        -        9               9
/ CSN             4        -        10              53
/ SCK             5        -        13              52
/ MOSI            6        -        11              51
/ MISO            7        -        12              50
/ IRQ             8        -        n/a             n/a

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

RF24 radio(9,10); //CE,CSN   uno=(9,10) mega=(9,53)

// Buttons: where and how many 
const uint8_t button_pins[] = { 3 }; // you can add more seperated by comma i.e.. (3, 4, 5)
const uint8_t num_button_pins = sizeof(button_pins);//this just adds how many pins there are so they can be checked in succession later

// Leds: where and how many
const uint8_t led_pins[] = { 2 };   // you can add more seperated by comma i.e.. (3, 4, 5)
const uint8_t num_led_pins = sizeof(led_pins); // same as as above for leds

// Single radio pipe address for the 2 nodes to communicate. in this case were just havining them take turns on the same address
const uint64_t pipe = 0xE8E8F0F0E1LL;

uint8_t button_states[num_button_pins]; // place to store button values
uint8_t led_states[num_led_pins]; // place to store led values

// Setup---------------------Setup---------------------Setup

void setup (void)

 printf_begin(); // starts printf.h so we can use it to print to serial monitor... 

 //you can replace all the printf("text"); stuff with Serial.println("text")
 //but I like printf better than the built in serial.prinln as it has more options.

 printf(" rf24 two way led test sketch %s\n"); // debug 

 radio.begin();  //starts nrf with whatever config settings have been set.
 radio.setRetries(150,150);// optionally, increase the delay between retries & # of retries

 radio.openReadingPipe(1,pipe); //opens preset pipe/channel for reading.
 radio.startListening();        // starts listen on above pipe/channel
 radio.printDetails();          // dumps the nrf settings to monitor for debugging

 int i = num_button_pins;                  //
 while(i--)                                //
 {                                       // Sets buttons pins high
 pinMode(button_pins[i],INPUT);        // Looks for ground when pressed
 digitalWrite(button_pins[i],HIGH);    //

 int L = num_led_pins;                          // Sets Led pins to on
 while(L--)                                   // till it recieves different info...
 {                                            //
 pinMode(led_pins[L],OUTPUT);               // if you wanted them off till there turned on
 led_states[L] = HIGH;                      // change HIGH to LOW
 digitalWrite(led_pins[L],led_states[L]);   //

}// end of setup=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Loop---------------------------Loop---------------------------Loop
void loop (void)

}          //end of loop-=-=--=--=--==-=--=--=-=-=-===-=-=--=-

void chk_incoming() // incoming fuction call...
 if ( radio.available() ) // check if a payload came in....
 // Dump the payloads until we've gotten everything
 bool done = false;
 while (!done)
 // Fetch the payload, 
 done = button_states, num_button_pins );

 printf("Got buttons\n\r"); // for debugging

 // takes recieved button state and toggles the correct led
 int i = num_led_pins;
 if ( button_states[i] )
 led_states[i] ^= HIGH;

void chk_outgoing() // chk buttons states to see if we need to send updated info to other unit... 
 int i = num_button_pins;
 bool different = false;
 uint8_t state = ! digitalRead(button_pins[i]);
 if ( state != button_states[i] )
 different = true;
 button_states[i] = state;
 if (different)// if button has been pressed then.....
 TX_mode(); //calls Tx_mode function

/*                                                                                                      /
/      Tx_mode's code could have been placed directly above where "TX_mode();"                          /
/      was called but, I seperated it into it's own fuction for visual clairity and                     /
/      for easier editing later.. This sketch only uses like 7k space of the 30k on a uno               /
/      so I wasnt too worried about saving space....  I also seperated it so it was clear how            /
/      I did the switch from receiving to sending button states and back to receiving again.....        /

void TX_mode()// TX_mode function......
 radio.stopListening(); // must stop listening before you open a writing pipe  
 printf("Now sending...",button_states, num_button_pins); // for debuggging info
 bool ok = radio.write( button_states, num_button_pins ); // sends data
 if (ok) {              // checks if data was propperly received..
 printf("ok\n\r");    // for debugging
 radio.openReadingPipe(1,pipe); // closes writing pipe and opens Reading pipe
 radio.startListening();        // sets listening mode so were receiving and we start all over again from the beginning...
 else {
 printf("failed\n\r"); // for debugging " lets you know other did not received transmittion "

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

Can you please read Sticky Topic How to use this forum - please read.

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7,148850.0.html

This Simple nRF24L01+ Tutorial may help get you started.