talofer99 icon

NRF_SLAVE

talofer99 | PRO | 06/04/19 02:58:14 PM UTC | 0 ⭐ | 343 👁️ | Never ⏰ | []
C |

1.43 KB

|

None

|

0 👍

/

0 👎

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
  
RF24 radio(8, 10); // CE, CSN for UNO
//  RF24 radio(7, 8); // CE, CSN FOR NANO
 
 
  
const byte address[6] = "00001";
int ActivationDelay = 2000; // TARGET ACTIVATION DELAY TIME
int SolenoidTime = 250;     // DURATION FOR SOLENOID TO BE TRIGGERED 
long SerialInput;
 
void setup() {
      pinMode(2, OUTPUT);       // LED CONTROL ON/OFF
      pinMode(3, OUTPUT);       // RELAY CONTROL ON/OFF
      Serial.begin(9600);
      Serial.setTimeout (10);   // SET DELAY BETWEEN ENTER IN SERIAL MONITOR AND PARSING STRING
      radio.begin();
      radio.openReadingPipe(0, address);
      radio.setPALevel(RF24_PA_MIN);
      radio.startListening();  
    }
    
void loop() {
// SECTION FOR READING REMOTE BUTTON STATE AND CONTROLLING RELAY //
       while (radio.available()) {
        char text[3] = "";
        radio.read(&text, sizeof(text));
        Serial.println(text);
        
        if text[0] == 1  { // this is the ON
             digitalWrite(2, HIGH); // TRIGGER LED ON
             delay(text[1]*1000);// ACTIVATION DELAY TIMER
             digitalWrite(3, HIGH); // RELAY CLOSED
             delay(text[2]*250);   // SOLENOID CHARGE DURATION TIME         
             digitalWrite(3, LOW);  // RELAY OPEN
             digitalWrite(2, LOW);  // TRIGGER LED OFF
        } else {
             digitalWrite(2, LOW); // TRIGGER LED OFF
             digitalWrite(3, LOW); // RELAY OPEN
        }
        
}

Comments