chihauccisoilconte

NRF24L01_receiver_basic

May 24th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //circuit for NRF24L01
  2. //MISO - 12
  3. //SCK - 13
  4. //CE - 7
  5. //CSN - 8
  6. //MOSI - 11
  7.  
  8. #include <SPI.h>
  9. #include <nRF24L01.h>
  10. #include <RF24.h>
  11. RF24 radio(7, 8); // CE, CSN
  12. const byte address[6] = "00001";
  13. boolean button_state = 0;
  14. int led_pin = 3;
  15. void setup() {
  16. pinMode(led_pin, OUTPUT);
  17. Serial.begin(9600);
  18. radio.begin();
  19. radio.openReadingPipe(0, address);   //Setting the address at which we will receive the data
  20. radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
  21. radio.startListening();              //This sets the module as receiver
  22. }
  23. void loop()
  24. {
  25. if (radio.available())              //Looking for the data.
  26. {
  27. char text[32] = "";                 //Saving the incoming data
  28. radio.read(&text, sizeof(text));    //Reading the data
  29. radio.read(&button_state, sizeof(button_state));    //Reading the data
  30. if(button_state == HIGH)
  31. {
  32. digitalWrite(led_pin, HIGH);
  33. Serial.println(text);
  34. }
  35. else
  36. {
  37. digitalWrite(led_pin, LOW);
  38. Serial.println(text);}
  39. }
  40. delay(5);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment