RF24 LIGHT SWITCH

RF24 switch tr

The code can be downloaded :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/RF24Switch.zip

TRANSMITTER

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”

int DataMsg[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F482LL;

int Button1 = 3;
int Button2 = 2;

void setup()
{
//ativa pull-up
pinMode(3, INPUT);
digitalWrite(3,HIGH);
pinMode(2, INPUT);
digitalWrite(2,HIGH);

Serial.begin(9600);
Serial.println(“NRF24L01 Transmitter”);

radio.begin();
radio.openWritingPipe(pipe);
}

void loop()
{
if (digitalRead(Button1) == LOW)
{
Serial.println(“Button 1 pressed”);
DataMsg[0] = 1;
radio.write(DataMsg, 1);
}
if (digitalRead(Button2) == LOW)
{
Serial.println(“Button 2 pressed”);
DataMsg[0] = 2;
radio.write(DataMsg, 1);
}
}

RF24 switch rcv

RECEIVER

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”

int DataMgs[1];
RF24 radio(8,7);
const uint64_t pipe = 0xE14BC8F482LL;
int Relay1 = 5;

void setup()
{
pinMode(Relay1, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop()
{
if (radio.available())
{
bool done = false;
while (!done)
{
done = radio.read(DataMgs, 1);
Serial.print(“NRF24L01 Receiver: “);
Serial.println(DataMgs[0]);

if (DataMgs[0] == 1)
{
delay(10);
digitalWrite(Relay1, HIGH);
}

if (DataMgs[0] == 2)
{
delay(10);
digitalWrite(Relay1, LOW);
}
delay(100);
}
}
else
{
Serial.println(“Waiting for signal…”);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s