# NRF24l01 not receiving (or transmitting?)

**URL:** <https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843>\
**Category:** Programming\
**Created:** [December 14, 2021, 12:51pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843 "2021-12-14T12:51:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 12:51pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/1 "2021-12-14T12:51:39Z")

</div>

Im working on a project with 2 Arduino nanos, each with its own NRF24l01. The transmitter has 2 buttons and a joystick, and the receiver is connected to a motor driver. Everything seems to be working (and was actually working when I tested it on a breadboard), but now the radios won't communicate.  
This is the transmitter code:

```cpp
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"

int SentMessage[1] = {000}; 
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

#define Button1 2
#define Button2 3

int button1=0;
int button2=0;

int xPosition = 0;
int yPosition = 0;

int directionX;
int directionY;

const int x_pin = A1;
const int y_pin = A2;

void setup() {
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(x_pin, INPUT);
  pinMode(y_pin, INPUT);

  Serial.begin(9600);

  pinMode(Button1, INPUT_PULLUP); 
  digitalWrite(Button1,HIGH); 
  pinMode(Button2, INPUT_PULLUP);
  digitalWrite(Button2, HIGH);

  radio.begin();
  //radio.openWritingPipe(pipe);   

  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);
}

```

This is the receiver code:

```cpp
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"

int ReceivedMessage[1] = {000};
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

#define MotorIN1 2
#define MotorIN2 3
#define ENA 5

#define MotorIN3 7
#define MotorIN4 4
#define ENB 6

int pwmSignal = 0;

void setup(void) {
  pinMode(MotorIN1, OUTPUT);
  pinMode(MotorIN2, OUTPUT);
  pinMode(ENA, OUTPUT);
  
  Serial.begin(9600);

  radio.begin(); // Start the NRF24L01
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  radio.startListening(); // Listen to see if information received

}

```

next in the receiver I have this:

```cpp
void loop(void) {
  while (radio.available()){

```

but the loop never seems to start? Im thinking that this is either because:

1. The transmitter never transmits
2. The receiver never receives
3. One of the radio is not operating

Please help ! Im at a loss

---

<div class="post-metadata">

**Author:** ![Danois90](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danois90](https://forum.arduino.cc/u/Danois90)\
**Post date:** [December 14, 2021, 1:00pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/2 "2021-12-14T13:00:34Z")

</div>

Vital parts of the code are missing, so impossible for anyone to help. There are numerous [guides on how to use NRF24 with Arduino](https://forum.arduino.cc/t/simple-nrf24l01-2-4ghz-transceiver-demo/405123), try to get one of those working before you add your own code for handling other things.

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 1:05pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/3 "2021-12-14T13:05:01Z")

</div>

I have followed a guide. Tested the same setup on a breadboard and it worked, so I don't see why this won't. Will post the complete code 👍

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 1:05pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/4 "2021-12-14T13:05:39Z")

</div>

Transmitter:

```cpp
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"

int SentMessage[1] = {000}; 
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

#define Button1 2
#define Button2 3

int button1=0;
int button2=0;

int xPosition = 0;
int yPosition = 0;

int directionX;
int directionY;

const int x_pin = A1;
const int y_pin = A2;

void setup() {
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(x_pin, INPUT);
  pinMode(y_pin, INPUT);

  Serial.begin(9600);

  pinMode(Button1, INPUT_PULLUP); 
  digitalWrite(Button1,HIGH); 
  pinMode(Button2, INPUT_PULLUP);
  digitalWrite(Button2, HIGH);

  radio.begin();
  //radio.openWritingPipe(pipe);   

  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);

}

void loop() {
  button1 = digitalRead(Button1);
  button2 = digitalRead(Button2);
  xPosition = analogRead(x_pin);
  yPosition = analogRead(y_pin);

  directionX = "0";
  directionY = "0";

  if (analogRead(x_pin) > 600){
    Serial.println("TOP");
    directionY = "TOP";
  }
  if (analogRead(x_pin) < 300){
    Serial.println("BOTTOM");
    directionY = "BOT";
  }
  if (analogRead(y_pin) > 600){
    Serial.println("RIGHT");
    directionX = "R";
  }
  if (analogRead(y_pin) < 300){
    Serial.println("LEFT");
    directionX = "L";
  }

  if ((button1 == LOW && button2 == LOW) or (button1 == HIGH && button2 == HIGH)){
    SentMessage[0] = 000;
    radio.write(SentMessage,1);
    Serial.println(1);
  } else {
    if (button1 == HIGH){
      SentMessage[0] = 001;
      radio.write(SentMessage,1);      
    } else if (button2 == HIGH){
      SentMessage[0] = 010;
      radio.write(SentMessage,1);       
    }
    
    if ((directionY == "TOP" && directionX == "0") or (directionY == "0" && directionX == "0")){
      SentMessage[0] == 011;
      radio.write(SentMessage,1);
      Serial.println("E");   
    } else if ((directionY == "TOP" && directionX == "R") or (directionY == "0" && directionX == "R")) {
      SentMessage[0] == 100;
      radio.write(SentMessage,1);
      Serial.println("D");   
    }else if (directionY == "BOT" && directionX == "R") {
      SentMessage[0] == 101;
      radio.write(SentMessage,1);
      Serial.println("C");         
    } else if (directionY == "BOT" && directionX == "L") {
      SentMessage[0] == 110;
      radio.write(SentMessage,1);
      Serial.println("B");   
    } else if ((directionY == "0" && directionX == "L") or (directionY == "TOP" && directionX == "L")) {
      SentMessage[0] == 111;
      radio.write(SentMessage,1);
      Serial.println("A");      
    }
  }
  Serial.println(SentMessage[0]);
  delay(1000);

  if (radio.available()){
    Serial.println("OK");
  }
}

```

Receiver:

```cpp
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"

int ReceivedMessage[1] = {000};
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

#define MotorIN1 2
#define MotorIN2 3
#define ENA 5

#define MotorIN3 7
#define MotorIN4 4
#define ENB 6

int pwmSignal = 0;

void setup(void) {
  pinMode(MotorIN1, OUTPUT);
  pinMode(MotorIN2, OUTPUT);
  pinMode(ENA, OUTPUT);
  
  Serial.begin(9600);

  radio.begin(); // Start the NRF24L01
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  radio.startListening(); // Listen to see if information received

}

void loop(void) {
  while (radio.available()){
    radio.read(ReceivedMessage, 1);

    if (ReceivedMessage[0] == 000){
      pwmSignal = 0;
      analogWrite(ENA, pwmSignal);
      digitalWrite(MotorIN1, LOW);
      digitalWrite(MotorIN2, LOW);
    }   
    if (ReceivedMessage[0] == 001){
      pwmSignal = 0;
      analogWrite(ENA, pwmSignal);
      digitalWrite(MotorIN1, HIGH);
      digitalWrite(MotorIN2, LOW);
    }
    if (ReceivedMessage[0] == 010){
      pwmSignal = 0;
      analogWrite(ENA, pwmSignal);
      digitalWrite(MotorIN1, LOW);
      digitalWrite(MotorIN2, HIGH);
    }

    if (ReceivedMessage[0] == 011){
      pwmSignal = 255;
      analogWrite(ENA, pwmSignal);  
    }
    if (ReceivedMessage[0] == 100){
      pwmSignal = 100;
      analogWrite(ENA, pwmSignal);
    }
    if (ReceivedMessage[0] == 101){
      pwmSignal = 0;
      analogWrite(ENA, pwmSignal);
    }
    if (ReceivedMessage[0] == 110){
      pwmSignal = 0;
      analogWrite(ENA, pwmSignal);
    }
    if (ReceivedMessage[0] == 111){
      pwmSignal = 100;
      analogWrite(ENA, pwmSignal);
    }
    delay(2);
    Serial.print(pwmSignal);
  }

  Serial.print("ABC");
  delay(1000);

}

```

---

<div class="post-metadata">

**Author:** ![Danois90](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danois90](https://forum.arduino.cc/u/Danois90)\
**Post date:** [December 14, 2021, 1:39pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/5 "2021-12-14T13:39:24Z")

</div>

Here is your problem:

```cpp
int SentMessage[1] = {000}; //An "int" is 2 bytes, and "000" is the same as "0"
...
SentMessage[0] = 000; //Again, why do you want three 0's?
radio.write(SentMessage,1); //Here you send one byte, but the message is 2 bytes.

//radio.write(SentMessage, sizeof(SentMessage)); //This is how to do it

```

The same problem is present in the receiver.

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 1:51pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/6 "2021-12-14T13:51:23Z")

</div>

So I need to change

```cpp
radio.write(SentMessage,1);

```

to

```cpp
radio.write(SentMessage,2);

```

?

---

<div class="post-metadata">

**Author:** ![Danois90](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danois90](https://forum.arduino.cc/u/Danois90)\
**Post date:** [December 14, 2021, 2:02pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/7 "2021-12-14T14:02:30Z")

</div>

> [@radeoic](#):
>
> So I need to change

Yes, but I would encourage you so use "sizeof()" or a constant instead of defining the size as inlined constants. If you change the size of the buffer, you must also change all the inlined constants and that is cumbersome.

```arduino
//Declare
const int BUFLEN = 1; //Number of elements in the array
const int BUFSIZE = BUFLEN * sizeof(int); //Size in bytes of the array
int buffer[BUFLEN] = {0}; //The array

//Use
radio.write(buffer, BUFSIZE);
radio.read(buffer, BUFSIZE);

```

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 2:08pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/8 "2021-12-14T14:08:16Z")

</div>

Does the constant declare the size of bytes? So I would just use BUFSIZE = 2 so I can use values from 0 to 111?

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [December 14, 2021, 2:22pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/9 "2021-12-14T14:22:48Z")

</div>

Hi,

> [@radeoic](#):
>
> Everything seems to be working (and was actually working when I tested it on a breadboard), but now the radios won't communicate.

What have you got it constructed on now, if not breadboard?

Can you please post some circuit and construction information, pictures, circuit?

Thanks.. Tom... 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![Danois90](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danois90](https://forum.arduino.cc/u/Danois90)\
**Post date:** [December 14, 2021, 2:34pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/10 "2021-12-14T14:34:33Z")

</div>

> [@radeoic](#):
>
> Does the constant declare the size of bytes? So I would just use BUFSIZE = 2 so I can use values from 0 to 111?

Sorry, I made a mistake and I have corrected it in the example in #7

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [December 14, 2021, 3:47pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/11 "2021-12-14T15:47:56Z")

</div>

> [@radeoic](#):
>
> `SentMessage[0] == 011;`

Why octal?

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 4:04pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/12 "2021-12-14T16:04:41Z")

</div>

what does octal mean?

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 4:10pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/13 "2021-12-14T16:10:21Z")

</div>

I have soldered everything to pcbs. I am trying to construct an rc  
Here are the schematic for the receiver and a picture of the pcbs 🙂Processing: IMG\_0076.jpg...  
Uploading: IMG\_3573 2.JPG...

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [December 14, 2021, 4:10pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/14 "2021-12-14T16:10:53Z")

</div>

10 - a decimal number (base 10)  
0x10 - a hexadecimal number (base 16)  
010 - an octal number (base 8)  
0b10 - a binary number (base 2)

---

<div class="post-metadata">

**Author:** ![anon77129126](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon77129126](https://forum.arduino.cc/u/anon77129126)\
**Post date:** [December 14, 2021, 4:16pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/15 "2021-12-14T16:16:26Z")

</div>

How long have you have the RF24s?  
When did they last work?  
Did they ever work?  
What range do you want?  
How much interference can you tolerate?  
Have they had any hard knocks?

My solution is just to buy RF nanos. They are basically nRF24s but soldered onto a nano. They work very well, if not without a bit of range loss.

I ask about knocks because the timing crystal on RF24 modules can be misaligned and fail.

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 4:25pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/16 "2021-12-14T16:25:50Z")

</div>

oh okay, I'm trying to use binary ig. Is there one that is better than the others to use?

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 4:27pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/17 "2021-12-14T16:27:56Z")

</div>

This is the first project im using them on, so about a month (have tried to switch them into complete new ones, but still won't work). They worked just fine before I soldered everything. I have changed the code a bit so im guessing that's where the mistake is.  
Dont need long range, just a couple of metres. Im just making a RC car as a hobby project

---

<div class="post-metadata">

**Author:** ![anon77129126](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon77129126](https://forum.arduino.cc/u/anon77129126)\
**Post date:** [December 14, 2021, 4:28pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/18 "2021-12-14T16:28:29Z")

</div>

Is it possible that the heat from soldering might have damaged them?

EDIT - Another possibility is that your PCB is flawed.

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 4:29pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/19 "2021-12-14T16:29:12Z")

</div>

Im sorry, but I still dont understand how to implement this into the code. And wont the receiver still receive the 000 signal? And if so the while loop would start, which it dosent...

---

<div class="post-metadata">

**Author:** ![radeoic](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@radeoic](https://forum.arduino.cc/u/radeoic)\
**Post date:** [December 14, 2021, 4:29pm UTC](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843/20 "2021-12-14T16:29:55Z")

</div>

As I said, I have tried to change them into someone that Is completely new...

[Next page](https://forum.arduino.cc/t/nrf24l01-not-receiving-or-transmitting/935843.md?page=2)
