There are three Arduinos on a model. Each of them has a DS18B20 Dallas temperature sensor and an nRF24L01 antenna wireless communication. There is also an independent device consisting of an Arduino and an nRF24L01 antenna. Device acts as a receiver. Arduino and antenna play the role of transmitter. The code is:

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

int temp1;
int WindSpeed;
int temp2;
int temp3;
RF24 radio(7, 8);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL};
void setup() {
  radio.setRetries(15, 15);
  radio.openReadingPipe(0, pipes[1]);
  radio.openReadingPipe(1, pipes[2]);
  radio.openReadingPipe(2, pipes[3]);

void loop() {
  if (radio.available()) {
    radio.read(&temp1, sizeof(temp1));  
     radio.read(&WindSpeed, sizeof(WindSpeed));
     Serial.println(" WindSpeed Bf : ");
     radio.read(&temp2, sizeof(temp2));
     radio.read(&temp3, sizeof(temp3));      
  } else {
    Serial.println("No radio Data avaliable");

The problem is that the code sends some values but the correspondence isn't right in AnalogRead. How can I watch each pipe with the antenna of corresponding Arduino in order to have the right results, and each Arduino sends to the receiver through its own antenna the value of its sensor?

Thanks all for your time!

  • 1
    I wouldn't send those three sensor values in different packets. Just combine them in a single packet. As you are currently relying on the order of the packets, things will get messed up if a single packed isn't being received. Using a single packet will prevent his problem. I'm not really understanding your question. I'm also missing the senders Arduino code.
    – Gerben
    Sep 1, 2016 at 12:55
  • @Gerben the data is coming from three distinct radio transmitters, and the question seems to be about using the radio's multiple pipes feature to keep the feeds distinct. Dec 31, 2016 at 19:13

2 Answers 2


You appear to be using the multiple pipes of the nrf24L01 to keep your data feeds distinct, and to be asking how you can differentiate the pipes on receive.

It's not clear which exact RF24 library you are using, but if you look at the headers of a typical one you will find something like:

   * Test whether there are bytes available to be read
   * Use this version to discover on which pipe the message
   * arrived.
   * @param[out] pipe_num Which pipe has the payload available
   * @return True if there is a payload available, false if none is
  bool available(uint8_t* pipe_num);

Additionally, you do not want to use any delays in receiving code, as that could cause you to miss transmissions - if you use delays for pacing, they should be on the transmit side.

It's not clear if you have 3 or 4 pipes (and in your setup you have forgotten that C/C++ array indexing starts at 0 not 1) but to read 3 of potentially 4, you could do something like:

#define INTERVAL_MS 10000
unsigned long lastMsg = 0;
int values[4];
char *pipeNames[] = {"Temp1:", " WindSpeed Bf : ", "temp2:", "temp3"}; 
void loop() {
   uint8_t pipe;         
   if (radio.available(&pipe) {
     if (pipe < 3) {
        radio.read(&values[pipe], sizeof(int));
        lastMsg = millis();
     else radio.flush_rx(); //unclear if this is needed to allow new data on a pipe that is of interest
   /* warning - may mis-operate after ~50 days */
   if ((millis() - lastMsg) > INTERVAL_MS) {
      Serial.println("no data received in past 10 seconds");
      lastMsg = millis();
  • Just two corrections: millis() is lowercase and from the available() prototype, you should pass in '&pipe' rather than 'pipe' so the function can modify it to the pipe that has available data. So, no need for the loop. Jan 1, 2017 at 16:27
  • Thanks! Tying "Millis" felt odd when I was doing it, but it is that way in the title of the reference page, but not for the actual function. Jan 1, 2017 at 17:39

You want to send data from 3 (or 4?) different Arduino transmitters to one Arduino receiver and you want to be able to distinguish the packets sent by each transmitter as they are received. The most straightforward way is to create a struct for your data and attach a unique header and trailer that can be used to identify the sender.

typedef struct {
  uint8_t header = 0x01;
  int temp1;
  uint8_t trailer = 0x10;

Something like this should be present in each transmitter but with unique header and trailer for each one. Then the receiver should have the header and trailer bytes for all the transmitters and, whenever it receives data, it checks the first received byte against the list of header bytes to know who sent the data before it continues. Finally, it checks the last byte to know if it's the correct trailer byte for the assumed sender and also as an additional (but perhaps unnecessary) layer of error detection to know if the received packet is a complete valid one.

  • This would work in the generic case, but the poster appears to be use the nrf24l01 "pipes" feature to keep their channels unique. Since they have that out-of-band distinction, they don't need to implement an in-band one with identifiers in their data. Dec 31, 2016 at 18:55
  • @ChrisStratton I agree. This is unnecessary, since the library already provides a convenient way to do it. Jan 1, 2017 at 16:22
  • The actual capability comes from the radio hardware, the library merely exposes it. Jan 1, 2017 at 17:40
  • @ChrisStratton True, but digging through the NRF24 docs to find this and then implement it would be a pain. Jan 1, 2017 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.