Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hammad Iqbal
Published © GPL3+

Wireless Communication Using nRF24L01 Transceiver Module

This project will help you to add wireless communication to any of your Arduino-based projects.

IntermediateFull instructions provided1 hour1,334
Wireless Communication Using nRF24L01 Transceiver Module

Story

Read more

Schematics

img_0288_yeFODLLZO5.JPG

Code

For Transmitter

C/C++
//Hammadiqbal12@gmail.com

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

RF24 radio(9, 10); // CE, CSE
const byte address[6] = "00001"; 


int sendingdata[6];

void setup()
{
 
Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
 delay(50);
}

void loop()
{
 

//Analogue Stick readings
 int in1 = analogRead(A0); //Right Stick Up and Down
int in2 = analogRead(A1); //Right Stick Left and Right
int in3 = analogRead(A2); //left Stick Up and Down
 int in4 = analogRead(A3); //Left Stick Left and Right
sendingdata[0]=in1;
sendingdata[1]=in2;
sendingdata[2]=in3;
sendingdata[3]=in4;
 radio.write( sendingdata, sizeof(sendingdata) );
 Serial.print("RY =");
Serial.println(sendingdata[0]);
 Serial.print("LY =");
Serial.println(sendingdata[2]);



  
  delay(15);
}

For Receiver

C/C++
//hammadiqbal12@gmail.com

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
Servo yaw;
Servo pitch;
Servo roll;
Servo thr;

int joystick[6];
void setup() {
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
thr.attach(2);
yaw.attach(3);
pitch.attach(4);
roll.attach(5);
delay(25);
}
void loop() {
  if ( radio.available() )
  {
    // Reading the data payload until the RX received everything
    bool done = false;
    while (!done)
    { 
      // Fetching the data payload
      radio.read( joystick, sizeof(joystick) );
     done = true; 
          
     int val0=map(joystick[0],0,1024,0,180);
     int val1=map(joystick[1],0,1024,0,180);
     int val2=map(joystick[2],0,1024,0,180);
     int val3=map(joystick[3],0,1024,0,180);
    thr.write(val0);
    yaw.write(val1);
    pitch.write(val2);
    roll.write(val3);
//for serial observation
    Serial.println(val0);
    Serial.println(val1);
    Serial.println(val2);
    Serial.println(val3);
    }
  }
  else
  {    
      Serial.println("No radio available");
  }
 delay(50);
} 

Github

https://github.com/nRF24/RF24

Credits

Hammad Iqbal
6 projects • 43 followers
I'm an Electrical Engineer and here I'm to share my knowledge about Embedded system.
Contact

Comments

Please log in or sign up to comment.