top of page

1.1KM Wireless Communication using Arduino & NRF24L01

Writer's picture: AdminAdmin


nRF24L01 Module


The nFR24L01 is a transceiver module which means that it can both send and receive the data.

These modules are very cheap, smaller in size and has a lot of specifications. Some of the specifications of these modules are as follows


Specifications of nRF24L01 Module

  • Power consumption is around 12mA during transmission which is even lesser than the led.

  • It can operate with baud rates from 250Kbps up to 2 Mbps.

  • Its range can reach up to 100 meters if used in open space and with antenna.

  • It can both send and receive the data simultaneously.

  • Each module can communicate with up to 6 other modules.

  • It uses the 2.4 GHz band.

  • It can send 1 to 25 bytes of raw data at the transmission rate of 1 MB.

  • It has 125 different channels.

CODE FOR RECEIVER

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>


#define relayPin1 A0

#define relayPin2 A1


int buttonState = 0;


RF24 radio(9, 10); // CE, CSN

const byte address[6] = "00002";


void setup() {

Serial.begin(9600);

pinMode(relayPin1, OUTPUT);

pinMode(relayPin2, OUTPUT);

digitalWrite(relayPin1, HIGH);

digitalWrite(relayPin2, HIGH);

radio.begin();

radio.openReadingPipe(0, address);

radio.setPALevel(RF24_PA_MIN);

}


void loop() {

radio.startListening();

while (!radio.available());

radio.read(&buttonState, sizeof(buttonState));

Serial.println(buttonState);


if (buttonState == 1) {

digitalWrite(relayPin1, LOW);

}

else if (buttonState == 0) {

digitalWrite(relayPin1, HIGH);

}

else if (buttonState == 3) {

digitalWrite(relayPin2, LOW);

}

else if (buttonState == 2) {

digitalWrite(relayPin2, HIGH);

}

}



CODE FOR TRANSMITTER


#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>


#define buttonPin1 A0

#define buttonPin2 A1


int buttonState1 = 0;

int buttonState2 = 0;


RF24 radio(9, 10); // CE, CSN


const byte address[6] = "00002";


void setup() {

pinMode(buttonPin1, INPUT);

pinMode(buttonPin2, INPUT);

Serial.begin(9600);

radio.begin();

radio.openWritingPipe(address);

radio.setPALevel(RF24_PA_MIN);

radio.stopListening();

}

void loop() {

buttonState1 = digitalRead(buttonPin1);

buttonState2 = digitalRead(buttonPin2);


if (buttonState1 == 1)

{

buttonState1 = 1;

}

else if (buttonState1 == 0)

{

buttonState1 = 0;

}

if (buttonState2 == 1)

{

buttonState2 = 3;

}

else if (buttonState2 == 0)

{

buttonState2 = 2;

}

Serial.print(buttonState1);

Serial.print("\t");

Serial.println(buttonState2);

radio.write(&buttonState1, sizeof(buttonState1));

radio.write(&buttonState2, sizeof(buttonState2));

}

629 views0 comments

Recent Posts

See All

Comments


bottom of page