Project showcase
Arduino Radio Communication (nRF24L01)

Arduino Radio Communication (nRF24L01) © GPL3+

Make your own RC toys, gadgets, stuff.

  • 499 views
  • 0 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

I wanted to make my own RC car with customisable controls, with an Arduino and the nRF24L01 module the only limit is our imagination (and our programing skills).

Here you can see my controller prototype, its ugly but functional.

And I made two receiver units for it:

It's really important to note that wecan use each of this module as a receiver or transmitter and both in the same time,and we can communicate with more than one module in the same time.

After using my prototype remote for a few weeks I've had enough because of the the hanging wires, and I decided to make/buy a real one.

Using the EasyADA online platform, I created the necessary gerber files, and I ordered my custom arduino remote controller. It was my first order custom pcb. It's not hard to make one and the final result looks really good, I even put my logo on it.

Short assembling video:

And I made a 3D-printed case for the pcb in which I glued the battery, the charging module and a DC step-up converter. And the result looks like this:

And in the two top holes I can put potentiometers, switches, buzzers or whatever the project requires.

Code

nrf24l01 remoteArduino
//Remote Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//LED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define L_AXIS A0 // Left Y Axis Port
#define R_AXIS A2 // Right Y Axis Port
#define Pot A7   // Poteciometer

//LED Display
#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);

float value ;
float voltage ;
int percentage;

struct data{
  int left;
  int right;
  int maxs;
 
};
data send_data;

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "06720"; //NRF Address
void setup() {
  
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  
  radio.begin();
  radio.setAutoAck(false);
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_HIGH);
  radio.setDataRate(RF24_250KBPS);
  radio.stopListening();
  
}
void loop() {
  send_data.left=analogRead(L_AXIS);  //Read Left Joystick Y axis value
  send_data.right=analogRead(R_AXIS); //Read Right Joystick Y axis value
  send_data.maxs=map(analogRead(Pot), 0, 1023, 1023, 0);
  
  radio.write(&send_data, sizeof(data));

  value = analogRead(A6);
  voltage = ((5*value)/1023)*4.103354632587859 ;
  percentage = map((voltage*10), 30, 42, 0, 100);
  

  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  
  display.setCursor(0,0);
  display.print("L= ");
  display.print(send_data.left);

  display.print("  Power: ");
  if( (500 < send_data.left ) && ( send_data.left < 530 ) )  display.println(0);
  if( send_data.left <= 500 ){
    display.print("-");
    display.println(map(send_data.left, 0, 500, 255, 100));
  }
  if( 530 <= send_data.left )  display.println(map(send_data.left, 530, 1023, 100, 255));

  
  display.print("R= ");
  display.print(send_data.right);

  display.print("  Power: ");
  if( (500 < send_data.right ) && ( send_data.right < 530 ) )  display.print(0);
  if( send_data.right <= 500 ){
    display.print("-");
    display.print(map(send_data.right, 0, 500, 255, 100));
  }
  if( 530 <= send_data.right )  display.print(map(send_data.right, 530, 1023, 100, 255));

  display.print('\n');
  display.print('\n');
  display.print('\n');
  display.print('\n');
  display.print("Max Speed: ");
  display.print(map(send_data.maxs, 0, 1023, 150, 255));
  display.print('\n');
  display.print("Voltage: ");
  display.print(voltage);
  display.print("V   ");
  display.print(percentage);
  display.print("%");
  
  display.display();
  
}
nrf24l01 receiverArduino
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);

//Motor Ports
#define R_FRONT 10
#define R_BACK 9  
#define L_FRONT 5 
#define L_BACK 6

int maxSpeed ;

const int buzzer = 3; //buzzer to arduino pin 9

  

RF24 radio(7, 8); // CE, CSN


const byte address[6] = "06720"; //NRF Address

unsigned long lastRecvTime = 0; //Used for latency check

struct data{
  int left;
  int right;
  int maxs;
 
};
data receive_data;

void reset_the_Data() //Set default values
{
  receive_data.left=510;
  receive_data.right=510;
  receive_data.maxs=0;
  
  
}

void receive_the_data() //Read
{
  while ( radio.available() ) {
    radio.read(&receive_data, sizeof(data));
    lastRecvTime = millis();
  }
}

void move(char direction[ ], char motor[ ], int value){
  if(motor == "right"){
    if(direction == "stay"){
      analogWrite(R_FRONT,0);
      analogWrite(R_BACK,0);
    }else if(direction == "backwards"){
      analogWrite(R_BACK,map(value, 0, 500, maxSpeed, 100));
    }else if(direction == "forwards"){
      analogWrite(R_FRONT,map(value, 530, 1023, 100, maxSpeed));
    }
  }else{
    if(direction == "stay"){
      analogWrite(L_FRONT,0);
      analogWrite(L_BACK,0);
    }else if(direction == "backwards"){
      analogWrite(L_BACK,map(value, 0, 500, maxSpeed, 100));
    }else if(direction == "forwards"){
      analogWrite(L_FRONT,map(value, 530, 1023, 100, maxSpeed));
    }
    maxSpeed = map(receive_data.maxs, 0, 1023, 150, 255);
  }

  
  Serial.print(direction);
  Serial.print(" ");
  Serial.print(motor);
  Serial.print(" ");
  Serial.println(value);

}

  



void setup() {
  
  
  Serial.begin(9600);
  radio.begin();
  radio.setAutoAck(false);
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_250KBPS);
  radio.startListening();

   Wire.begin();
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3C (for the 128x32)(initializing the display)
  
}
void loop() {
  receive_the_data();
  
  unsigned long now = millis();
  if ( now - lastRecvTime > 1000 ) {  //Check for latency
    reset_the_Data();
  }

  
  if( (500 < receive_data.left ) && ( receive_data.left < 530 ) )  move("stay","left",receive_data.left);
  if( receive_data.left <= 500 )  move("backwards","left",receive_data.left);
  if( 530 <= receive_data.left )  move("forwards","left",receive_data.left);

  if( (500 < receive_data.right ) && ( receive_data.left < 530 ) )  move("stay","right",receive_data.right);
  if( receive_data.right <= 500 )  move("backwards","right",receive_data.right);
  if( 530 <= receive_data.right )  move("forwards","right",receive_data.right);
  
  //int value=map(receive_data.right, 0, 1023, 180, 255);
  //analogWrite(R_FRONT,value);

  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  
  display.setCursor(0,0);
  display.print("LY= ");
  display.print(receive_data.left);
  display.print("\t");
  display.print("  RY= ");
  display.print(receive_data.right);
  
        
  display.display();

  
   
  
      
  /*Serial.print(receive_data.left);
  Serial.print("\t");
  Serial.println(receive_data.right);*/
}

Schematics

nrf24l01 Remote

Comments

Similar projects you might like

FM Radio with Frequency Display

Project showcase by Tauno Erik

  • 5,845 views
  • 0 comments
  • 12 respects

RC Toy Car Using nRF24L01

Project tutorial by Jayraj Desai

  • 5,939 views
  • 0 comments
  • 10 respects

FM Radio Using Arduino and RDA8057M

Project tutorial by Neeraj Rane

  • 6,625 views
  • 2 comments
  • 24 respects

Art Deco FM Radio Project Using Arduino

Project tutorial by Nick Koumaris

  • 6,076 views
  • 1 comment
  • 20 respects
Add projectSign up / Login