Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //
  2. // https://www.youtube.com/c/LeventeDaradici/videos
  3. //
  4.  
  5.     #include <SPI.h>
  6.     #include <nRF24L01.h>
  7.     #include <RF24.h>
  8.     RF24 radio(9, 10); // CE, CSN, MOSI=11, MISO=12, SCK=13
  9.     const byte address[6] = "00001";
  10.     void setup() {
  11.       Serial.begin(9600);
  12.       radio.begin();
  13.       radio.openReadingPipe(0, address);
  14.       radio.setPALevel(RF24_PA_MAX,1); //set as: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
  15.       radio.setDataRate(RF24_250KBPS); //set as: F24_250KBPS, F24_1MBPS, F24_2MBPS ==>250KBPS = longest range
  16.       radio.setChannel(120); //sets channel from 2.4 to 2.524 GHz in 1 MHz increments 2.483.5 GHz is normal legal limit
  17.       radio.startListening();
  18.       pinMode(2, OUTPUT);
  19.       pinMode(3, OUTPUT);
  20.     }
  21.     void loop() {
  22.       if (radio.available())
  23.          {
  24.             digitalWrite(3, LOW);
  25.             char text[32] = "";
  26.             radio.read(&text, sizeof(text));
  27.             String Data = String(text);
  28.             Serial.println(text);
  29.             if(Data == "ON")
  30.               {
  31.                  digitalWrite(2, HIGH);
  32.                  delay(500);
  33.               }
  34.             if(Data == "OFF")
  35.               {
  36.                  digitalWrite(2, LOW);
  37.                  delay(500);
  38.               }              
  39.            
  40.           }
  41.       else
  42.           {
  43.             digitalWrite(2, LOW);
  44.             digitalWrite(3, HIGH);                      
  45.           }
  46.     }