DrOpShOtZ
Published

Controls a LED from NRF24L01

Controlls a LED from NRF24L01

BeginnerProtip27,464
Controls a LED from NRF24L01

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×20
Arduino Nano R3
Arduino Nano R3
×2
nRF24 Module (Generic)
×2
Push Button
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Controlls a LED from NRF24L01

The circuit diagram

Code

Code for Transmitter

Arduino
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); 
const byte address[6] = "00001";     
int button_pin = 2;
boolean button_state = 0;


void setup() 
{
pinMode(button_pin, INPUT);
radio.begin();                 
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN); 
radio.stopListening();  
}


void loop()
{
button_state = digitalRead(button_pin);
if(button_state == HIGH)
{
const char text[] = "Your Button State is HIGH";
radio.write(&text, sizeof(text));                
}
else
{
const char text[] = "Your Button State is LOW";
radio.write(&text, sizeof(text)); 
}
radio.write(&button_state, sizeof(button_state)); 
delay(1000);
}

Code for Receiver

Arduino
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10);
const byte address[6] = "00001";
boolean button_state = 0;
int led_pin = 3;



void setup() 
{
pinMode(6, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address); 
radio.setPALevel(RF24_PA_MIN);       
radio.startListening();              
}



void loop()
{
if (radio.available())            
{
char text[32] = "";                 
radio.read(&text, sizeof(text)); 
radio.read(&button_state, sizeof(button_state));   
if(button_state == HIGH)
{
digitalWrite(6, HIGH);
Serial.println(text);
}
else
{
digitalWrite(6, LOW);
Serial.println(text);}
}
delay(5);
}

Credits

DrOpShOtZ

DrOpShOtZ

12 projects • 17 followers
Contact me from Discord. DrOpShOtZ#6290

Comments