chihauccisoilconte

NRF24L01_transmitter_basic

May 24th, 2020
137
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";     //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.
  13. int button_pin = 2;
  14. boolean button_state = 0;
  15. void setup() {
  16. pinMode(button_pin, INPUT);
  17. radio.begin();                  //Starting the Wireless communication
  18. radio.openWritingPipe(address); //Setting the address where we will send the data
  19. radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
  20. radio.stopListening();          //This sets the module as transmitter
  21. }
  22. void loop()
  23. {
  24. button_state = digitalRead(button_pin);
  25. if(button_state == HIGH)
  26. {
  27. const char text[] = "Your Button State is HIGH";
  28. radio.write(&text, sizeof(text));                  //Sending the message to receiver
  29. }
  30. else
  31. {
  32. const char text[] = "Your Button State is LOW";
  33. radio.write(&text, sizeof(text));                  //Sending the message to receiver
  34. }
  35. radio.write(&button_state, sizeof(button_state));  //Sending the message to receiver
  36. delay(5);
  37. }
Add Comment
Please, Sign In to add comment