Hugo Gomes
Published © GPL3+

FPV RC Car

Control an RC car with a computer racing wheel and in the end add a wireless camera.

IntermediateFull instructions provided8 hours1,285
FPV RC Car

Things used in this project

Hardware components

RC Auto
×1
Wireless Camera
×1
DFRobot Dreamer Nano V4.1
×2
Computador Racing Wheel
×1
L298N
×1
nRF24L01+
×2
7.4V 800mA LiPo
×1
Resistor 10k ohm
Resistor 10k ohm
×4
100K Resistor
×4

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Dremel

Story

Read more

Schematics

RX Schematic

Schematic v1 1 rx v1 1 tz6smedepk

TX Schematic

Schematic v1 1 tx ohm3ak3i2l

Code

Car_RX.ino

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

RF24 radio(9, 10); //Set up nRF24L01+ radio on SPI bus plus pins 9 and 10

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };//2 pipes communication
unsigned int received_data[3];
unsigned int num_received_data = sizeof(received_data);


////////////////////////////////////////////////////////////////////////////////////

//Define Pins for Motor Drive
//Motor Speed
int enable_A = 3;
int in1Pin = 2;
int in2Pin = 4;

//Motor Direction
int enable_B = 5;
int in3Pin = 6;
int in4Pin = 7;

boolean reverse = false;
int motor_pwm = 0;
boolean right = false;
boolean left = false;


////////////////////////////////////////////////////////////////////////////////////
void setup(void)
{
  Serial.begin(115200);
  //configure pin modes

  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(enable_A, OUTPUT);

  pinMode(in3Pin, OUTPUT);
  pinMode(in4Pin, OUTPUT);
  pinMode(enable_B, OUTPUT);

  radio.begin();


  radio.setPALevel( RF24_PA_MAX ) ; // Max power
  radio.setDataRate( RF24_250KBPS ) ; // Min speed (for better range I presume)
  radio.setCRCLength( RF24_CRC_8 ) ; // 8 bits CRC
  radio.setChannel(108); //2.508 Ghz - Above most Wifi Channel
  radio.setRetries(15, 15); // increase the delay between retries & # of retries
  radio.openReadingPipe(1, pipes[1]);
  radio.startListening();
  radio.printDetails();
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1, pipes[0]);
  radio.startListening();
}//void setup

void loop(void)
{

  ///////////////////////////////Radio reading///////////////////////////////////////////////////////
  if ( radio.available() )
  {
    bool done = false;
    while (!done)
    {
      radio.read(&received_data, num_received_data);
      done = true;
      delay(30);
    }// while (!done)

    Serial.print(received_data[0]);
    Serial.print ("---");
    Serial.print(received_data[1]);
    Serial.print ("---");

    Serial.println(received_data[2]);



    if (received_data[0] < 0 || received_data[0] != 1)

      if (received_data [1] == 1 && received_data [2] == 0)
      {

        motor_pwm = motor_pwm + 10;
        reverse = false;

      }
      else if (received_data [2] == 1 && received_data [1] == 0)
      {

        // if (reverse==false) motor_pwm=0;

        motor_pwm = motor_pwm + 10;
        reverse = true;

      }
      else  motor_pwm = motor_pwm - 10;


    motor_pwm = constrain(motor_pwm, 0, 200);

    if (received_data [0] <= 90 && received_data [0] >= 40)
    {
      analogWrite(enable_B, 0);
      digitalWrite(in3Pin, 0);
      digitalWrite(in4Pin, 0);
    }
    if (received_data [0] >= 75 &&  received_data [0] <= 90) //Left
    {

      analogWrite(enable_B, 230);
      digitalWrite(in3Pin, 0);
      digitalWrite(in4Pin, 1);

    } else if (received_data [0] >= 40 && received_data [0] <= 58) //Right
    {
      analogWrite(enable_B, 230);
      digitalWrite(in3Pin, 1);
      digitalWrite(in4Pin, 0);
    }

  }//if ( radio.available() )


  setMotor(motor_pwm, reverse);

}// void loop


void setMotor(int speed, boolean reverse)
{
  analogWrite(enable_A, speed);
  digitalWrite(in1Pin, ! reverse);
  digitalWrite(in2Pin, reverse);
}


void Car_direction(int speed, boolean direction)
{

}

Car_TX.ino

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

RF24 radio(9, 10); //Set up nRF24L01+ radio on SPI bus plus pins 9 and 10

unsigned int data[3] ;
const uint8_t buffer_size = sizeof(data);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };//two pipes communication


//Declare the pins for the racing wheel
const int wheel_direction = A0;//

const int button_1A = 2;
const int Button_2A = 4;

const int button_1B = 3;
const int button_2B = 5;


void setup(void)
{
  Serial.begin(115200);
  pinMode(wheel_direction, INPUT );

  pinMode(button_1A, INPUT_PULLUP );
  pinMode(Button_2A, INPUT_PULLUP );
  pinMode(button_1B, INPUT_PULLUP );
  pinMode(button_2B, INPUT_PULLUP );

  radio.begin();
  radio.setPALevel( RF24_PA_MAX );  // Max power
  radio.setDataRate( RF24_250KBPS); // Min speed (for better range I presume)
  radio.setCRCLength( RF24_CRC_8);  // 8 bits CRC
  radio.setChannel(108);            //2.508 Ghz - Above most Wifi Channel
  radio.setRetries(15, 15);
  radio.openReadingPipe(1, pipes[1]);
  radio.startListening();
  radio.printDetails();
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);
  radio.stopListening();

}

void loop(void)
{


  int wheel_value = analogRead(wheel_direction) / 10;

  data[0] = wheel_value;
  ////////////////////////////////////////////////////////////////////////

  if (digitalRead(button_1A) == LOW || digitalRead(Button_2A) == LOW  )   data[1] = 1;
  else   data[1] = 0;

  if ( digitalRead(button_1B) == LOW || digitalRead(button_2B) == LOW )   data[2] = 1;
  else   data[2] = 0;
  /////////////////////////////////////////////////////////////////////////

  /////////////////////////////////////////////////////////////////////////
  
  radio.stopListening();

  bool ok = radio.write(  data , sizeof(data) );
  delay(30);
  radio.startListening();
  delay(20);
  if (ok) {
    Serial.print("data[0]=");
    Serial.print(data[0]);
    Serial.print(" data[1]=");
    Serial.print(data[1]);
    Serial.print(" data[2]=");
    Serial.println(data[2]);

  }
  else
    Serial.println("Failed");

}//void loop()

Credits

Hugo Gomes

Hugo Gomes

10 projects • 60 followers
http://www.hugogomes.net Youtube Channel - https://goo.gl/fnQLJo
Contact

Comments