MAKING A DRONE REMOTE
to make the drone remote you will need following components:-
- nrf24 rf module(two)
- joystick module(two)
- arduino nano (two)
- capacitors (one)
connection of nrf24 for both transmitter and receiver are same. there are some additional connections to be made in transmitter to read data from joystick so
and connnect the joystick pins in following way
Right joystick y axis pin = A0;
Right joystick x axis pin = A7;
Right joystick switch pin = A6;
left joystick y axis pin = A1;
left joystick x axis pin = A5;
left joystick switch pin = A2;
now after connecting the above circuit upload the following codes given for transmitter and receiver and you will get the data as shown below in receiver side.
now transmitter code is as follows
#include <SPI.h>
#include "RF24.h"
const int Ry = A0;
const int Rx = A7;
const int Rs = A6;
const int Ly = A1;
const int Lx = A5;
const int Ls = A2;
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
struct package
{
int lx = 0;
int ly = 0;
int ls = 0;
int rx = 0;
int ry = 0;
int rs = 0;
};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
myRadio.write(&data, sizeof(data));
data.rx = analogRead(Rx);
data.ry = analogRead(Ry);
data.rs = analogRead(Rs);
if(data.rs >100)
{data.rs = 1;}
else if(data.rs <100)
{data.rs = 0;}
data.lx = analogRead(Lx);
data.ly = analogRead(Ly);
data.ls = analogRead(Ls);
if(data.ls >100)
{data.ls = 1;}
else if(data.ls <100)
{data.ls = 0;}
delay(100);
}
#include "RF24.h"
const int Ry = A0;
const int Rx = A7;
const int Rs = A6;
const int Ly = A1;
const int Lx = A5;
const int Ls = A2;
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
struct package
{
int lx = 0;
int ly = 0;
int ls = 0;
int rx = 0;
int ry = 0;
int rs = 0;
};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
myRadio.write(&data, sizeof(data));
data.rx = analogRead(Rx);
data.ry = analogRead(Ry);
data.rs = analogRead(Rs);
if(data.rs >100)
{data.rs = 1;}
else if(data.rs <100)
{data.rs = 0;}
data.lx = analogRead(Lx);
data.ly = analogRead(Ly);
data.ls = analogRead(Ls);
if(data.ls >100)
{data.ls = 1;}
else if(data.ls <100)
{data.ls = 0;}
delay(100);
}
receiver code is as follows
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
struct package
{
int lx = 0;
int ly = 0;
int ls = 0;
int rx = 0;
int ry = 0;
int rs = 0;
};
byte addresses[][6] = {"0"};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.read( &data, sizeof(data) );
}
Serial.print("lx ");
Serial.print(data.lx);
Serial.print(" ly ");
Serial.print(data.ly);
Serial.print(" ls ");
Serial.print(data.ls);
Serial.print(" rx ");
Serial.print(data.rx);
Serial.print(" ry ");
Serial.print(data.ry);
Serial.print(" rs ");
Serial.println(data.rs);
}
}
#include "RF24.h"
RF24 myRadio (7, 8);
struct package
{
int lx = 0;
int ly = 0;
int ls = 0;
int rx = 0;
int ry = 0;
int rs = 0;
};
byte addresses[][6] = {"0"};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.read( &data, sizeof(data) );
}
Serial.print("lx ");
Serial.print(data.lx);
Serial.print(" ly ");
Serial.print(data.ly);
Serial.print(" ls ");
Serial.print(data.ls);
Serial.print(" rx ");
Serial.print(data.rx);
Serial.print(" ry ");
Serial.print(data.ry);
Serial.print(" rs ");
Serial.println(data.rs);
}
}