NRF24L01 PART-2 || LEDS CONTROLL


NRF24L01 PART-2 || LEDS CONTROL


CIRCUIT DIAGRAM:




COMPONENTS REQUIRED:
1. ARDUINO NANO(2).
2. NRF24L01 (2).
3. SPDT TOGGEL SWITCH(4).
4. LEDS(4).
5. BATTERIES(2).

TRANSMITTER CODE:

#include <SPI.h> #include <RF24.h> #include<nRF24L01.h> #define FRONT_LED A0 #define BACK_LED A1 #define BOTTOM_LED A2 RF24 radio(9,10); const byte address[6] = "mkinventions100"; void setup() { pinMode(FRONT_LED,INPUT_PULLUP); pinMode(BACK_LED,INPUT_PULLUP); pinMode(BOTTOM_LED,INPUT_PULLUP); radio.begin(); radio.openWritingPipe(address); radio.setPALevel(RF24_PA_HIGH); radio.stopListening(); } void loop() { int LIGHTS[3]; LIGHTS[0] = digitalRead(FRONT_LED); LIGHTS[1] = digitalRead(BACK_LED); LIGHTS[2] = digitalRead(BOTTOM_LED); radio.write(&LIGHTS,sizeof(LIGHTS)); delay(100); }


RECEIVER CODE:


#include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #define FRONT_LED A0 #define BACK_LED A1 #define BOTTOM_LED A2 RF24 radio(9, 10); // CE, CSN const byte address[6] = "mkinventions100"; void setup() { pinMode(FRONT_LED,OUTPUT); pinMode(BACK_LED,OUTPUT); pinMode(BOTTOM_LED,OUTPUT); radio.begin(); radio.openReadingPipe(0, address); radio.setPALevel(RF24_PA_MIN); radio.startListening(); } void loop() { if (radio.available()) { LED_LIGHTS(); } }
void LED_LIGHTS(){ delay(100); int LIGHTS[3]; radio.read(&LIGHTS, sizeof(LIGHTS)); if (LIGHTS[0]==0) { //FRONT LIGHTS 0N analogWrite(FRONT_LED,255); } if (LIGHTS[0]==1) { //FRONT LIGHTS OFF analogWrite(FRONT_LED,0); } if (LIGHTS[1]==0) { //BACK LIGHTS ON analogWrite(BACK_LED,255); } if (LIGHTS[1]==1) { //BACK LIGHTS OFF analogWrite(BACK_LED,0); } if (LIGHTS[2]==0) { //BOTTOM LIGHTS ON analogWrite(BOTTOM_LED,255); } if (LIGHTS[2]==1) { //BOTTOM LIGHTS OFF analogWrite(BOTTOM_LED,0); } }///END LIGHTS---------------------------------------------

Comments