Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Neeraj Rane
Published © CC BY-NC-SA

RC Transmitter Using NRF24L01 Radio Module and Arduino

A transmitter for your RC projects!

IntermediateFull instructions provided4 hours8,700
RC Transmitter Using NRF24L01 Radio Module and Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
nRF24 Module (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Top Body

Bottom Body

Error uploading file to Sketchfab.

Schematics

Schematic

Code

Transmitter Code

Arduino
/*A basic 4 channel transmitter using the nRF24L01 module.*/
/* Like, share and subscribe, ELECTRONOOBS */
/* http://www.youtube/c/electronoobs */

/* First we include the libraries. Download it from 
   my webpage if you donw have the NRF24 library */
 
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

/*Create a unique pipe out. The receiver has to 
  wear the same unique code*/
  
const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(9, 10); // select  CSN  pin

// The sizeof this struct should not exceed 32 bytes
// This gives us up to 32 8 bits channals
struct MyData {
  byte throttle;
  byte yaw;
  byte pitch;
  byte roll;
  byte AUX1;
  byte AUX2;
};

MyData data;

void resetData() 
{
  //This are the start values of each channal
  // Throttle is 0 in order to stop the motors
  //127 is the middle value of the 10ADC.
    
  data.throttle = 0;
  data.yaw = 127;
  data.pitch = 127;
  data.roll = 127;
  data.AUX1 = 0;
  data.AUX2 = 0;
}

void setup()
{
  //Start everything up
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  resetData();
}

/**************************************************/

// Returns a corrected value for a joystick position that takes into account
// the values of the outer extents and the middle of the joystick range.
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
  val = constrain(val, lower, upper);
  if ( val < middle )
    val = map(val, lower, middle, 0, 128);
  else
    val = map(val, middle, upper, 128, 255);
  return ( reverse ? 255 - val : val );
}

void loop()
{
  // The calibration numbers used here should be measured 
  // for your joysticks till they send the correct values.
  data.throttle = mapJoystickValues( analogRead(A0), 0, 523, 1023, true );
  data.yaw      = mapJoystickValues( analogRead(A1),  0, 512, 1023, true );
  data.pitch    = mapJoystickValues( analogRead(A3), 0, 516, 1023, true );
  data.roll     = mapJoystickValues( analogRead(A2), 0, 524, 1023, true );
  data.AUX1     = digitalRead(4);
  data.AUX2     = digitalRead(5);

  radio.write(&data, sizeof(MyData));
}

Credits

Neeraj Rane
18 projects • 47 followers
Electrical Engineer and a Maker from India. Engineering is fun once you start applying it!
Contact

Comments

Please log in or sign up to comment.