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?
Moderator edit: added code tags like this [code] ... your code... [/code]
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
const byte address[6] = "00001";
boolean button_state = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MIN); //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening(); //This sets the module as receiver
}
void loop()
{
if (radio.available()) //Looking for the data.
{
char text[32] = ""; //Saving the incoming data
radio.read(&text, sizeof(text)); //Reading the data
radio.read(&button_state, sizeof(button_state)); //Reading the 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);
}