DIY : How to make Wireless Communication Between Two Arduino Boards Using The NRF24L01

Image result for nrf24l01

In this tutorial, we'll learn how to make wireless communication between two Arduino boards using the NRF24L01 transceiver module. You can read the written tutorial below. 

OVERVIEW:

Image result for introduction to NRF24L01

Here, we are going to learn how to turn on Led using NRF24L01 with Arduino Boards. NRF24L01 is Wireless Communicating using Radio Frequency. We are going to show you some basic use of NRF24L01. 

Required Components
  • 2x Arduino UNO/NANO/MEGA/Pro-Mini
  • 2x NRF24L01 Module
  • 1x BreadBoard / PCB Board
  • Jumper Wires for Connection
  • On/Off Switch
  • Small LED
Connection As Below




Please Complete Wiring as Above from both side transmitter and Receiver. and connect three switches on digital pin 2, 3 and 4 of the Arduino board respectively on the transmitter side and three LEDs on digital pin 2,3 and 4 of the Arduino board respectively on the receiver side.

Now upload the below program and start to communicate.
Transmitter Code:-
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[2];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 2;
int SW2 = 3;
int SW3 = 4;
void setup(void) {
  Serial.begin(115200);
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);
}
void loop(void) {
  if (digitalRead(SW1) == LOW) {
    msg[0] = 111;
    radio.write(msg, 2);
  }
  if (digitalRead(SW2) == LOW) {
    msg[0] = 222;
    radio.write(msg, 2);
  }
  if (digitalRead(SW3) == LOW) {
    msg[0] = 333;
    radio.write(msg, 2);
  }
}
     

Receiver Code:-
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[2];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
void setup(void) {
  Serial.begin(115200);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
}
void loop(void) {
  if (radio.available()) {
    bool done = false;
    while (!done) {
      radio.read(msg, 2);
      Serial.println(msg[0]); {
     
        if (msg[0] == 111) {
          digitalWrite(LED1, LOW);
        }
        if (msg[0] == 222) {
          digitalWrite(LED2, LOW);
        }
        if (msg[0] == 333) {
          digitalWrite(LED3, LOW);
        }
      }
    }
  }
  else {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);
  }
}

On the Transmitter side, CE is connected to Digital Pin 9 and CSN is connected to Digital Pin 10. and complete the wiring as shown in this Picture with 3 PushButtons.
And on the receiver side also, CE is connected to Digital Pin 9 and CSN is connected to Digital Pin 10 and complete the wiring as shown in this Picture using 3 LEDs.


Upload Program:-
           For Uploading Code, Open your Arduino IDE and in Tools select your Boards, and USB Port according to your Controller Board and upload the Code. Remember that here Baudrate is 115200.


Download the code library here: Library


Post a Comment

Post a Comment (0)

Previous Post Next Post