Problem with project!

Hey Arduino finatics,

I need someone to help me with coding my Arduino Uno. I've built a gesture controlled RF robotic car that is controlled by the Uno and a MPU6050 6 axis accelerometer. Everything is wired and working fine. Ive loaded a code onto the arduino that gives me readings from the MPU6050 and im getting constant values that tells me the MPU6050 is working and what direction its in, but im struggling with the coding part of the project. The main basics are MPU to Uno to encoder to Rf transmitter and the receiver is Rf reciver to decoder to l293D motor driver. I'll upload any documents if needed

Thanks Henza64

So, now that you've checked things out with test code, what have you written for final application code? Start by posting that . Use CODE TAGS.

int xPin=A4; //X axis input
int yPin=A5; //Y axis input
int zPin=A1; //Z axis input(not used)
int Q1=10,Q2=11,Q3=12,Q4=13; //Output pins to be connected to 10, 11, 12, 13 of Decoder IC
long x; //Variabe for storing X coordinates
long y; //Variabe for storing Y coordinates
long z; //Variabe for storing Z coordinates
void setup()
{
  Serial.begin(9600);
  Serial.println("Initialize MPU6050");
  pinMode(Q1,OUTPUT);
  pinMode(Q2,OUTPUT);
  pinMode(Q3,OUTPUT);
  pinMode(Q4,OUTPUT);
 
}
void loop()
{
  x = analogRead(xPin); //Reads X coordinates
  y = analogRead(yPin); //Reads Y coordinates
  z = analogRead(zPin); //Reads Z coordinates (Not Used)
    if(x<5000)      // Change the value for adjusting sensitivity  
      forward();
    else if(x>5000) // Change the value for adjusting sensitivity
      backward();
    else if(y>5000) // Change the value for adjusting sensitivity
      right();
    else if(y<5000) // Change the value for adjusting sensitivity
      left();
    else
      stop_();
}
void stop_()
{
  Serial.println("");
  Serial.println("STOP");
  digitalWrite(Q1,LOW);
  digitalWrite(Q2,LOW);
  digitalWrite(Q3,LOW);
  digitalWrite(Q4,LOW);
}
void forward()
{
  Serial.println("");
  Serial.println("Forward");
  digitalWrite(Q1,HIGH);
  digitalWrite(Q2,LOW);
  digitalWrite(Q3,HIGH);
  digitalWrite(Q4,LOW);
}
void backward()
{
  Serial.println("");
  Serial.println("Backward");
  digitalWrite(Q1,LOW);
  digitalWrite(Q2,HIGH);
  digitalWrite(Q3,LOW);
  digitalWrite(Q4,HIGH);
}
void left()
{
  Serial.println("");
  Serial.println("Left");
  digitalWrite(Q1,LOW);
  digitalWrite(Q2,HIGH);
  digitalWrite(Q3,HIGH);
  digitalWrite(Q4,LOW);
}
void right()
{
  Serial.println("");
  Serial.println("Right");
  digitalWrite(Q1,HIGH);
  digitalWrite(Q2,LOW);
  digitalWrite(Q3,LOW);
  digitalWrite(Q4,HIGH);
}

This is what i've written so far but when i go into serial monitor all it reads is a single variable forward while the MPU6050 is placed flat. Im unsure if what i have written is at all correct.

Is this what you meant by attaching application code?

Please do not double post.

Appologies Jr, im unsure of how to delete my other post :confused: ?

Wow ok thanks so Detla_G the problem that im stuck with is that ive put a value test onto the Arduino Uno and it gives me a bunch of readings way over 1023 as shown below:

These are the values im getting at each position:
Flat:
AcX = 1012 | AcY = 412 | AcZ = 11184 | Tmp = 25.24 | GyX = 10 | GyY = -18 | GyZ = -27
AcX = 1132 | AcY = 532 | AcZ = 11048 | Tmp = 25.24 | GyX = 9 | GyY = -20 | GyZ = -21
AcX = 1108 | AcY = 400 | AcZ = 11160 | Tmp = 25.33 | GyX = 12 | GyY = -18 | GyZ = -22
AcX = 1036 | AcY = 448 | AcZ = 11056 | Tmp = 25.33 | GyX = 9 | GyY = -20 | GyZ = -23
AcX = 1116 | AcY = 516 | AcZ = 11008 | Tmp = 25.42 | GyX = 8 | GyY = -17 | GyZ = -24
Forward:
AcX = -6688 | AcY = 468 | AcZ = 9236 | Tmp = 24.91 | GyX = 10 | GyY = -54 | GyZ = -23
AcX = -6732 | AcY = 508 | AcZ = 9420 | Tmp = 24.86 | GyX = 13 | GyY = 1 | GyZ = -1
AcX = -6696 | AcY = 476 | AcZ = 9136 | Tmp = 25.00 | GyX = 7 | GyY = -48 | GyZ = -4
AcX = -6756 | AcY = 524 | AcZ = 9288 | Tmp = 25.00 | GyX = 10 | GyY = -22 | GyZ = -19
AcX = -6792 | AcY = 504 | AcZ = 9220 | Tmp = 25.05 | GyX = 21 | GyY = -33 | GyZ = -4
Backward
AcX = 8568 | AcY = 244 | AcZ = 9236 | Tmp = 25.33 | GyX = 5 | GyY = -22 | GyZ = -24
AcX = 8460 | AcY = 224 | AcZ = 9276 | Tmp = 25.42 | GyX = 6 | GyY = -18 | GyZ = -15
AcX = 8512 | AcY = 252 | AcZ = 9176 | Tmp = 25.42 | GyX = 9 | GyY = -23 | GyZ = -8
AcX = 8536 | AcY = 208 | AcZ = 9220 | Tmp = 25.38 | GyX = 6 | GyY = -21 | GyZ = -17
AcX = 8524 | AcY = 160 | AcZ = 9208 | Tmp = 25.57 | GyX = 8 | GyY = -21 | GyZ = -15
Left:
AcX = 1100 | AcY = -6436 | AcZ = 9384 | Tmp = 25.66 | GyX = -4 | GyY = -30 | GyZ = -23
AcX = 1016 | AcY = -6412 | AcZ = 9560 | Tmp = 25.80 | GyX = 13 | GyY = -18 | GyZ = -19
AcX = 1108 | AcY = -6420 | AcZ = 9408 | Tmp = 25.71 | GyX = -3 | GyY = -36 | GyZ = -10
AcX = 1052 | AcY = -6384 | AcZ = 9464 | Tmp = 25.71 | GyX = 20 | GyY = -22 | GyZ = -13
AcX = 964 | AcY = -6388 | AcZ = 9596 | Tmp = 25.75 | GyX = 6 | GyY = -23 | GyZ = -14
Right:
AcX = 1024 | AcY = 6708 | AcZ = 9972 | Tmp = 25.28 | GyX = 8 | GyY = -21 | GyZ = -17
AcX = 1008 | AcY = 6600 | AcZ = 9940 | Tmp = 25.38 | GyX = 10 | GyY = -22 | GyZ = -12
AcX = 1104 | AcY = 6724 | AcZ = 9784 | Tmp = 25.33 | GyX = -7 | GyY = -29 | GyZ = -39
AcX = 1072 | AcY = 6736 | AcZ = 9928 | Tmp = 25.38 | GyX = 7 | GyY = -22 | GyZ = -15
AcX = 1064 | AcY = 6636 | AcZ = 10008 | Tmp = 25.38 | GyX = 9 | GyY = -20 | GyZ = -15

Can you calibrate MPU6050's? Whats the next step from here?

Thanks Henza64

These values came from this code:
Its just an example code that gives me the real time readings from the MPU6050
There is a bunch of these example codes and this one is the one ive got on the Arduino Uno

#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

I got the code from this playground link
https://playground.arduino.cc/Main/MPU-6050

If any other material is needed i'm happy to post.

Delta_G yeah i suspected thanks :slight_smile: , do you have any idea what the wire commands would look like in my situation?

So ive edited my first application code, based on the Wire.h library do you think this will work?

int xPin=A4; //X axis input
int yPin=A5; //Y axis input
int zPin=A1; //Z axis input(not used)
int Q1=10,Q2=11,Q3=12,Q4=13; //Output pins to be connected to 10, 11, 12, 13 of Decoder IC
long x; //Variabe for storing X coordinates
long y; //Variabe for storing Y coordinates
long z; //Variabe for storing Z coordinates
#include <Wire.h> 

void setup()
{
  delay(100) //allow sensor to get ready
  Wire.begin(); 
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);

   
  pinMode(Q1,OUTPUT);
  pinMode(Q2,OUTPUT);
  pinMode(Q3,OUTPUT);
  pinMode(Q4,OUTPUT);
 
}
void loop()
{
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);  
  x = Wire.read(xPin); //Reads X coordinates
  y = Wire.read(yPin); //Reads Y coordinates
  z = Wire.read(zPin); //Reads Z coordinates (Not Used)
   
    if(x<500)      // Change the value for adjusting sensitivity  
      forward();
    else if(x>500) // Change the value for adjusting sensitivity
      backward();
    else if(y>500) // Change the value for adjusting sensitivity
      right();
    else if(y<500) // Change the value for adjusting sensitivity
      left();
    else
      stop_();
}
void stop_()
{
  Serial.println("");
  Serial.println("STOP");
  digitalWrite(Q1,LOW);
  digitalWrite(Q2,LOW);
  digitalWrite(Q3,LOW);
  digitalWrite(Q4,LOW);
}
void forward()
{
  Serial.println("");
  Serial.println("Forward");
  digitalWrite(Q1,HIGH);
  digitalWrite(Q2,LOW);
  digitalWrite(Q3,HIGH);
  digitalWrite(Q4,LOW);
}
void backward()
{
  Serial.println("");
  Serial.println("Backward");
  digitalWrite(Q1,LOW);
  digitalWrite(Q2,HIGH);
  digitalWrite(Q3,LOW);
  digitalWrite(Q4,HIGH);
}
void left()
{
  Serial.println("");
  Serial.println("Left");
  digitalWrite(Q1,LOW);
  digitalWrite(Q2,HIGH);
  digitalWrite(Q3,HIGH);
  digitalWrite(Q4,LOW);
}
void right()
{
  Serial.println("");
  Serial.println("Right");
  digitalWrite(Q1,HIGH);
  digitalWrite(Q2,LOW);
  digitalWrite(Q3,LOW);
  digitalWrite(Q4,HIGH);
}