# [SOLVED] nRF24L01

#### wernerdejong1972

Joined Sep 10, 2021
12
Hi all

I´m trying to get to arduinos to communicate together througt a nRF24L01. On the receiver side I want to turn the builtin LED to turn on every time I press a button on the transmitter. Furthermore I want to show a message on the Serial monitor that tells me the state off the button.
The part with the serial monitor works as planned but the builtin LED doesn´t turn on. What am I doing wrong?

C:
//RECEIVER
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
boolean button_state = 0;

void setup() {
pinMode(LED_BUILTIN, OUTPUT);

Serial.begin(9600);
radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
}
void loop()
{
if (radio.available())              //Looking for the data.
{
char text[32] = "";                 //Saving the incoming data
if (button_state == HIGH)
{
Serial.println(text);
delay(5);
digitalWrite(LED_BUILTIN, HIGH);
}
else
{
Serial.println(text);
delay(5);
digitalWrite(LED_BUILTIN, LOW);
}
}
delay(5);
}
Moderator edit: added code tags like this [code] ... your code... [/code]

#### MrChips

Joined Oct 2, 2009
27,651
Welcome to AAC!

Please post the code for the transmitter.

#### wernerdejong1972

Joined Sep 10, 2021
12
Sure

C-like:
// Transmitter

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>

RF24 radio(9, 10); // CE, CSN

const byte address[6] = "00001";     //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.

int button_pin = 2;

boolean button_state = 0;

void setup() {

pinMode(button_pin, INPUT);

radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.

radio.stopListening();          //This sets the module as transmitter

}

void loop()

{

if(button_state == HIGH)

{

const char text[] = "Your Button State is HIGH";

}

else

{

const char text[] = "Your Button State is LOW";

}

delay(1000);

}

#### wernerdejong1972

Joined Sep 10, 2021
12
When I remove:

digitalWrite(LED_BUILTIN, HIGH);
in setup, the builtin LED turn on. Otherwise it´s impossible to get the LED to turn on.

#### Ya’akov

Joined Jan 27, 2019
6,853
Why are your delays between the serial write and the digital write?

#### wernerdejong1972

Joined Sep 10, 2021
12
Yaakov: I don´t really know, somebody recommended it. It has no function what so ever. It har no effect when I remove the delay.

#### Ya’akov

Joined Jan 27, 2019
6,853
Try adding a delay at the end of the on button state block, just to check.

C++:
    {
Serial.println(text);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
}

#### wernerdejong1972

Joined Sep 10, 2021
12
Nope, no succes....

#### Ya’akov

Joined Jan 27, 2019
6,853
OK. More quick troubleshooting. Comment out the serial write, just leave the digital write code in the conditional block.

#### wernerdejong1972

Joined Sep 10, 2021
12
Do you mean this?
C-like:
if (button_state == HIGH)

{

//Serial.println(text);

digitalWrite(LED_BUILTIN, HIGH);

delay(1000);

}

else

{

//Serial.println(text);

digitalWrite(LED_BUILTIN, HIGH);

delay(1000);

}

}
(didn´t work either...)

Last edited by a moderator:

#### Ya’akov

Joined Jan 27, 2019
6,853
Yes, that's what I meant. So I have this straight, when the serial code is uncommented, it does write to the serial monitor, correct?

#### wernerdejong1972

Joined Sep 10, 2021
12
yes, serial monitor works but no LED,

#### Ya’akov

Joined Jan 27, 2019
6,853
Which pins are the nRF24L01 wired to?

#### wernerdejong1972

Joined Sep 10, 2021
12
8 - 13

#### wernerdejong1972

Joined Sep 10, 2021
12

#### Ya’akov

Joined Jan 27, 2019
6,853
Pin 13 is probably your LED. You need to put an external one on a different pin, if so.

#### wernerdejong1972

Joined Sep 10, 2021
12
" SPI uses pin 13, so you can’t really use the built in LED while using SPI. "
could this be the solution? I´m not sure, because I´ve also tried pin3 without luck.

#### Ya’akov

Joined Jan 27, 2019
6,853
" SPI uses pin 13, so you can’t really use the built in LED while using SPI. "
could this be the solution? I´m not sure, because I´ve also tried pin3 without luck.
See above. pin 13 is hardwired to the builtin LED. You will ahve to put an external led on a different pin to make it work.