Control dc motor speed with imu sensor

I'm trying to control the speed of a dc motor with MPU6050, IBT-2, and Arduino UNO. This is the code that I'm uploading on Arduino. The motor doesn't even start when i turn the power on. What's wrong with the code, any idea?

 
#include <Wire.h>
#include <MPU6050.h>
MPU6050 sensor ;
int16_t ax, ay, az ;
int16_t gx, gy, gz ;

int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)
 
void setup()
{
Wire.begin ( );
Serial.begin  (9600); 
sensor.initialize ( );
  
  pinMode(RPWM_Output, OUTPUT);
  pinMode(LPWM_Output, OUTPUT);
}
 
void loop()
{
sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
ax = map (ax, -17000, 17000, 0, 1023) ;
int sensorValue = ax;
 
  // sensor value is in the range 0 to 1023
  // the lower half of it we use for reverse rotation; the upper half for forward rotation
  if (sensorValue < 512)
  {
    // reverse rotation
    int reversePWM = -(sensorValue - 511) / 2;
    analogWrite(LPWM_Output, 0);
    analogWrite(RPWM_Output, reversePWM);
  }
  else
  {
    // forward rotation
    int forwardPWM = (sensorValue - 512) / 2;
    analogWrite(LPWM_Output, forwardPWM);
    analogWrite(RPWM_Output, 0);
  }
}

Show us at lease a block diagram of how you have all this connected. I hope you are not trying to POWER the motor using your Arduino! What are the electrical specifications for your motor?

Hi,
A schematic would be great.
A few images of your project can also help.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Screenshot_17
This is the connection. Nothing is attached to A0 please ignore that.

MPU6050 connection with Arduino:
SCL - A5
SDA - A4
VCC - 5V of Arduino
GND - GND of arduino

I'm using a dc power supply to power the motor with 12V.

Could it be a problem with the IMU sensor? I checked it with a separate program, it was giving roll pitch values but everytime it suddenly stops giving values after half a min or so. But it does give values in the beginning.

there is no problem with the motor or power supply. I've made several other projects with these and they've worked fine. The motor is working fine when i connect it directly to the supply.

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