"gesture control car" NRF24L01 error

So, I've been trying to figure out what's wrong in my project, I'm trying to make gesture control car using 2 nrf24l01 modules for receiving and transferring data I'm using arduino uno r3 for receiving and for transmitting i'm using 9v battery MPU 6050 as gyroscopic sensor and arduino nano as board for transmitter i'm using 7.4 v. I did some research and some people mentioned inadequate voltage supply also can be hindering me from transmitting or receiving when I checked voltage i was getting enough power supply in my receiver NRF module and for transmitter I was getting 3.29v so is that 0.1 v the cause or is it my code?


these are my circuit diagrams. Also directly supplying 5v on my nrf module will fry it right? Sorry for my bad english and grammar.

//Transmitter code
//These are needed for MPU
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"

//These are need for RF handlling
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//#define PRINT_DEBUG   //Uncomment this line if you want to print the MPU6050 initialization information on serial monitor

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif

// MPU control/status vars
MPU6050 mpu;
bool dmpReady = false;  // set true if DMP init was successful
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint8_t fifoBuffer[64]; // FIFO storage buffer
Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

// RF control
const uint64_t pipeOut = 0xF9E8F0F0E1LL;   //IMPORTANT: The same as in the receiver 0xF9E8F0F0E1LL
RF24 radio(8, 9); // select CE,CSN pin

struct PacketData 
{
  byte xAxisValue;
  byte yAxisValue;
} data;

void setupRadioTransmitter()
{
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  radio.stopListening(); //start the radio comunication for Transmitter  

  data.xAxisValue = 127; // Center
  data.yAxisValue = 127; // Center 
}


void setupMPU()
{
  // join I2C bus (I2Cdev library doesn't do this automatically)
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
      Wire.begin();
      Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
  #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
      Fastwire::setup(400, true);
  #endif

  #ifdef PRINT_DEBUG
    // initialize serial communication
    Serial.begin(115200);
    while (!Serial); // wait for Leonardo enumeration, others continue immediately
    // initialize device
    Serial.println(F("Initializing I2C devices..."));
  #endif
  
  mpu.initialize();

  #ifdef PRINT_DEBUG  
    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
    // wait for ready
    Serial.println(F("\nSend any character to begin DMP programming and demo: "));
    while (Serial.available() && Serial.read()); // empty buffer
    while (!Serial.available());                 // wait for data
    while (Serial.available() && Serial.read()); // empty buffer again
    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
  #endif
  
  devStatus = mpu.dmpInitialize();
  
  // make sure it worked (returns 0 if so)
  if (devStatus == 0) 
  {
      // Calibration Time: generate offsets and calibrate our MPU6050
      mpu.CalibrateAccel(6);
      mpu.CalibrateGyro(6);
      
      #ifdef PRINT_DEBUG      
        mpu.PrintActiveOffsets();
        // turn on the DMP, now that it's ready
        Serial.println(F("Enabling DMP..."));
      #endif
      mpu.setDMPEnabled(true);
  
      // set our DMP Ready flag so the main loop() function knows it's okay to use it
      #ifdef PRINT_DEBUG      
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
      #endif
      dmpReady = true;
  
      // get expected DMP packet size for later comparison
      packetSize = mpu.dmpGetFIFOPacketSize();
  } 
  else 
  {
      // ERROR!
      // 1 = initial memory load failed
      // 2 = DMP configuration updates failed
      // (if it's going to break, usually the code will be 1)
      #ifdef PRINT_DEBUG       
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
      #endif
  }
}


void setup()
{
  //This is to set up radio transmitter for rf
  setupRadioTransmitter();   
  //This is to set up MPU6050 sensor
  setupMPU();
}

void loop() 
{
  // if programming failed, don't try to do anything
  if (!dmpReady) return;
  // read a packet from FIFO. Get the Latest packet
  if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) 
  {  
    // display Euler angles in degrees
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

    int xAxisValue = constrain(ypr[2] * 180/M_PI, -90, 90);
    int yAxisValue = constrain(ypr[1] * 180/M_PI, -90, 90);
    data.xAxisValue = map(xAxisValue, -90, 90, 0, 254); 
    data.yAxisValue = map(yAxisValue, -90, 90, 254, 0);

    radio.write(&data, sizeof(PacketData));

    #ifdef PRINT_DEBUG  
      Serial.println(xAxisValue);  
      Serial.println(yAxisValue);        
    #endif
  }
}
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//#define PRINT_DEBUG   //Uncomment this line if you want to print the values on serial monitor

#define SIGNAL_TIMEOUT 500  // This is signal timeout in milli seconds.

const uint64_t pipeIn = 0xF9E8F0F0E1LL;
RF24 radio(8, 9); 
unsigned long lastRecvTime = 0;

struct PacketData
{
  byte xAxisValue;    
  byte yAxisValue;
} receiverData;

//Right motor
int enableRightMotor=5; 
int rightMotorPin1=2;
int rightMotorPin2=3;

//Left motor
int enableLeftMotor=6;
int leftMotorPin1=4;
int leftMotorPin2=7;


void setup()
{
  pinMode(enableRightMotor,OUTPUT);
  pinMode(rightMotorPin1,OUTPUT);
  pinMode(rightMotorPin2,OUTPUT);
  
  pinMode(enableLeftMotor,OUTPUT);
  pinMode(leftMotorPin1,OUTPUT);
  pinMode(leftMotorPin2,OUTPUT);

  rotateMotor(0,0); 
    
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1,pipeIn);
  radio.startListening(); //start the radio receiver 

  #ifdef PRINT_DEBUG
    Serial.begin(115200);
  #endif
}

void loop()
{
    int rightMotorSpeed=0;
    int leftMotorSpeed=0;
    // Check if RF is connected and packet is available 
    if(radio.isChipConnected() && radio.available())
    {
      radio.read(&receiverData, sizeof(PacketData)); 
      int mappedYValue = map(receiverData.yAxisValue, 0, 254, -255, 255); 
      int mappedXValue = map(receiverData.xAxisValue, 0, 254, -255, 255); 
      int motorDirection = 1;     
      if (mappedYValue < 0)
      {
        motorDirection = -1;
      }
    
      rightMotorSpeed = abs(mappedYValue) - mappedXValue;
      leftMotorSpeed = abs(mappedYValue) + mappedXValue;
  
      rightMotorSpeed = constrain(rightMotorSpeed, 0, 255);
      leftMotorSpeed = constrain(leftMotorSpeed, 0, 255);
      
      rotateMotor(rightMotorSpeed * motorDirection, leftMotorSpeed * motorDirection);

      lastRecvTime = millis();  
      
      #ifdef PRINT_DEBUG  
        Serial.println(receiverData.xAxisValue);
        Serial.println(receiverData.yAxisValue);      
      #endif
    }
    else
    {
      //Signal lost. Reset the motor to stop
      unsigned long now = millis();
      if ( now - lastRecvTime > SIGNAL_TIMEOUT ) 
      {
        rotateMotor(0, 0);   
     }
   }
}


void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
  if (rightMotorSpeed < 0)
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,HIGH);    
  }
  else if (rightMotorSpeed > 0)
  {
    digitalWrite(rightMotorPin1,HIGH);
    digitalWrite(rightMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,LOW);      
  }
  
  if (leftMotorSpeed < 0)
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,HIGH);    
  }
  else if (leftMotorSpeed > 0)
  {
    digitalWrite(leftMotorPin1,HIGH);
    digitalWrite(leftMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,LOW);      
  }  

  analogWrite(enableRightMotor, abs(rightMotorSpeed));
  analogWrite(enableLeftMotor, abs(leftMotorSpeed));    
}
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define CE_PIN   8
#define CSN_PIN 9
const uint64_t pipe = 0xF9E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN); 
int data[2];
void setup()   
{
  Wire.begin();
  mpu.initialize();
   pinMode(5,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(7,OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}


void loop() {
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
gyro_value = map(ax, 0, 17000, 0,255);
motor_value=abs(gyro_value);
  if ( radio.available() ) //Eğer sinyal algılarsan...
  {
    int y = data[1];
    int x = data[0];
    radio.read( data, sizeof(data) ); 
    if(y >= 400 && y <= 600) {
     digitalWrite(5,LOW);
    digitalWrite(2,LOW);
    analogWrite(3,0);
    digitalWrite(6,LOW);
    digitalWrite(4,LOW);
    analogWrite(7,0);
    }
     if(y >= 800 && y <= 1023) {
     digitalWrite(5,LOW);
    digitalWrite(2,HIGH);
    analogWrite(3,motor_value);
    digitalWrite(6,LOW);
    digitalWrite(4,HIGH);
    analogWrite(7,motor_value);
    }
    if(y >= 0 && y <= 450) {
     digitalWrite(5,HIGH);
    digitalWrite(2,LOW);
    analogWrite(3,motor_value);
    digitalWrite(6,HIGH);
    digitalWrite(4,LOW);
    analogWrite(7,motor_value);
    }
    if(x >= 0 && x <= 450) {
     digitalWrite(5,LOW);
    digitalWrite(2,HIGH);
    analogWrite(3,motor_value);
    digitalWrite(6,HIGH);
    digitalWrite(4,LOW);
    analogWrite(7,255);
    }
    if(x >= 600 && x <= 1023) {
     digitalWrite(5,HIGH);
    digitalWrite(2,LOW);
    analogWrite(3,motor_value);
    digitalWrite(6,LOW);
    digitalWrite(4,HIGH);
    analogWrite(7,motor_value);
    }
  }
}

/////////// second//////
#include <SPI.h> 
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN  8
#define CSN_PIN 9
#define x_axis A1 // x axis
#define y_axis A2 //y axis




const uint64_t pipe = 0xF9E8F0F0E1LL; 
RF24 radio(CE_PIN, CSN_PIN); 
int data[2];  

void setup() 
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
}

void loop()   
{

  data[0] = analogRead(x_axis);
  data[1] = analogRead(y_axis);
  radio.write( data, sizeof(data) ); 
}

Thanks for trying to help me. But I'm facing one error that says. I'm quite new to arduinos so please bear with my silly mistakes.

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define CE_PIN   8
#define CSN_PIN 9
const uint64_t pipe = 0xF9E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN); 
int data[2];
int gyro_value;
int motor_value;
void setup()   
{
  Wire.begin();
  mpu.initialize();
   pinMode(5,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(7,OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}


void loop() {
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
gyro_value = map(ax, 0, 17000, 0,255);
motor_value=abs(gyro_value);
  if ( radio.available() ) //Eğer sinyal algılarsan...
  {
    int y = data[1];
    int x = data[0];
    radio.read( data, sizeof(data) ); 
    if(y >= 400 && y <= 600) {
     digitalWrite(5,LOW);
    digitalWrite(2,LOW);
    analogWrite(3,0);
    digitalWrite(6,LOW);
    digitalWrite(4,LOW);
    analogWrite(7,0);
    }
     if(y >= 800 && y <= 1023) {
     digitalWrite(5,LOW);
    digitalWrite(2,HIGH);
    analogWrite(3,motor_value);
    digitalWrite(6,LOW);
    digitalWrite(4,HIGH);
    analogWrite(7,motor_value);
    }
    if(y >= 0 && y <= 450) {
     digitalWrite(5,HIGH);
    digitalWrite(2,LOW);
    analogWrite(3,motor_value);
    digitalWrite(6,HIGH);
    digitalWrite(4,LOW);
    analogWrite(7,motor_value);
    }
    if(x >= 0 && x <= 450) {
     digitalWrite(5,LOW);
    digitalWrite(2,HIGH);
    analogWrite(3,motor_value);
    digitalWrite(6,HIGH);
    digitalWrite(4,LOW);
    analogWrite(7,255);
    }
    if(x >= 600 && x <= 1023) {
     digitalWrite(5,HIGH);
    digitalWrite(2,LOW);
    analogWrite(3,motor_value);
    digitalWrite(6,LOW);
    digitalWrite(4,HIGH);
    analogWrite(7,motor_value);
    }
  }
}

now?

code is compiling without error. Thanks to you, But I need to try it in hardware just some minutes.

Did you try?

I'm connecting my wires as I disconnected all of them to test if my components were working again. I'll get you back after some minutes

the code seems to be working fine. But idk what's wrong it's not working at all

does R24f in the code needs to be yellow I do have the library installed

then, if didnt connect try: m1=12 m0=11 sck=13

if again not start l298n battery

how much voltage i must be giving to l298 motor it's having 7.4 volt and my nrf modules are at 3.4 and 3.3 volt is it enough?

I'm not getting any headups is it because of any low power stuff for 4 3v motors? after using the code NRF24l01 module get 4.12 v and l298 motor driver gets 8.55v so, is it my voltage or is it the code? I'm too jumbled.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.