Gesture controlled arduino car

Hi everyone,
I'm an arduino beginner and want to make an gesture controlled arduino car with an MPU-6050 and Nrf module.I also want to use L293D motor driver shield and
4 dc motors. So their will be no pins for Nrf CE and CSN pins (If I use arduino uno). So I've decided to use arduino mega.

I want to know about the schematics,code etc.
Reply soon.
Thanks.

Kalpit:
I also want to use L293D motor driver shield

In 2019, that's a bad choice. If you didn't buy that one yet, have a look here for example, for something more modern and more efficient. You can scan the specifications (voltage, current...) to find those that matches your motors.

Or you can buy an arduino car kit and learn about it

This Simple nRF24L01+ Tutorial may be of interest.

Note that the SPI pins are in a different place on a Mega

...R

Thank you all for fast replies.
And I've purchased The L293D Motor Driver.
I now want you to check My Schematic and Code.
Schematic is in attachments below.
Code:

//Include Libraries
#include <SPI.h>         //SPI library for communicate with the nRF24L01+
#include <nRF24L01.h>
#include <RF24.h>        //The main library of the nRF24L01+
#include <AFMotor.h>     //Library for L293D Motor Driver

//Define Motors
AF_DCMotor Front_Motor_Right(1, MOTOR12_8KHZ);           
AF_DCMotor Front_Motor_Left(2, MOTOR12_8KHZ);
AF_DCMotor Back_Motor_Right(3, MOTOR12_8KHZ);
AF_DCMotor Back_Motor_Left(4, MOTOR12_8KHZ);

//Define packet for the direction (X axis and Y axis)
int data[2];

//Define object from RF24 library - 23 and 22 are a digital pin numbers to which signals CE and CSN are connected
RF24 radio(23,22);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

void setup()
{
  Front_Motor_Right.setSpeed(250);
  Front_Motor_Left.setSpeed(250);
  Back_Motor_Right.setSpeed(250);
  Back_Motor_Left.setSpeed(250);
  
  //Start the nRF24 communicate
  radio.begin();
                             
  //Sets the address of the transmitter to which the program will receive data
  radio.openReadingPipe(0, address);       
  
  //Set module as receiver
  radio.startListening();
 }
 
 void loop(){

  //Read the data if available in buffer
  if (radio.available())
  {
    radio.read(data, sizeof(data));

    if(data[0] > 380){
      //forward
      Front_Motor_Right.run (FORWARD);
      Front_Motor_Left.run (FORWARD);
      Back_Motor_Right.run (FORWARD);
      Back_Motor_Left.run (FORWARD);
     }
    
    if(data[0] < 310){
      //backward              
      Front_Motor_Right.run (BACKWARD);
      Front_Motor_Left.run (BACKWARD);
      Back_Motor_Right.run (BACKWARD);
      Back_Motor_Left.run (BACKWARD);
    }
     
    if(data[1] > 180){
      //left
      Front_Motor_Right.run (FORWARD);
      Front_Motor_Left.run (BACKWARD);
      Back_Motor_Right.run (FORWARD);
      Back_Motor_Left.run (BACKWARD);
    }

    if(data[1] < 110){
      //right
      Front_Motor_Right.run (BACKWARD);
      Front_Motor_Left.run (FORWARD);
      Back_Motor_Right.run (BACKWARD);
      Back_Motor_Left.run (FORWARD);
    }

    if(data[0] > 330 && data[0] < 360 && data[1] > 130 && data[1] < 160){
      //stop car
      Front_Motor_Right.run (RELEASE);
      Front_Motor_Left.run (RELEASE);
      Back_Motor_Right.run (RELEASE);
      Back_Motor_Left.run (RELEASE);
    }
  }
}

Kalpit:
I now want you to check My Schematic and Code.

Please display your image(s) in your post so we can see it(them) without downloading it(them). See this Simple Image Upload Guide

And before I look at your code please tell us in detail what happens when you try it.

...R

@Robin2

First tell me that code and schematic is right or not.

I am not prepared to say that a Fritzing diagram is correct - it is too easy to misunderstand. Just make a simple pencil drawing with all the pins clearly labelled and post a photo of the drawing.

One thing I do see is that you are powering the nRF24 from a 5v pin whereas it should be from a 3.3v pin. And I have a Mega clone that cannot provide enough 3.3v power for an nRF24 - it needs a separate 3.3v power supply. A pair of AA alkaline cells (3v) can be used for testing. Make sure the power supply GND is connected to the Arduino GND.

Another thing - you don’t have a 10µF capacitor across Vcc and GND on the nRF24.

I have absolutely no intention of studying code without your information about what happens when you try it. If it works I would be wasting my time. And if it does not work then your information will help pinpoint the problem.

Also, you MUST have two programs to test a pair of nRF24s - you CANNOT test one in isolation no more than you can clap with one hand.

…R

Transmitter Specifications :

I Will Be Using Either Arduino Nano Or Uno(So Code Will Remain Same).

Connections of Nrf :

VCC - 3.3V
GND - GND
CE - D9
CSN - D10
MOSI - D11
MISO - D12
SCK - D13

Connections of MPU-6050 :

VCC - 5V
GND - GND
SCL - A5
SDA - A4
INT - D2

CODE :

//Add the necessary libraries
//You can find all the necessary library links in the video description.
#include <SPI.h>        //SPI library for communicate with the nRF24L01+
#include "RF24.h"       //The main library of the nRF24L01+
#include "Wire.h"       //For communicate
#include "I2Cdev.h"     //For communicate with MPU6050
#include "MPU6050.h"    //The main library of the MPU6050


//Define the object to access and cotrol the Gyro and Accelerometer (We don't use the Gyro data)
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;

//Define packet for the direction (X axis and Y axis)
int data[2];

//Define object from RF24 library - 9 and 10 are a digital pin numbers to which signals CE and CSN are connected.
RF24 radio(9,10);

//Create a pipe addresses for the communicate                                    
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void){
  Serial.begin(115200);
  Wire.begin();
  mpu.initialize();                 //Initialize the MPU object
  radio.begin();                    //Start the nRF24 communicate     
  radio.openWritingPipe(pipe);   //Sets the address of the receiver to which the program will send data.
  radio.stopListening();            //Set module as transmitter 
}

void loop(void){
  
  //With this function, the acceleration and gyro values of the axes are taken. 
  //If you want to control the car axis differently, you can change the axis name in the map command.
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  //In two-way control, the X axis (data [0]) of the MPU6050 allows the robot to move forward and backward. 
  //Y axis (data [0]) allows the robot to right and left turn.
  data[0] = map(ax, -17000, 17000, 90, 270 ); //Send X axis data
  data[1] = map(ay, -17000, 17000, 90, 270);  //Send Y axis data
  radio.write(data, sizeof(data));
  Serial.println("X Axis =");
  Serial.println(data[0]);
  delay(1000);
  Serial.println("Y Axis =");
  Serial.println(data[1]);
  delay(1000);
}

Receiver Specifications :

I Will Be Using Arduino Mega 2560.

Connections For Nrf :

VCC - 3.3V
GND - GND
CE - D22
CSN - D23
MOSI - D51
MISO - D50
SCK - D52

Connections For Motor Driver :

It Is An Arduino Uno Sized L293D Motor Driver Shield So It Will Be Occupying All The Arduino Uno (D0 - D13, A0 - A5) pins.

CODE :

//Include Libraries
#include <SPI.h>         //SPI library for communicate with the nRF24L01+
#include <nRF24L01.h>
#include <RF24.h>        //The main library of the nRF24L01+
#include <AFMotor.h>     //Library for L293D Motor Driver

//Define Motors
AF_DCMotor Front_Motor_Right(1, MOTOR12_8KHZ);           
AF_DCMotor Front_Motor_Left(2, MOTOR12_8KHZ);
AF_DCMotor Back_Motor_Right(3, MOTOR12_8KHZ);
AF_DCMotor Back_Motor_Left(4, MOTOR12_8KHZ);

//Define packet for the direction (X axis and Y axis)
int data[2];

//Define object from RF24 library - 22 and 23 are a digital pin numbers to which signals CE and CSN are connected
RF24 radio(22,23);  // CE, CSN

//address through which two modules communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup()
{
  Front_Motor_Right.setSpeed(250);
  Front_Motor_Left.setSpeed(250);
  Back_Motor_Right.setSpeed(250);
  Back_Motor_Left.setSpeed(250);

    Serial.begin(115200);

  
  //Start the nRF24 communicate
  radio.begin();
                             
  //Sets the address of the transmitter to which the program will receive data
  radio.openReadingPipe(0, pipe);       
  
  //Set module as receiver
  radio.startListening();
 }
 
 void loop(){

  //Read the data if available in buffer
  if (radio.available())
  {
    radio.read(data, sizeof(data));

   Serial.println("X Axis =");
   Serial.println(data[0]);
   delay(500);
   Serial.println("Y Axis =");
   Serial.println(data[1]);
   delay(500);

    if(data[0] > 150){
      //forward
      Front_Motor_Right.run (FORWARD);
      Front_Motor_Left.run (FORWARD);
      Back_Motor_Right.run (FORWARD);
      Back_Motor_Left.run (FORWARD);
     }
    
    if(data[0] < 230){
      //backward              
      Front_Motor_Right.run (BACKWARD);
      Front_Motor_Left.run (BACKWARD);
      Back_Motor_Right.run (BACKWARD);
      Back_Motor_Left.run (BACKWARD);
    }
     
    if(data[1] > 150){
      //left
      Front_Motor_Right.run (FORWARD);
      Front_Motor_Left.run (BACKWARD);
      Back_Motor_Right.run (FORWARD);
      Back_Motor_Left.run (BACKWARD);
    }

    if(data[1] < 220){
      //right
      Front_Motor_Right.run (BACKWARD);
      Front_Motor_Left.run (FORWARD);
      Back_Motor_Right.run (BACKWARD);
      Back_Motor_Left.run (FORWARD);
    }

    if(data[0] > 150 && data[0] < 230 && data[1] > 150 && data[1] < 220){
      //stop car
      Front_Motor_Right.run (RELEASE);
      Front_Motor_Left.run (RELEASE);
      Back_Motor_Right.run (RELEASE);
      Back_Motor_Left.run (RELEASE);
    }
  }
}

Problems :

Transmitter Code Working Fine With All ARDUINOs After Slightly Changing The Code( CE And CSN Pins)

But Receiver Code Is Not Working With Arduino Mega(With Uno Its Working )

In Serial Monitor, All Values Are Being Shown As 0.

I think There Maybe Some Problem In Code( Or Library As I’m Using It With Mega)

Note :

Whenever I change Arduino, I Change CE And CSN Pins In The Code.

Kalpit:
[But Receiver Code Is Not Working With Arduino Mega(With Uno Its Working )

What pins are you connecting the nRF24 to when you use the Mega?

Is it genuine Mega or a clone?

...R

Mine One Is A Clone But It Have A 3.3V Output.

The Connections Which I've Told In Receiver Connections Are Of Mega.

That is,

VCC - 3.3V
GND - GND
CE - D22
CSN - D23
MOSI - D51
MISO - D50
SCK - D52

This One Is Mine Arduino Mega :

Kalpit:
Mine One Is A Clone But It Have A 3.3V Output.

My clone with a 3.3v output cannot power an nRF24

The Connections Which I've Told In Receiver Connections Are Of Mega.

You also need to ensure that pin 53 (SS) is set as OUTPUT even if you are not using it.

...R

You mean, "pinMode(53, OUTPUT);" ?

Thank You All For Fast Answers.
There Was A Wiring Mistake.
Sorry All For Wasting Your Time.
By The Way, After My First Post Now I Will Surely Ask And Answer More Questions.
Had A Very Good Experience.

Kalpit:
You mean, “pinMode(53, OUTPUT);” ?

Yes.

What else might I have meant?

…R